Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pop.sim in demography - confusing dimnames #30

Open
ghost opened this issue May 27, 2018 · 0 comments
Open

pop.sim in demography - confusing dimnames #30

ghost opened this issue May 27, 2018 · 0 comments

Comments

@ghost
Copy link

ghost commented May 27, 2018

When forecasting population with pop.sim in demography package, I find the dimnames in output confusing.
Here is my example:

library("demography")

mort.fo <- read.demogdata(file = "data/mort_no.txt", popfile = "data/pop_fo.txt", type = "mortality", label = "Føroyar", skip = 0)
mort.fo <- extract.years(mort.fo, 1985:2007)

fert.fo <- read.demogdata(file = "data/fert_rate.txt", popfile = "data/pop_fert.txt", type = "fertility", label = "Føroyar", skip = 0, lambda = 0.4)
fert.fo <- extract.years(fert.fo, 1985:2007)

mort.sm <- smooth.demogdata(extract.years(mort.fo, 1985:2006))
fert.sm <- smooth.demogdata(extract.years(fert.fo, 1985:2006))
mig.fo <- netmigration(mort.fo, fert.fo)

mort.fit <- coherentfdm(mort.sm)
fert.fit <- fdm(fert.sm)
mig.fit <- coherentfdm(mig.fo)

mort.fcast <- forecast(mort.fit, h = 40, level = 95)
fert.fcast <- forecast(fert.fit, h = 40, level = 95)
mig.fcast <- forecast(mig.fit, h = 40, level = 95)

set.seed(27052018) # dagfesting fyri fyrstu simulering
sim10000 <- pop.sim(mort = mort.fcast, fert = fert.fcast, mig = mig.fcast, firstyearpop = mort.fo, N = 10000, mfratio = 1.05, bootstrap = T)

Output

In this case the firstyearpop is medio 2007, and the first forecasted year have the dimname = 2007, it does not make sense to me, it should be 2008. Am I right or wrong?
I made a forecast 40 year a head. While comparing forecasted population with dimname = 2007, with actual population 2007, it does not fit at all, but fit perfectly with actual population 2008. Dimname 2016 fit also very well with actual population 2017.

What about changing pop.sim function to something like this:

at the very end of the pop.sim function, line number 153 and 154 it says:

dimnames(pop.m)[[2]] <- dimnames(pop.m)[[2]] <- firstyr +
(1:h) - 1
return(list(male = pop.m, female = pop.f))
}

Changed to:

dimnames(pop.m)[[2]] <- dimnames(pop.f)[[2]] <- firstyr +
(1:h)
return(list(male = pop.m, female = pop.f))
}

What do you think?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

0 participants