forked from ruthkeogh/causal_sim
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathanalysis_TRUE_VALUES_2.R
62 lines (43 loc) · 2.09 KB
/
analysis_TRUE_VALUES_2.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
#------------------------------------------------------
#------------------------------------------------------
# analysis_TRUE_VALUES_2.R
# - Obtains (estimated) true values of survival probabilities under the treatment regimes 'always treated' and 'never treated'
# using the large trial data generated in dat_sim_TRUE_VALUES_2.R.
# - Survival probabilities are directly estimated using simple proportions, since there is only administrative censoring in the data.
# - This is just an another way of obtaining the true values for the survival probabilities. It is faster than using dat_sim_TRUE_VALUES_1.R and analysis_TRUE_VALUES_1.R because it doesn't involve fitting a model. See Section 6.2. of the paper.
# - Unlike analysis_TRUE_VALUES_1.R, this file does not obtains (estimated) true values of the cumulative coefficients.
# Created by Ruth Keogh
#------------------------------------------------------
#------------------------------------------------------
#--------------------------
#times at which we obtain estimates of survival probabilities
#--------------------------
t.hor=seq(0,5,0.01)
#--------------------------
#analysis of n.sim large trials
#--------------------------
n.sim.true=1000
#----
#store results
surv1_true=matrix(nrow=n.sim.true,ncol=length(t.hor))
surv0_true=matrix(nrow=n.sim.true,ncol=length(t.hor))
#----
#start of simulation loop
for(i in 1:n.sim.true){
print(i)
#-----
#simulate data using dat_sim_TRUE_VALUES_2
source("dat_sim_TRUE_VALUES_2.R")
#----
#estimated survival probabilities at times t.hor in the 'always treated' (surv1) and in the 'never treated' (surv0)
surv1_true[i,]=sapply(1:length(t.hor),function(x){mean(dat.1$T.obs>t.hor[x])})
surv0_true[i,]=sapply(1:length(t.hor),function(x){mean(dat.0$T.obs>t.hor[x])})
}
#end of simulation loop
#----
#--------------------------
#True values of survival probabilities
#Taken to be the average of the n.sim.true estimates from the large trials
#--------------------------
surv1_true=colMeans(surv1)
surv0_true=colMeans(surv0)