-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcalculate-dispersion-param.R
62 lines (46 loc) · 2.26 KB
/
calculate-dispersion-param.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
path.code <- Sys.getenv("path.code")
path.output_data <- Sys.getenv("path.output_data")
this.folder <- "exchangeable"
source(file.path(path.code, "datagen-utils.R"))
###############################################################################
# Calculate value of dispersion parameter for base case
###############################################################################
dat.mu <- read.csv(file.path(path.output_data, this.folder, "base_case/input_means.csv"))
dat.tau <- read.csv(file.path(path.output_data, this.folder, "base_case/input_prop_zeros.csv"))
dat.disp <- dat.mu
dat.disp[,2:7] <- NA
for(this.row in 1:6){
for(this.column in 2:7){
use.mu <- dat.mu[this.row, this.column]
use.prop.zeros <- dat.tau[this.row, this.column]
val <- SolveForSigmaSquared(input.mu = use.mu, input.prop.zeros = use.prop.zeros)
dat.disp[this.row, this.column] <- val
}
}
write.csv(dat.disp, file.path(path.output_data, this.folder, "base_case/dispersion_parameter.csv"))
###############################################################################
# Calculate value of dispersion parameter for cases within sim_vary_effect
###############################################################################
list.dat <- list()
for(idx.scenario in 1:10){
dat.mu <- read.csv(file.path(path.output_data, this.folder, "sim_vary_effect", paste("sim_results", idx.scenario, sep="_"), "input_means.csv"))
dat.tau <- read.csv(file.path(path.output_data, this.folder, "sim_vary_effect", paste("sim_results", idx.scenario, sep="_"), "input_prop_zeros.csv"))
dat.disp <- dat.mu
dat.disp[,2:7] <- NA
for(this.row in 1:6){
for(this.column in 2:7){
use.mu <- dat.mu[this.row, this.column]
use.prop.zeros <- dat.tau[this.row, this.column]
val <- SolveForSigmaSquared(input.mu = use.mu, input.prop.zeros = use.prop.zeros)
dat.disp[this.row, this.column] <- val
}
}
list.dat <- append(list.dat, list(dat.disp))
write.csv(dat.disp, file.path(path.output_data, this.folder, "sim_vary_effect", paste("sim_results", idx.scenario, sep="_"), "dispersion_parameter.csv"))
}
list.pct <- list()
for(i in 2:10){
dat.pct <- (list.dat[[i]][,2:7] - list.dat[[1]][,2:7])/list.dat[[1]][,2:7]
list.pct <- append(list.pct, list(dat.pct))
}
print(list.pct)