-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerateExampleResults.R
106 lines (89 loc) · 5.21 KB
/
generateExampleResults.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
# function for analyzing example datasets
# first name elements of ed to be the same as the corresponding elements of the simulated datasets
generateExampleResults = function(targetPop=c("women", "children"), verbose=TRUE, startI=7, endI=Inf, family=c("binomial", "betabinomial"),
urbanPrior=FALSE, nBuffer=15, skipThreeLayer=FALSE) {
family = match.arg(family)
targetPop = match.arg(targetPop)
if(targetPop == "women") {
load("../U5MR/kenyaDataEd.RData")
dat=ed
dataType="ed"
resultNameRoot="Ed"
} else {
load("../U5MR/kenyaData.RData")
dat=mort
dataType="mort"
resultNameRoot="Mort"
}
resultNameRootLower = tolower(resultNameRoot)
familyText=""
if(family == "binomial")
familyText = "_LgtN"
clusterEffect = family == "binomial"
##### run SPDE
argList = list(list(dat = dat, urbanEffect = FALSE),
list(dat = dat, urbanEffect = TRUE))
otherArguments = list(dataType=dataType, verbose=verbose, family=family, clusterEffect=clusterEffect)
for(i in 1:length(argList)) {
if(startI <= i && i <= endI) {
args = argList[[i]]
urbanEffect = args$urbanEffect
fileName = paste0("savedOutput/", resultNameRoot, "/resultsSPDE", resultNameRootLower,
"_urbanEffect", urbanEffect, familyText, ".RData")
print(paste0("Fitting SPDE model with urbanEffect=", urbanEffect, "..."))
spdeResults = do.call("fitSPDEKenyaDat", c(args, otherArguments))
print(paste0("Aggregating SPDE model with urbanEffect=", urbanEffect, "..."))
aggregatedSPDEresults = aggregateModelResultsKenya(spdeResults, clusterLevel=TRUE, pixelLevel=TRUE,
countyLevel=TRUE, regionLevel=TRUE, targetPop=targetPop)
spdeResults$mlik = spdeResults$mod$mlik
spdeResults$mod = NULL # make sure saved file isn't too large
results = list(fit=spdeResults, aggregatedResults=aggregatedSPDEresults)
save(results, file=fileName)
}
}
##### run LK-INLA
dirichletConcentration1=1.5
dirichletConcentration2=3
dirichletConcentration3=5
argList = list(list(dat = dat, separateRanges = FALSE, urbanEffect = FALSE),
list(dat = dat, separateRanges = FALSE, urbanEffect = TRUE),
list(dat = dat, separateRanges = TRUE, urbanEffect = FALSE),
list(dat = dat, separateRanges = TRUE, urbanEffect = TRUE),
list(dat = dat, separateRanges = FALSE, urbanEffect = FALSE, dirichletConcentration=dirichletConcentration2),
list(dat = dat, separateRanges = FALSE, urbanEffect = TRUE, dirichletConcentration=dirichletConcentration2),
list(dat = dat, separateRanges = TRUE, urbanEffect = FALSE, dirichletConcentration=dirichletConcentration2),
list(dat = dat, separateRanges = TRUE, urbanEffect = TRUE, dirichletConcentration=dirichletConcentration2),
list(dat = dat, separateRanges = FALSE, urbanEffect = FALSE, dirichletConcentration=dirichletConcentration3),
list(dat = dat, separateRanges = FALSE, urbanEffect = TRUE, dirichletConcentration=dirichletConcentration3),
list(dat = dat, separateRanges = TRUE, urbanEffect = FALSE, dirichletConcentration=dirichletConcentration3),
list(dat = dat, separateRanges = TRUE, urbanEffect = TRUE, dirichletConcentration=dirichletConcentration3))
otherArguments = list(dataType=dataType, verbose=verbose, family=family, clusterEffect=clusterEffect,
useUrbanPrior=urbanPrior, nBuffer=nBuffer)
for(i in 1:length(argList)) {
if(startI <= i + 2 && i + 2 <= endI) {
args = argList[[i]]
separateRanges = args$separateRanges
urbanEffect = args$urbanEffect
dirichletConcentration = args$dirichletConcentration
if(skipThreeLayer && !separateRanges) {
next
}
urbanPriorText = ""
if(!urbanPrior && separateRanges)
urbanPriorText = "_noUrbanPrior"
concentrationText = paste0("_conc", dirichletConcentration)
fileName = paste0("savedOutput/", resultNameRoot, "/resultsLKINLA", resultNameRootLower, "_separateRanges", separateRanges,
"_urbanEffect", urbanEffect, familyText, urbanPriorText, concentrationText, ".RData")
print(paste0("Fitting LK-INLA model with separateRanges=", separateRanges, ", urbanEffect=", urbanEffect, ", and concentration parameter ", dirichletConcentration, "..."))
lkinlaResults = do.call("fitLKINLAKenyaDat", c(args, otherArguments))
print(paste0("Aggregating LK-INLA model with separateRanges=", separateRanges, " and urbanEffect=", urbanEffect, "..."))
aggregatedLKINLAresults = aggregateModelResultsKenya(lkinlaResults, clusterLevel=TRUE, pixelLevel=TRUE,
countyLevel=TRUE, regionLevel=TRUE, targetPop=targetPop)
lkinlaResults$mlik = lkinlaResults$mod$mlik
lkinlaResults$mod = NULL # make sure saved file isn't too large
results = list(fit=lkinlaResults, aggregatedResults=aggregatedLKINLAresults)
save(results, file=fileName)
}
}
invisible(NULL)
}