-
Notifications
You must be signed in to change notification settings - Fork 32
/
simulation.R
153 lines (105 loc) · 2.88 KB
/
simulation.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
###
### Simulate 100 different 'journals' where the p-values
### that are reported are all the p-values less than 0.05
###
### Source our functions
###
source("calculateSwfdr.R")
source("journalAnalysisHelp.R")
library(stats4)
##
## Perform the simulation
##
set.seed(23452134)
n=100
pi0 = pi0hat = rep(NA,n)
for(i in 1:n){
palt = rbeta(1e3,1,100)
palt = palt[palt < 0.05]
x = runif(1,0,5)
pnull = runif(floor(length(palt)*x),0,0.05)
pp = c(pnull,palt)
tt = rbinom(length(pp),size=1,prob=0.2)
rr = rbinom(length(pp),size=1,prob=0.2)
rr[tt==1] = 0
pp[rr > 0] = round(pp[rr > 0],2)
pi0[i] = length(pnull)/length(pp)
pi0hat[i] = calculateSwfdr(pp,tt,rr,alpha=1,beta=150,numEmIterations=10)$pi0
print(i)
}
### Plot our estimate of the swfdr versus the truth.
###
pdf(file="all-significant.pdf")
plot(pi0,pi0hat,xlim=c(0,1),ylim=c(0,1),xlab="True swfdr",ylab="Estimated swfdr",pch=22,bg="blue",col="black",cex.axis=1.5,cex.lab=1.5,cex=2)
abline(c(0,1),lwd=3,col="grey ")
dev.off()
###
### Simulate from the case where only the minimum
### p-value is reported if it less than 0.05
###
n=100
pi0 = pi0hat = rep(NA,n)
for(i in 1:n){
palt = rep(NA,1000)
for(j in 1:1000){
ptmp = rbeta(20,1,100)
pval = min(ptmp)
if(pval < 0.05){palt[j] = pval}
}
palt = palt[!is.na(palt)]
x = runif(1,0,5)
pnull = rep(NA,floor(length(palt)*x))
for(j in 1:length(pnull)){
ptmp = rbeta(20,1,1)
pval = min(ptmp)
if(pval < 0.05){pnull[j] = pval}
}
pnull = pnull[!is.na(pnull)]
pp = c(pnull,palt)
tt = rbinom(length(pp),size=1,prob=0.2)
rr = rbinom(length(pp),size=1,prob=0.2)
rr[tt==1] = 0
pp[rr > 0] = round(pp[rr > 0],2)
pi0[i] = length(pnull)/length(pp)
pi0hat[i] = calculateSwfdr(pp,tt,rr,alpha=1,beta=150,numEmIterations=10)$pi0
print(i)
}
pdf(file="only-min.pdf")
plot(pi0,pi0hat,xlim=c(0,1),ylim=c(0,1),xlab="True swfdr",ylab="Estimated swfdr",pch=22,bg="blue",col="black",cex.axis=1.5,cex.lab=1.5,cex=2)
abline(c(0,1),lwd=3,col="grey")
dev.off()
###
### Simulate from the case where p-values are always
### rounded down when they are rounded.
###
n=100
pi0 = pi0hat = rep(NA,n)
for(i in 1:n){
palt = rep(NA,1000)
for(j in 1:1000){
ptmp = rbeta(20,1,100)
pval = min(ptmp)
if(pval < 0.05){palt[j] = pval}
}
palt = palt[!is.na(palt)]
x = runif(1,0,5)
pnull = rep(NA,floor(length(palt)*x))
for(j in 1:length(pnull)){
ptmp = rbeta(20,1,1)
pval = min(ptmp)
if(pval < 0.05){pnull[j] = pval}
}
pnull = pnull[!is.na(pnull)]
pp = c(pnull,palt)
tt = rbinom(length(pp),size=1,prob=0.2)
rr = rbinom(length(pp),size=1,prob=0.2)
rr[tt==1] = 0
pp[rr > 0] = floor(pp[rr > 0]*100)/100
pi0[i] = length(pnull)/length(pp)
pi0hat[i] = calculateSwfdr(pp,tt,rr,alpha=1,beta=150,numEmIterations=10)$pi0
print(i)
}
pdf(file="floored-rounding.pdf")
plot(pi0,pi0hat,xlim=c(0,1),ylim=c(0,1),xlab="True swfdr",ylab="Estimated swfdr",pch=22,bg="blue",col="black",cex.axis=1.5,cex.lab=1.5,cex=2)
abline(c(0,1),lwd=3,col="grey")
dev.off()