Skip to content

Commit

Permalink
Tidy unneeded birthrate functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
pwinskill committed Jul 26, 2022
1 parent 38b3ec4 commit 4670e6a
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 15 deletions.
1 change: 0 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ export(AL_params)
export(DHA_PQP_params)
export(SP_AQ_params)
export(arab_params)
export(find_birthrates)
export(fun_params)
export(gamb_params)
export(get_correlation_parameters)
Expand Down
14 changes: 1 addition & 13 deletions R/population_parameters.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,12 @@ set_demography <- function(
deathrates
) {

stopifnot(all(timesteps >= 0))
if(min(timesteps) != 0){
stop("Must include the baseline demography (timesteps must include 0),
when setting a custom demography")
}

stopifnot(all(agegroups > 0))
stopifnot(all(timesteps >= 0))
stopifnot(all(deathrates > 0 & deathrates < 1))
stopifnot(length(agegroups) == ncol(deathrates))
stopifnot(length(timesteps) == nrow(deathrates))
Expand All @@ -30,8 +29,6 @@ set_demography <- function(
parameters$deathrate_agegroups <- agegroups
parameters$deathrate_timesteps <- timesteps
parameters$deathrates <- deathrates
parameters$birthrates <- find_birthrates(parameters$human_population, agegroups, deathrates[1,])
parameters$birthrate_timesteps <- 0

parameters
}
Expand Down Expand Up @@ -63,7 +60,6 @@ get_equilibrium_population <- function(age_high, birthrate, deathrates) {
#' @param age_high a vector of age groups
#' @param deathrates vector of deathrates for each age group
#' @importFrom stats uniroot
#' @export
find_birthrates <- function(pops, age_high, deathrates) {
vnapply(
pops,
Expand All @@ -76,14 +72,6 @@ find_birthrates <- function(pops, age_high, deathrates) {
)
}

get_birthrate <- function(parameters, timestep) {
if (!parameters$custom_demography) {
return(1 / parameters$average_age * get_human_population(parameters, timestep))
}
last_birthrate <- match_last_timestep(parameters$birthrate_timesteps, timestep)
parameters$birthrates[last_birthrate]
}

get_human_population <- function(parameters, timestep) {
last_pop <- match_last_timestep(parameters$human_population_timesteps, timestep)
parameters$human_population[last_pop]
Expand Down
2 changes: 1 addition & 1 deletion R/variables.R
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ calculate_initial_ages <- function(parameters) {
age_width <- diff(c(0, age_high))
age_low <- age_high - age_width
n_age <- length(age_high)
birthrate <- get_birthrate(parameters, 0)
birthrate <- find_birthrates(parameters$human_population, agegroups, deathrates[1,])
deathrates <- parameters$deathrates[1,]

eq_pop <- get_equilibrium_population(age_high, birthrate, deathrates)
Expand Down

0 comments on commit 4670e6a

Please sign in to comment.