P37. 例 2.1
60,88,88,87,60,73,60,97,91,60,83,87,81,90);length(
scores)# 输入向量求长度
build.price<- c(36,32,31,25,28,36,40,32,41,26,35,35,32,87,33,35 );build.price
hist(build.price,freq=FALSE)# 直方图 lines(density(build.price),col="red")# 连线
# 方法一: m<-mean(build.price);m# 均值
D<-var(build.price)# 方差
SD<-sd(build.price)# 标准差 S
t=(m-37)/(SD/sqrt(length(build.price)));t#t 统计量
计算检验统计量
t=
[1] -0.1412332
# 方法二: t.test(build.price-37)# 课本第 38 页
例 2.2
st(sum(build.price<37),length(build.price),
0.5)# 课本 40 页
例 2.3
P<-2*(1-pnorm(1.96,0,1));P
[1] 0.04999579
P1<-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<- c(95,89,68,90,88,60,81,67,60,60,60,63,60,92, ss<-c(scores-80);ss
t<-0
t1<-0
for(i in 1:length(ss)){
if (ss[i]<0) t<-t+1# 求小于 80 的个数
else t1<-t1+1 求大于 80 的个数
}
t;t1
> t;t1
[1] 13
[1] st(sum(scores<80),length(scores),0.75) p-value = 0.001436<0.01
Cox-Staut 趋势存在性检验 P47
例 2.6
year<-1971:2002;year length(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=0
for (i in 1:5){
if (rain[i]<rain[i+5]) t1<-t1+1
}
t1
k<-0:t1-1
sum(dbinom(k,5,0.5))# =0.1875
y<-6/(2A5);y# =0.1875
n<-length(client);n
rl<-1+2*n1*n0/(n1+n0)*(1-1.96/sqrt(n1+n0));rl ru<-
2*n1*n0/(n1+n0)*(1+1.96/sqrt(n1+n0));ru#=15.3
3476 (课本为 ru=17 )
#(2) 该地区前 32 年降雨量是否变化?
t=0
for (i in 1:16){
if (rain[i]<rain[i+16]) t<-t+1
}
t
k1<-0:min(t,16-t)-1
sum(dbinom(k1,16,0.5))# =0.0002593994
pbinom(max(k1),16,0.5)#= 0.0002593994
y1<-(1 + 16)/(2X6);y1#=0.0002593994
plot(year,rain)
abline(v=(1971+2002)/2,col=2)
lines(year,rain)
anova(lm(rain~(year)))
随机游程检验( P50)
例 2.8 client<-c("F","M","M","M","M","M","F","M",
n1<-sum(client=="M");n1
n0<-n-n1;n0 t1<-0 for (i in 1:(length(client)-1)){ if (client[i]==client[i+1]) t1<-t1 else t1<-t1+1 }
R<-t1+1;R#=12 #find rejection region (不写) 例 2.9
shuju39<-data.frame(read.table ("",header=TRUE));shuju39 attach(shuju39)
sum.a=0
sum.b=0
sum.c=0
for (i in 1:length(id)){
if (pinzhong[i]=="A") sum.a<-sum.a+chanliang[i] else if (pinzhong[i]=="B") sum.b<- sum.b+chanliang[i]
frequency函数计算频数else fuhao<-sum.c<-sum.c+chanliang[i]
} sum.a;sum.b;sum.c ma<-sum.a/4 mb<-sum.b/4 mc<-sum.c/4
ma;mb;mc fuhao<-rep("a",12);fuhao for (i in 1:length(id)){ if (pinzhong[i]=="A" & ((chanliang[i]-ma)>0)) fuhao[i]<-"+"
else if (pinzhong[i]=="B" & ((chanliang[i]-mb)>0)) fuhao[i]<-"+"
else if (pinzhong[i]=="C" & ((chanliang[i]-mc)>0)) fuhao[i]<-"+"
else fuhao[i]<-"-"
}
fuhao
# 利用上题编程解决检验的随机性 n<-length(fuhao);n
n1<-sum(fuhao=="+");n1 n0<-n-n1;n0
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论