-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPartiallyFD_simulation_analysis.r
More file actions
487 lines (384 loc) · 22.9 KB
/
Copy pathPartiallyFD_simulation_analysis.r
File metadata and controls
487 lines (384 loc) · 22.9 KB
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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
##########################################################################################
##########################################################################################
## Supplement for "Partially Observed Functional Data: The Case of Systematically Missing"
## by Dominik Liebl & Stefan Rameseder
## Analyse the results from the predecessing simulation
# Need parameters for version since all files saved before will be loaded here
version <- paste0(ver,"_p", p, "_n", n, "_R", replications, "_SD", 100*suppliedSettings$sd_part, "_SD", 1000*suppliedSettings$xi_1_d_cor,"_BC_", b_choice,maxAllowedBasis ))
maxAllowedBasis <- 51
replications <- 500
ns <- c(50,150,250,500)
require(xtable)
library(xtable)
##########################################################################################
## Get it for all n's together into one list
allResults <- lapply(ns, function(x){ #
print(version <- "FirstSimulation_p501_n50_R1_SD100_SD995_BC_Med31")
load(paste0("PartiallyFD_sim_", version,".RData"))
DGP_names <- names(resDGP)
cor <- lapply(resDGP, function(dgp) sapply(dgp, function(rep) rep$cor[1,2]))
(corSum <- lapply(cor, summary))
##########################################################################################
### a) Mean Estimation
## True Mean
# Define basis once
basis_fd <- get(paste0("create.",base,".basis"))(rangeval = range(comp_dom), nbasis = nbasis_dgp)
# Calculate true mean
trueMean <- calcTrueMean(basis_fd, xi_means, comp_dom)
## FTC Estimator
ftcMeans <- lapply(resDGP, function(dgp) lapply(dgp, function(rep) rep$ftcMean))
## Bias: Calculate the Mean of all Means
# Bias[\hat{\mu}_{n}(t)] =
# = E_{MC}[\hat{\mu}_{n}(t) ] - \mu(t)
# = (1/500)\sum_{r=1}^{500}[\hat{\mu}_{n,r}(t)] - \mu(t)
ftcMeansMeans <- lapply(ftcMeans, function(dgp){
return(rowMeans(matrix(unlist(dgp), nrow = 501) ))
} )
ftcMeansBias <- lapply(ftcMeansMeans, function(rep) rep - trueMean)
SqIntMeanBias <- lapply(ftcMeansBias, function(rep) sum((rep)^2)/p)
## Calculate the Variance of the Means
#Var[\hat{\mu}_{n}(t)] =
# = E_{MC}[ (\hat{\mu}_{n}(t) - E_{MC}[\hat{\mu}_{n}(t) ] )^2 ]
# = (1/500)\sum_{r=1}^{500}[ (\hat{\mu}_{n,r}(t) - (1/500)\sum_{l=1}^{500}[\hat{\mu}_{n,l}(t)] )^2 ]
VarOfMeans <- vector("list", length = length(DGP_names))
names(VarOfMeans) <- DGP_names
for(dgp in DGP_names){ # dgp <- DGP_names[[1]]; rep <- ftcMeans[[1]][[1]]
VarOfMeans[[dgp]] <- lapply(ftcMeans[[dgp]], function(rep) ( rep - ftcMeansMeans[[dgp]] )^2 )
}
ftcVarMeans <- lapply(VarOfMeans, function(dgp){
return(rowMeans(matrix(unlist(dgp), nrow = p) ))
} )
IntftcVarMeans <- lapply(ftcVarMeans, function(rep) sum(rep)/p)
## MSE Median and Mean
sqDevs <- lapply(ftcMeans, function(dgp) sapply(dgp, function(rep) sum((rep-trueMean)^2)/length(comp_dom)))
ftcSqDevsSum <- lapply(sqDevs, function(dgp) summary(dgp))
ftcMeansAndMed <- t(sapply(ftcSqDevsSum, function(x) x[c("Mean", "Median")]))
## Krauss Estimator
krausMeans <- lapply(resDGP, function(dgp) lapply(dgp, function(rep) rep$krausMean))
## Bias: Calculate the Mean of all Means
krausMeansMeans <- lapply(krausMeans, function(dgp){
return(rowMeans(matrix(unlist(dgp), nrow = p) ))
} )
krausMeansBias <- lapply(krausMeansMeans, function(rep) rep - trueMean)
krausSqIntMeanBias <- lapply(krausMeansBias, function(rep) sum((rep)^2)/p)
## Calculate the Variance of the Means
VarOfMeans <- vector("list", length = 4)
names(VarOfMeans) <- DGP_names
for(dgp in DGP_names){ # dgp <- DGP_names[[4]]; rep <- ftcMeans[[1]][[1]]
VarOfMeans[[dgp]] <- lapply(krausMeans[[dgp]], function(rep) ( rep - krausMeansMeans[[dgp]] )^2 )
}
krausVarMeans <- lapply(VarOfMeans, function(dgp){
return(rowMeans(matrix(unlist(dgp), nrow = p)) )
} )
IntkrausVarMeans <- lapply(krausVarMeans, function(rep) sum(rep)/p)
krausptwDevs <- lapply(ftcMeans, function(dgp) sapply(dgp, function(rep) rep-trueMean))
krausSqDevs <- lapply(krausMeans, function(dgp) sapply(dgp, function(rep) sum((rep-trueMean)^2)/length(comp_dom)))
krausSqDevsSum <- lapply(krausSqDevs, function(dgp) summary(dgp))
krausMeansAndMed<- t(sapply(krausSqDevsSum, function(x) x[c("Mean", "Median")]))
## Bring both together
EST_names <- c("ftc", "kraus")
distMatrix <- matrix(NA, ncol = 2*length(DGP_names), nrow = 2)
colnames(distMatrix) <- paste(rep(c("Mean", "Median"), length(DGP_names)), rep(DGP_names, each =2))
rownames(distMatrix) <- EST_names
for(est in EST_names){ # est <- ftc
for(stat in c("Mean", "Median")){ # stat <- "Mean"
for(dgp in DGP_names){ # dgp <- "SD"
#print(paste0(est, stat, dgp))
distMatrix[est,paste(stat,dgp)] <- get(paste0(est,"MeansAndMed"))[dgp,stat]
}
}
}
(distMatrixLat <- round(distMatrix,2))
## FTC Estimator
ftcMeans <- lapply(resDGP, function(dgp) lapply(dgp, function(rep) rep$ftcMean))
sqDevs <- lapply(ftcMeans, function(dgp) sapply(dgp, function(rep) sum((rep[-(1:250)]-trueMean[-(1:250)])^2)/length(comp_dom[-(1:250)])))
ftcSqDevsSum <- lapply(sqDevs, function(dgp) summary(dgp))
ftcMeansAndMed <- t(sapply(ftcSqDevsSum, function(x) x[c("Mean", "Median")]))
## Krauss Estimator length(-(251:501))
krausMeans <- lapply(resDGP, function(dgp) lapply(dgp, function(rep) rep$krausMean))
krausSqDevs <- lapply(krausMeans, function(dgp) sapply(dgp, function(rep) sum((rep[-(1:250)]-trueMean[-(1:250)])^2)/length(comp_dom[-(1:250)])))
krausSqDevsSum <- lapply(krausSqDevs, function(dgp) summary(dgp))
krausMeansAndMed<- t(sapply(krausSqDevsSum, function(x) x[c("Mean", "Median")]))
distMatrixsd <- matrix(NA, ncol = 2*length(DGP_names), nrow = 2)
colnames(distMatrixsd) <- paste(rep(c("Mean", "Median"), length(DGP_names)), rep(DGP_names, each =2))
rownames(distMatrixsd) <- EST_names
for(est in EST_names){ # est <- ftc
for(stat in c("Mean", "Median")){ # stat <- "Mean"
for(dgp in DGP_names){ # dgp <- "SD"
#print(paste0(est, stat, dgp))
distMatrixsd[est,paste(stat,dgp)] <- get(paste0(est,"MeansAndMed"))[dgp,stat]
}
}
}
(distMatrixsdLat <- round(distMatrixsd,2))
##########################################################################################
### b) Chosen Basis Length
selBasis <- lapply(resDGP, function(dgp) sapply(dgp, function(rep) rep$selBasis))
lapply(selBasis, table)
##########################################################################################
### c) Identification via Romano Wolf
romWolfent <- lapply(resDGP, function(dgp) lapply(dgp, function(rep) rep$romWolf$ent))
# Define scenario F1, F2, and the Correct One
# F1 = All are not rejected
# F2 = There are more than the first rejected
# C = Only H1 is rejected, the others are not
romWolfDec <- lapply(romWolfent, function(dgp) sapply(dgp, checkFtcHypothesis))
lapply(romWolfDec, table)
##########################################################################################
### d) Analysis of Correlations
cor <- lapply(resDGP, function(dgp) sapply(dgp, function(rep) rep$cor[1,2]))
# lapply(resDGP[["SC"]], function(x) x$cor[1,2])
(corSum <- lapply(cor, summary))
##########################################################################################
### e) Analysis of Covariances
resCov <- lapply(DGP_names, function(dgp){ # dgp <- "SC"
# Define basis once
basis_fd <- get(paste0("create.",base,".basis"))(rangeval = range(comp_dom), nbasis = nbasis_dgp)
# Calculate true mean
trueMean <- calcTrueMean(basis_fd, xi_means, comp_dom)
# Calculate true covariance via cov(s,t) = sum_i=1^b lambda_i * psi_i(t)*psi_i(s)
trueCov <- calcTrueCovariance(basis_fd, seq.ev, comp_dom)
return(list(trueMean = trueMean, trueCov = trueCov))
})
names(resCov) <- DGP_names
covDistMatrix <- matrix(NA, ncol = dim(distMatrixLat)[2], nrow = dim(distMatrixLat)[1])
dimnames(covDistMatrix) <- dimnames(distMatrix)
for(dgp in DGP_names){ # dgp <- "SD"
print(paste0(dgp))
ftcCovs <- lapply(resDGP[[dgp]], function(rep) rep$ftcCov) # rep <- ftcCovs[[1]]
ftcCovDist <- sapply(ftcCovs, function(rep) sum((rep - resCov[[dgp]]$trueCov)^2)/p^2)
covDistMatrix["ftc", paste(c("Mean", "Median"),dgp) ] <- c(mean(ftcCovDist), median(ftcCovDist))
krausCovs <- lapply(resDGP[[dgp]], function(rep) rep$krausCov)
ftcCovDist <- sapply(krausCovs, function(rep) sum((rep - resCov[[dgp]]$trueCov)^2)/p^2)
covDistMatrix["kraus",paste(c("Mean", "Median"),dgp)] <- c(mean(ftcCovDist), median(ftcCovDist))
}
(covDistMatrixLat <- round(covDistMatrix,2))
covDistMatrixsd <- matrix(NA, ncol = dim(distMatrixLat)[2], nrow = dim(distMatrixLat)[1])
dimnames(covDistMatrixsd) <- dimnames(distMatrix)
for(dgp in DGP_names){ # dgp <- "SD"
print(paste0(dgp))
ftcCovs <- lapply(resDGP[[dgp]], function(rep) rep$ftcCov) # rep <- ftcCovs[[1]]
ftcCovDist <- sapply(ftcCovs, function(rep) sum((rep[-(1:250), -(1:250)] - resCov[[dgp]]$trueCov[-(1:250), -(1:250)])^2)/(p-250)^2)
covDistMatrixsd["ftc", paste(c("Mean", "Median"),dgp) ] <- c(mean(ftcCovDist), median(ftcCovDist))
krausCovs <- lapply(resDGP[[dgp]], function(rep) rep$krausCov)
ftcCovDist <- sapply(krausCovs, function(rep) sum((rep[-(1:250), -(1:250)] - resCov[[dgp]]$trueCov[-(1:250), -(1:250)])^2)/(p-250)^2)
covDistMatrixsd["kraus",paste(c("Mean", "Median"),dgp)] <- c(mean(ftcCovDist), median(ftcCovDist))
}
(covDistMatrixsdLat <- round(covDistMatrixsd,2))
covDistMatrix_ftc <- matrix(NA, ncol = dim(distMatrixLat)[2], nrow = dim(distMatrixLat)[1])
dimnames(covDistMatrix_ftc) <- dimnames(distMatrix)
for(dgp in DGP_names){ # dgp <- "SD"
print(paste0(dgp))
ftcCovs <- lapply(resDGP[[dgp]], function(rep) rep$ftcCov) # rep <- ftcCovs[[1]]
ftcCovDist <- sapply(ftcCovs, function(rep) sum((rep - resCov[[dgp]]$trueCov)^2)/p^2)
covDistMatrix_ftc["ftc", paste(c("Mean", "Median"),dgp) ] <- c(mean(ftcCovDist), median(ftcCovDist))
krausCovs <- lapply(resDGP[[dgp]], function(rep) rep$krausCov_ftc)
ftcCovDist <- sapply(krausCovs, function(rep) sum((rep - resCov[[dgp]]$trueCov)^2)/p^2)
covDistMatrix_ftc["kraus",paste(c("Mean", "Median"),dgp)] <- c(mean(ftcCovDist), median(ftcCovDist))
}
(covDistMatrixLat_ftc <- round(covDistMatrix_ftc,2))
covDistMatrixsd_ftc <- matrix(NA, ncol = dim(distMatrixLat)[2], nrow = dim(distMatrixLat)[1])
dimnames(covDistMatrixsd_ftc) <- dimnames(distMatrix)
for(dgp in DGP_names){ # dgp <- "SD"
print(paste0(dgp))
ftcCovs <- lapply(resDGP[[dgp]], function(rep) rep$ftcCov) # rep <- ftcCovs[[1]]
ftcCovDist <- sapply(ftcCovs, function(rep) sum((rep[-(1:250), -(1:250)] - resCov[[dgp]]$trueCov[-(1:250), -(1:250)])^2)/(p-250)^2)
covDistMatrixsd_ftc["ftc", paste(c("Mean", "Median"),dgp) ] <- c(mean(ftcCovDist), median(ftcCovDist))
krausCovs <- lapply(resDGP[[dgp]], function(rep) rep$krausCov_ftc)
ftcCovDist <- sapply(krausCovs, function(rep) sum((rep[-(1:250), -(1:250)] - resCov[[dgp]]$trueCov[-(1:250), -(1:250)])^2)/(p-250)^2)
covDistMatrixsd_ftc["kraus",paste(c("Mean", "Median"),dgp)] <- c(mean(ftcCovDist), median(ftcCovDist))
}
(covDistMatrixsdLat_ftc <- round(covDistMatrixsd_ftc,2))
covDistBias <- matrix(NA, ncol = 2*length(DGP_names), nrow = 2)
dimnames(covDistBias) <- dimnames(distMatrix)
for(dgp in DGP_names){ # dgp <- DGP_names[1]
# FTC
# a) Bias
## Bias: Calculate the Mean of all Means
# Bias[\hat{\sigma}_{n}(s,t)] =
# = E_{MC}[\hat{\sigma}_{n}(s,t) ] - \hat{\sigma}_{n}(s,t)
# = (1/500)\sum_{r=1}^{500}[\hat{\sigma}_{n,r}(s,t)] - \sigma(s,t)
print(dgp)
ftcCovs <- lapply(resDGP[[dgp]], function(rep) rep$ftcCov) # rep <- ftcCovs[[1]]
#str(ftcCovs, max = 1); length(ftcCovs) # rep <- ftcCovs[[1]]
#str(ftcCovs1, max = 1); length(ftcCovs1) # rep <- ftcCovs[[1]]
# Stack matrix to vector
ftcCovs1 <- lapply(ftcCovs, function(rep) c(rep))
# Calculate rowMeans over all stacked matrices
ftcCovs2 <- rowMeans(matrix(unlist(ftcCovs1), nrow = p^2))
# Back transform to matrix
ftcCovs3 <- matrix(ftcCovs2, byrow = TRUE, nrow = p)
ftcCovBias <- sum( (ftcCovs3 - resCov[[dgp]]$trueCov)^2 ) /p^2
# b) Var
#Var[\hat{\sigma}_{n}(t)] =
# = E_{MC}[ (\hat{\sigma}_{n}(t) - E_{MC}[\hat{\sigma}_{n}(t) ] )^2 ]
# = (1/500)\sum_{r=1}^{500}[ (\hat{sigma}_{n,r}(t) - (1/500)\sum_{l=1}^{500}[\hat{sigma}_{n,l}(t)] )^2 ]
# = (1/500)\sum_{r=1}^{500}[ (\hat{\sigma}_{n,r}(t) - ftcCovs3 )^2 ]
ftcCovs_Var <- lapply(ftcCovs, function(rep) (rep - ftcCovs3)^2)
ftcCovs_Var1 <- lapply(ftcCovs_Var, function(rep) c(rep))
# Calculate rowMeans over all stacked matrices
ftcCovs_Var2 <- rowMeans(matrix(unlist(ftcCovs_Var1), nrow = p^2))
# Back transform to matrix
ftcCovs_Var3 <- matrix(ftcCovs_Var2, byrow = TRUE, nrow = p)
ftcCovVar <- sum(ftcCovs_Var3)/p^2
#c) Insert into matrix
covDistBias["ftc",paste(c("Mean", "Median"),dgp)] <- c(ftcCovBias,ftcCovVar)
# Kraus
# a) Bias
krausCovs <- lapply(resDGP[[dgp]], function(rep) rep$krausCov) # rep <- ftcCovs[[1]]
# Stack matrix to vector
ftcCovs1 <- lapply(krausCovs, function(rep) c(rep))
# Calculate rowMeans over all stacked matrices
ftcCovs2 <- rowMeans(matrix(unlist(ftcCovs1), nrow = p^2))
# Back transform to matrix
ftcCovs3 <- matrix(ftcCovs2, byrow = TRUE, nrow = p)
krausCovBias <- sum( (ftcCovs3 - resCov[[dgp]]$trueCov)^2 ) /p^2
# b) Var
#Var[\hat{\sigma}_{n}(t)] =
# = E_{MC}[ (\hat{\sigma}_{n}(t) - E_{MC}[\hat{\sigma}_{n}(t) ] )^2 ]
# = (1/500)\sum_{r=1}^{500}[ (\hat{sigma}_{n,r}(t) - (1/500)\sum_{l=1}^{500}[\hat{sigma}_{n,l}(t)] )^2 ]
# = (1/500)\sum_{r=1}^{500}[ (\hat{\sigma}_{n,r}(t) - ftcCovs3 )^2 ]
krausCovs_Var <- lapply(krausCovs, function(rep) (rep - ftcCovs3)^2)
ftcCovs_Var1 <- lapply(krausCovs_Var, function(rep) c(rep))
# Calculate rowMeans over all stacked matrices
ftcCovs_Var2 <- rowMeans(matrix(unlist(ftcCovs_Var1), nrow = p^2))
# Back transform to matrix
ftcCovs_Var3 <- matrix(ftcCovs_Var2, byrow = TRUE, nrow = p)
krausCovVar <- sum(ftcCovs_Var3)/p^2
# c) Insert into matrix
covDistBias["kraus",paste(c("Mean", "Median"),dgp)] <- c(krausCovBias,krausCovVar)
}
colnames(covDistBias) <- paste(rep(c("Bias", "Variance"), length(DGP_names)), rep(DGP_names, each =2))
##########################################################################################
##########################################################################################
### Summary
(distMatrixLat <- round(distMatrix,2))
corSum
lapply(selBasis, table)
lapply(lapply(romWolfDec, table), function(x) round(x/replications*100,1))
(covDistMatrixLat <- round(covDistMatrix,2))
return(list(distMatrixLat = distMatrixLat, distMatrixsdLat = distMatrixsdLat,
corSum = corSum, selBasis = selBasis, romWolfDec = romWolfDec, covDistMatrixsdLat = covDistMatrixsdLat,
covDistMatrixLat = covDistMatrixLat, covDistMatrixsdLat_ftc = covDistMatrixsdLat_ftc,
ftcBias = SqIntMeanBias,
krausBias = krausSqIntMeanBias,
ftcVar = IntftcVarMeans,
krausVar = IntkrausVarMeans,
covDistBias = covDistBias,
covDistMatrixLat_ftc = covDistMatrixLat_ftc))
})
names(allResults ) <- ns
save(allResults, file = paste0("R_Data/bid_sim_complete.RData"))
##########################################################################################
#### In all allResults now a list of
# n
## dgp
load(file = paste0("R_Data/bid_sim_complete.RData"))
path <- "/Users/stefanrameseder/Dropbox/BID DP/Round_2_CSDA_SI_Due_Apr_14_2018/Manuscript/bid_sim_means.tex"
path <- "C:\\Users\\LocalAdmin\\Dropbox\\BID DP\\Manuscript\\latexChapters\\bid_sim_means.tex"
## Latex Options
table_placement <- "!htpb"
hlineAfter <- seq(2,8, 2)
# Means
distMat <- lapply(allResults, function(n) n$distMatrixLat)
(tdistMat <- transfBidSimObj(distMat))
print(xtable(tdistMat) , type="latex", file=paste0(path), include.rownames = TRUE,
hline.after = hlineAfter,size = "\\setlength{\\tabcolsep}{0.1cm}",
table.placement = getOption("xtable.table.placement", paste(table_placement)))
distMatSD <- lapply(allResults, function(n) n$distMatrixsdLat)
tdistMatSD <- transfBidSimObj(distMatSD)
print(xtable(tdistMatSD) , type="latex", file=path, include.rownames = TRUE,
hline.after = hlineAfter,size = "\\setlength{\\tabcolsep}{0.1cm}",
table.placement = getOption("xtable.table.placement", paste(table_placement)))
# Biases and Variances
ftcbias <- lapply(allResults, function(n) n$ftcBias)
krausbias <- lapply(allResults, function(n) n$krausBias)
ftcvar <- lapply(allResults, function(n) n$ftcVar)
krausvar <- lapply(allResults, function(n) n$krausVar)
str(ftcBias, max = 2)
biasAndVars <- matrix(NA, ncol = length(DGP_names)*2, nrow = length(ns)*2)
colnames(biasAndVars) <- paste0(c("bias", "var"),rep(DGP_names, each = 2))
rownames(biasAndVars) <- paste0(c("ftc", "kraus"),rep(ns, each = 2))
for(n in ns){ # n <- ns[1]
for(est in c("ftc", "kraus")){ # est <- "ftc"
for(stat in c("bias", "var")){ # stat <- "bias"
for(dgp in DGP_names){ # dgp <- DGP_names[1]
biasAndVars[ paste0(est,as.character(n)) , paste0(stat, dgp)] <- get(paste0(est, stat))[[as.character(n)]][[dgp]]
}
}
}
}
round(biasAndVars, 3)
unlist(ftcbias)
unlist(ftcvar)
# Bring all together
# Covariances
covDistMatrix <- lapply(allResults, function(n) n$covDistBias)
(tcovDistMatrix <- round(transfBidSimObj(covDistMatrix),1))
print(xtable(tcovDistMatrix) , type="latex", file=path, include.rownames = TRUE,
hline.after = hlineAfter,size = "\\setlength{\\tabcolsep}{0.1cm}",
table.placement = getOption("xtable.table.placement", paste(table_placement)))
covDistMatrixSD <- lapply(allResults, function(n) n$covDistMatrixsdLat)
tcovDistMatrixSD <- transfBidSimObj(covDistMatrixSD)
print(xtable(tcovDistMatrixSD) , type="latex", file=paste0("C:\\Users\\LocalAdmin\\Dropbox\\BID DP\\Manuscript\\latexChapters\\bid_sim_covs_sd.tex"), include.rownames = TRUE,
hline.after = hlineAfter,size = "\\setlength{\\tabcolsep}{0.1cm}",
table.placement = getOption("xtable.table.placement", paste(table_placement)))
covDistMatrix <- lapply(allResults, function(n) n$covDistMatrixLat)
covDistMatrixSD <- transfBidSimObj(covDistMatrix)
print(xtable(covDistMatrixSD) , type="latex", file=path, include.rownames = TRUE,
hline.after = hlineAfter,size = "\\setlength{\\tabcolsep}{0.1cm}",
table.placement = getOption("xtable.table.placement", paste(table_placement)))
# Romano Wolf
romWolf <- lapply(allResults, function(n) n$romWolfDec) # n <- romWolf[[1]]; dgp <- n[[1]]
romWolfMatrix <- t(sapply(romWolf, function(n) {
res <- lapply(n, function(dgp){
dgpTab <- round(table(factor(dgp, levels = c("Null", "(V)", "Other with (V)", "Other")))/replications*100,1)
})
resLong <- c(do.call("cbind",res))
names(resLong) <- rep(c("Null", "(V)", "Other with (V)", "Other"), times = 4)
return(resLong)
}))
romWolfMatrix
latromWolfMatrix <- xtable(romWolfMatrix)
align(latromWolfMatrix) <- c("c|", rep(c("c","c","c|"), times = 4))
print(latromWolfMatrix , type="latex", file=paste0("C:\\Users\\LocalAdmin\\Dropbox\\BID DP\\Manuscript\\latexChapters\\bid_sim_romWolf.tex"), include.rownames = TRUE,
table.placement = getOption("xtable.table.placement", paste(table_placement)))
# Selected Basis:
selBasis <- lapply(allResults, function(n) n$selBasis) # n <- selBasis[[1]]; dgp <- n[[1]]
selBasisMatrix <- lapply(selBasis, function(n) {
res <- t(sapply(n, function(dgp){
dgpTab <-round(table(factor(dgp, levels = seq(3,maxAllowedBasis,2)))/replications*100,1)
}))
return(res)})
cNames <- colnames(selBasisMatrix[[1]])
rNames <- rownames(selBasisMatrix[[1]])
selBasisResMatrix <- matrix(NA, ncol = length(cNames), nrow = length(rNames)*length(ns))
colnames(selBasisResMatrix) <- cNames
rownames(selBasisResMatrix) <- paste0(rep(ns, each = length(rNames)), rNames)
for(n in ns){
for(cname in cNames){
for(rname in rNames){
selBasisResMatrix[ paste0(n, rname) , cname] <- selBasisMatrix[[as.character(n)]][rname , cname]
}
}
}
round(selBasisResMatrix,1)
selBasisResMatrix <- xtable(round(selBasisResMatrix,1))
align(selBasisResMatrix) <- c("c", "c","|c|", rep("c", times = 10))
print(selBasisResMatrix , type="latex", file=paste0("C:\\Users\\LocalAdmin\\Dropbox\\BID DP\\Manuscript\\latexChapters\\bid_sim_selBasis.tex"),
include.rownames = TRUE, size = "\\setlength{\\tabcolsep}{0.1cm}", hline.after = seq(4, 4*length(ns), 4),
table.placement = getOption("xtable.table.placement", paste(table_placement)))
# Correlations
usedCorrelations <- lapply(allResults, function(n) n$corSum) # n <- selBasis[[1]]; dgp <- n[[1]]
usedCorrelationsMatrix <- matrix(NA, ncol = length(rNames), nrow = length(ns))
colnames(usedCorrelationsMatrix) <- rNames
rownames(usedCorrelationsMatrix) <- ns
for(n in ns){
for(rname in rNames){
usedCorrelationsMatrix[ as.character(n) , rname] <- round(usedCorrelations[[as.character(n)]][[rname]]["Mean"],2)
}
}
usedCorrelationsMatrix <- xtable(round(usedCorrelationsMatrix,1))
print(usedCorrelationsMatrix , type="latex", file=paste0("C:\\Users\\LocalAdmin\\Dropbox\\BID DP\\Manuscript\\latexChapters\\bid_sim_selCor.tex"),
include.rownames = TRUE, size = "\\setlength{\\tabcolsep}{0.1cm}",
table.placement = getOption("xtable.table.placement", paste(table_placement)))