Skip to content

Instantly share code, notes, and snippets.

@timriffe
Created August 14, 2018 14:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save timriffe/5c432a9d51e50813a9f0a6418a84c954 to your computer and use it in GitHub Desktop.
Save timriffe/5c432a9d51e50813a9f0a6418a84c954 to your computer and use it in GitHub Desktop.
rescale single ages to a known prior in some larger age groups
install_github("timriffe/DemoTools")
library(DemoTools)
pop1 <- runif(20)
Age1 <- 0:19
pop2 <- DemoTools::groupAges(pop1,0:19) * c(1.1,1.05,.95,1.01)
Age2 <- seq(0,15,by=5)
# I'll use rescale.vector
rescaleAgeGroups <- function(Value1, Age1, Value2, Age2){
stopifnot(is_single(Age1))
int2 <- age2int(Age2,FALSE)
AgeN <- rep(Age2,times = int2)
beforeN <- groupAges(Value1, Age1, AgeN = AgeN)
beforeNint <- rep(beforeN, times = int2)
afterNint <- rep(Value2, times = int2)
ratio <- afterNint / beforeNint
Value1 * ratio
}
rescaleAgeGroups(pop1,Age1,pop2,Age2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment