# NOT RUN {
dn <- LETTERS[1:4]
P1 <- matrix(data = c(1000, 100, 10, 0, 55, 555, 50, 5, 80, 40, 800, 40, 20, 25, 20, 200),
nrow = 4, ncol = 4, dimnames = list(pob = dn, por = dn), byrow = TRUE)
P2 <- matrix(data = c(950, 100, 60, 0, 80, 505, 75, 5, 90, 30, 800, 40, 40, 45, 0, 180),
nrow = 4, ncol = 4, dimnames = list(pob = dn, por = dn), byrow = TRUE)
# display with row and col totals
addmargins(A = P1)
addmargins(A = P2)
# births and deaths
b <- rep(x = 10, 4)
d <- rep(x = 5, 4)
# no change in stocks, but 20 more births than deaths...
sum(P2 - P1) + sum(b - d)
# rescale
y <- rescale_nb(m1 = P1, m2 = P2, b = b, d = d)
y
sum(y$m1_adj - y$m2_adj) + sum(b - d)
# check for when extra is positive and odd
d[1] <- 31
d
sum(P2 - P1) - sum(b - d)
# rescale
y <- rescale_nb(m1 = P1, m2 = P2, b = b, d = d)
sum(y$m1_adj - y$m2_adj) - sum(b - d)
# }
Run the code above in your browser using DataLab