(7) 対立仮説からの量的形質の分布、等分散・異分散(t-test)

  • 等分散からのサンプリング
# 対立仮説

N1<-5
N2<-5


m1<-500
m2<-510

v1<-10
v2<-10 # 異分散

Niter<-1000
ps1<-ps2<-rep(0,Niter)
for(i in 1:Niter){
	d1<-rnorm(N1,m1,sqrt(v1))
	d2<-rnorm(N2,m2,sqrt(v2))
	t.test.out1<-t.test(d1,d2,var.equal=TRUE)
	t.test.out2<-t.test(d1,d2,var.equal=FALSE)
	ps1[i]<-t.test.out1$p.value
	ps2[i]<-t.test.out2$p.value

}

plot(ps1,ps2,cex=0.1)
plot(ppoints(Niter,a=0),sort(ps1),cex=0.1)
plot(ppoints(Niter,a=0),sort(ps2),cex=0.1)
  • 異分散からのサンプリング
# 対立仮説

N1<-5
N2<-5


m1<-500
m2<-510

v1<-1
v2<-200 # 異分散

Niter<-1000
ps1<-ps2<-rep(0,Niter)
for(i in 1:Niter){
	d1<-rnorm(N1,m1,sqrt(v1))
	d2<-rnorm(N2,m2,sqrt(v2))
	t.test.out1<-t.test(d1,d2,var.equal=TRUE)
	t.test.out2<-t.test(d1,d2,var.equal=FALSE)
	ps1[i]<-t.test.out1$p.value
	ps2[i]<-t.test.out2$p.value

}

plot(ps1,ps2,cex=0.1)
plot(ppoints(Niter,a=0),sort(ps1),cex=0.1)
plot(ppoints(Niter,a=0),sort(ps2),cex=0.1)