Created
August 14, 2018 14:25
-
-
Save timriffe/5c432a9d51e50813a9f0a6418a84c954 to your computer and use it in GitHub Desktop.
rescale single ages to a known prior in some larger age groups
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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