-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFittingModels.R
51 lines (29 loc) · 1.28 KB
/
FittingModels.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
library(StMoMo); library(demography)
genderList <- c("male", "female"); agesFit <- 50:89; yearsFit <- 1960:1990
countryList <- c("BLR","AUT", "BEL", "FRATNP","IRL","ITA","JPN", "USA", "GBRTENW","CHE")
dataList <- function(ages, years, genderList, countryList)
{
for (c in 1:length(countryList)) { for (g in 1:length(genderList))
{
nAg <- length(ages); nYr <- length(years)
MorData <- lapply(countryList, function(x) hmd.mx(country = x, username = "[email protected]", password = "Salva=0606"))
DataStMoMo <- lapply(1:length(MorData), function(i) lapply(genderList, function(x) StMoMoData(MorData[[i]], x)))
}
}
return(DataStMoMo)
}
data <- dataList(agesFit, yearsFit, genderList, countryList)
fitModel <- function(data)
{
LC <- lc(); APC <- apc(); CBD <- cbd(link = "log"); M7 <- m7(link = "log")
RH <- rh(approxConst = TRUE); PLAT = plat()
models <- list(LC, RH, APC, CBD, M7, PLAT)
modelNames <- c("LC","RH", "APC", "CBD", "M7", "PLAT")
fitModels <- list()
for (c in 1:length(countryList))
{
fitModels[[c]] <- lapply(1:length(genderList), function(g) lapply(models, function(x) fit(x, data = data[[c]][[g]], ages.fit = agesFit, years.fit = yearsFit)))
}
return(fitModels)
}
fitCountry <- fitModel(data)