资源描述:
《统计建模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<
2、-B[,-3]......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',
3、'14','15'),+身高=c('156','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)i
4、f(n==1)break}print('运算成功')}}第三章3.1首先将数据录入为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)>qql
5、ine(x)3.3>stem(x)>boxplot(x)>fivenum(x)3.4>shapiro.test(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
6、-Smirnovtest这里出现警告信息是因为ks检验要求样本数据是连续的,不允许出现重复值......3.5>x1<-c(2,4,3,2,4,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
7、,length(x3)))),c(x1,x2,x3))3.6>rubber<-data.frame(x1=c(65,70,70,69,66,67,68,72,66,68),+x2=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)......具体有相关关系的两个变量的散点图要么是从左下角到右上角(正相关),要么是从左上角到右下角(负相关)。从上图可知所有的图中偶读没有这样的趋势,故均
8、不相关。3.7(1)>student<-read.csv('3.7.csv')>attach(student)>plot(体重~身高)(2)>coplot(体重~身高
9、性别)(3)>coplot(体重~身高
10、年龄)(4)