-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmainfile.R
150 lines (103 loc) · 4.82 KB
/
mainfile.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
rm(list = ls(all=TRUE))
library(AER)
library(MASS)
args <- commandArgs(T)
set.seed(as.numeric(args[1]))
job_id <- (as.numeric(args[1]))
message("job number ", job_id)
source("functions_flexnoX.R")
#Set sample size and number of snps for this simulation
ss = 20000 #sample size
givs = 200 #number of snps
reps = 100
output <- data.frame()
##Simulations with weak instruments
pimax = 0.1
for(tau_true in c(0,0.5)){
set.seed(as.numeric(args[1]))
n=ss
L = givs
sim = 1
kx = 2
delta = 0.7
mu = c(0,0,0)
s = matrix(c(1,0.8,-0.7,0.8,1,-0.7,-0.7,-0.7,1), ncol = 3)
pi2 = as.matrix(c(runif((L),0,pimax)),nrow=L,ncol=n)
pi1 = as.matrix(c(runif((L),0,pimax)),nrow=L,ncol=n)
alpha = as.matrix(c(rnorm(L/2,0,tau_true), rep(0,L/2)),nrow=L,ncol=1)
source("simulations_2ex.R")
output <- rbind(output, data.frame(sim, L, tau_true, pimax, ivest1, ivest2, olsest1, olsest2,
tsest1, tsest2, F1, F2, F1_iv, F2_iv,
QIVW1_LIML, QIVW1, QIVW2_LIML, QIVW2, Qa, Qa_novar,
Qexact, Qexact_het,
limlest1, limlest2, limlhet1, limlhet2, tau, QIVW1_LIMLnoc, QIVW1_noc, QIVW2_LIMLnoc, QIVW2_noc,
Qexactnoc, Qexact_hetnoc,
limlest1_noc, limlest2_noc, limlhet1_noc, limlhet2_noc, taunoc))
}
#simulations with conditionally weak instruments
for(tau_true in c(0,0.5)){
set.seed(as.numeric(args[1]))
pimax = 2
sim = 2
delta = 0.7
mu = c(0,0,0)
s = matrix(c(1,0.8,-0.7,0.8,1,-0.7,-0.7,-0.7,1), ncol = 3)
pi2 = as.matrix(c(runif((L),0,pimax)),nrow=L,ncol=n)
pi1 = delta*pi2 + c(0,rnorm((L-1),2.8/sqrt(n),0.075))
alpha = as.matrix(c(rnorm(L/2,0,tau_true), rep(0,L/2)),nrow=L,ncol=1)
source("simulations_2ex.R")
output <- rbind(output, data.frame(sim, L, tau_true, pimax, ivest1, ivest2, olsest1, olsest2,
tsest1, tsest2, F1, F2, F1_iv, F2_iv,
QIVW1_LIML, QIVW1, QIVW2_LIML, QIVW2, Qa, Qa_novar,
Qexact, Qexact_het,
limlest1, limlest2, limlhet1, limlhet2, tau, QIVW1_LIMLnoc, QIVW1_noc, QIVW2_LIMLnoc, QIVW2_noc,
Qexactnoc, Qexact_hetnoc,
limlest1_noc, limlest2_noc, limlhet1_noc, limlhet2_noc, taunoc))
}
#simulations with strong instruments
for(tau_true in c(0,0.5)){
set.seed(as.numeric(args[1]))
pimax = 2
sim = 2.2
delta = 0.7
mu = c(0,0,0)
s = matrix(c(1,0.8,-0.7,0.8,1,-0.7,-0.7,-0.7,1), ncol = 3)
pi2 = as.matrix(c(runif((L),0,pimax)),nrow=L,ncol=n)
pi1 = as.matrix(c(runif((L),0,pimax)),nrow=L,ncol=n)
alpha = as.matrix(c(rnorm(L/2,0,tau_true), rep(0,L/2)),nrow=L,ncol=1)
source("simulations_2ex.R")
output <- rbind(output, data.frame(sim, L, tau_true, pimax, ivest1, ivest2, olsest1, olsest2,
tsest1, tsest2, F1, F2, F1_iv, F2_iv,
QIVW1_LIML, QIVW1, QIVW2_LIML, QIVW2, Qa, Qa_novar,
Qexact, Qexact_het,
limlest1, limlest2, limlhet1, limlhet2, tau, QIVW1_LIMLnoc, QIVW1_noc, QIVW2_LIMLnoc, QIVW2_noc,
Qexactnoc, Qexact_hetnoc,
limlest1_noc, limlest2_noc, limlhet1_noc, limlhet2_noc, taunoc))
}
message("filesave", sprintf("output2ex%s.Rda", job_id))
save(output, file=sprintf("output2ex%s.Rda", job_id))
#simulations for table 3
output3 <- data.frame()
pimax = 1
n=ss
L = givs
sim = 3
kx = 3
mu = c(0,0,0)
s = matrix(c(1,0.8,-0.7,0.8,1,-0.7,-0.7,-0.7,1), ncol = 3)
pi2 = as.matrix(c(runif((L),0,pimax)),nrow=L,ncol=n)
pi1 = as.matrix(c(runif((L),0,pimax)),nrow=L,ncol=n)
pi3 = 0.1*pi1+0.9*as.matrix(c(runif((L),0,pimax/5)),nrow=L,ncol=n)
source("simulations_3ex.R")
output3 <- rbind(output3, data.frame(sim, L, tau_true, pimax, ivest1, ivest2, olsest1, olsest2,
tsest1, tsest2, F1, F2, F1_iv, F2_iv,
QIVW1_LIML, QIVW1, QIVW2_LIML, QIVW2, Qa, Qa_novar,
Qexact, Qexact_het,
limlest1, limlest2, limlhet1, limlhet2, tau,
ivest1_3, ivest2_3, ivest3_3, olsest1_3, olsest2_3, olsest3_3,
tsest1_3, tsest2_3, tsest3_3, F1_3, F2_3, F3_3, F1_iv_3, F2_iv_3, F3_iv_3,
QIVW1_3, QIVW2_3, QIVW3_3, Qa3, Qa_novar3,
Qexact_3, Qexact_het_3,
limlest1_3, limlest2_3, limlest3_3, limlhet1_3, limlhet2_3, limlhet3_3, tau_3))
message("filesave", sprintf("output3ex%s.Rda", job_id))
save(output3 , file=sprintf("output3ex%s.Rda", job_id))