## create P1 and P2 stock tables
dn <- LETTERS[1:4]
P1 <- matrix(c(1000, 100, 10, 0, 55, 555, 50, 5, 80, 40, 800, 40, 20, 25, 20, 200), 4, 4,
dimnames = list(pob = dn, por = dn), byrow = TRUE)
P2 <- matrix(c(950, 100, 60, 0, 80, 505, 75, 5, 90, 30, 800, 40, 40, 45, 0, 180), 4, 4,
dimnames = list(pob = dn, por = dn), byrow = TRUE)
# display with row and col totals
addmargins(P1)
addmargins(P2)
# no births and deaths
b <- rep(0, 4)
d <- rep(0, 4)
y <- ffs(P1, P2, d, b)
# display with row, col and table totals
round(addmargins(y$mu), 1)
# display with row and col totals
round(fm(y$mu), 1)
## alternative offset term
dis <- array(c(1, 2, 3, 4, 2, 1, 5, 6, 3, 4, 1, 7, 4, 6, 7, 1), c(4, 4, 4))
y <- ffs(P1, P2, d, b, dis)
# display with row, col and table totals
round(addmargins(y$mu), 1)
# display with row and col totals
round(fm(y$mu), 1)
## alternative P2 and changes in population from natural increase
P2 <- matrix(c(1060, 60, 10, 10, 45, 540, 40, 0, 70, 75, 770, 70, 30, 30, 20, 230), 4, 4,
dimnames = list(pob = dn, por = dn), byrow = TRUE)
# display with row and col totals
addmargins(P2)
b <- c(80, 20, 40, 60)
d <- c(70, 30, 50, 10)
y <- ffs(P1, P2, d, b)
# display with row, col and table totals
round(addmargins(y$mu), 1)
# display with row and col totals
round(fm(y$mu), 1)
Run the code above in your browser using DataLab