[R] Surprising behaviour of fisher.test
Öhagen Patrik
Patrik.Ohagen at mpa.se
Mon Aug 29 13:44:28 CEST 2011
I did a simple little simulation of a binary variable in a two armed trial. I was quite surprised by the number of p-values delivered by the fisher.test function which was >1(!). Of course, under the null hypothesis you expect a fair number of outcomes with the same number of event in both arms but still?
Is there some silly error in my crude code?
##########################################################################################
niter<-50000
ra<-rbinom(niter,100,.05)
rb<-rbinom(niter,100,.05)
pval<-rep(NA,niter)
for (i in 1:niter){
apa<-matrix(c(100-ra[i],ra[i],100-rb[i],rb[i]),byrow=T,ncol=2)
pval[i]<-fisher.test(apa)$p.value
}
cbind(ra,rb,pval)[pval < 0.06 & pval > 0.04,]
hist(pval,probability=T)
summary(pval)
table(pval< 0.05)/niter
sum(pval>1)/niter
################################################################################################
Patrik Öhagen
Biostatistiker
Enheten för effekt och säkerhet 4
Box 26, 751 03 Uppsala
Besöksadress: Dag Hammarskjöldsväg 42
Telefon: 018 - 17 49 24, växel: 018 - 17 46 00
Fax: 018 - 54 85 66
patrik.ohagen at mpa.se
www.lakemedelsverket.se
More information about the R-help
mailing list