资源描述:
《非参数统计第二版习题r程序(doc版)》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、P37.例2.1build.price<-c(36,32,31,25,28,36,40,32,41,26,35,35,32,87,33,35);build.pricehist(build.price,freq=FALSE)#直方图lines(density(build.price),col="red")#连线#方法一:m<-mean(build.price);m#均值D<-var(build.price)#方差SD<-sd(build.price)#标准差St=(m-37)/(SD/sqrt(length(build.price)));t#t统计量计算检验统计量t=[1]-0.1
2、412332#方法二:t.test(build.price-37)#课本第38页例2.2binom.test(sum(build.price<37),length(build.price),0.5)#课本40页例2.3P<-2*(1-pnorm(1.96,0,1));P[1]0.04999579P1<-2*(1-pnorm(0.7906,0,1));P1[1]0.4291774>例2.4>p<-2*(pnorm(-1.96,0,1));p[1]0.04999579>>p1<-2*(pnorm(-0.9487,0,1));p1[1]0.3427732例2.5(P45)scores<
3、-c(95,89,68,90,88,60,81,67,60,60,60,63,60,92,60,88,88,87,60,73,60,97,91,60,83,87,81,90);length(scores)#输入向量求长度ss<-c(scores-80);sst<-0t1<-0for(iin1:length(ss)){if(ss[i]<0)t<-t+1#求小于80的个数elset1<-t1+1求大于80的个数}t;t1>t;t1[1]13[1]15binom.test(sum(scores<80),length(scores),0.75)p-value=0.001436<0.01C
4、ox-Staut趋势存在性检验P47例2.6year<-1971:2002;yearlength(year)rain<-c(206,223,235,264,229,217,188,204,182,230,223,227,242,238,207,208,216,233,233,274,234,227,221,214,226,228,235,237,243,240,231,210)length(rain)#(1)该地区前10年降雨量是否变化?t1=0for(iin1:5){if(rain[i]5、0.5))#=0.1875y<-6/(2^5);y#=0.1875#(2)该地区前32年降雨量是否变化?t=0for(iin1:16){if(rain[i]6、ain~(year)))随机游程检验(P50)例2.8client<-c("F","M","M","M","M","M","F","M","M","F","M","M","M","M","F","M","F","M","M","M","F","F","F","M","M","M");clientn<-length(client);nn1<-sum(client=="M");n1n0<-n-n1;n0t1<-0for(iin1:(length(client)-1)){if(client[i]==client[i+1])t1<-t1elset1<-t1+1}R<-t1+1;R#=12
7、#findrejectionregion(不写)rl<-1+2*n1*n0/(n1+n0)*(1-1.96/sqrt(n1+n0));rlru<-2*n1*n0/(n1+n0)*(1+1.96/sqrt(n1+n0));ru#=15.33476(课本为ru=17)例2.9shuju39<-data.frame(read.table("SHUJU39.txt",header=TRUE));shuju39attach(shuju39)sum.a=0sum.b=0sum.c=0for(