资源描述:
《统计建模与R软件课后问题详解》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、实用标准第二章2.1>x<-c(1,2,3);y<-c(4,5,6)>e<-c(1,1,1)>z<-2*x+y+e;z[1]71013>z1<-crossprod(x,y);z1[,1][1,]32>z2<-outer(x,y);z2[,1][,2][,3][1,]456[2,]81012[3,]1215182.2(1)>A<-matrix(1:20,nrow=4);B<-matrix(1:20,nrow=4,byrow=T)文案大全实用标准>C<-A+B;C(2)>D<-A%*%B;D(3)>E<-A*B;E(4)>F<-A[1:3,1:3](5)>G<-B[,-3]
2、2.3>x<-c(rep(1,5),rep(2,3),rep(3,4),rep(4,2));x2.4>H<-matrix(nrow=5,ncol=5)>for(iin1:5)+for(jin1:5)+H[i,j]<-1/(i+j-1)(1)>det(H)(2)>solve(H)(3)>eigen(H)2.5>studentdata<-data.frame(姓名=c('张三','李四','王五','赵六','丁一')文案大全实用标准+,性别=c('女','男','女','男','女'),年龄=c('14','15','16','14','15'),+身高=c('156',
3、'165','157','162','159'),体重=c('42','49','41.5','52','45.5'))2.6>write.table(studentdata,file='student.txt')>write.csv(studentdata,file='student.csv')2.7count<-function(n){if(n<=0)print('要求输入一个正整数')else{repeat{if(n%%2==0)n<-n/2elsen<-(3*n+1)文案大全实用标准if(n==1)break}print('运算成功')}}第三章3.1首先将数据
4、录入为x。利用data_outline函数。如下>data_outline(x)3.2>hist(x,freq=F)>lines(density(x),col='red')>y<-min(x):max(x)>lines(y,dnorm(y,73.668,3.9389),col='blue')>plot(ecdf(x),verticals=T,do.p=F)>lines(y,pnorm(y,73.668,3.9389))>qqnorm(x)>qqline(x)文案大全实用标准3.3>stem(x)>boxplot(x)>fivenum(x)3.4>shapiro.test
5、(x)>ks.test(x,'pnorm',73.668,3.9389)One-sampleKolmogorov-Smirnovtestdata:xD=0.073,p-value=0.6611alternativehypothesis:two-sidedWarningmessage:Inks.test(x,"pnorm",73.668,3.9389):tiesshouldnotbepresentfortheKolmogorov-Smirnovtest文案大全实用标准这里出现警告信息是因为ks检验要求样本数据是连续的,不允许出现重复值3.5>x1<-c(2,4,3,2,4
6、,7,7,2,2,5,4);x2<-c(5,6,8,5,10,7,12,12,6,6);x3<-c(7,11,6,6,7,9,5,5,10,6,3,10)>boxplot(x1,x2,x3,names=c('x1','x2','x3'),vcol=c(2,3,4))>windows()>plot(factor(c(rep(1,length(x1)),rep(2,length(x2)),rep(3,length(x3)))),c(x1,x2,x3))3.6>rubber<-data.frame(x1=c(65,70,70,69,66,67,68,72,66,68),+x2
7、=c(45,45,48,46,50,46,47,43,47,48),x3=c(27.6,30.7,31.8,32.6,31.0,31.3,37.0,33.6,33.1,34.2))>plot(rubber)文案大全实用标准具体有相关关系的两个变量的散点图要么是从左下角到右上角(正相关),要么是从左上角到右下角(负相关)。从上图可知所有的图中偶读没有这样的趋势,故均不相关。3.7(1)>student<-read.csv('3.7.csv')>attach(student)>plot(体重~身高)(2)>coplot(体重~身高
8、性别)(3