# NOT RUN {
par(mfrow = c(1, 2))
plot(female / (male + female) ~ year, chinese.nz, type = "b",
ylab = "Proportion", col = "blue", las = 1,
cex = 0.015 * sqrt(male + female),
# cex = 0.10 * sqrt((male + female)^1.5 / sqrt(female) / sqrt(male)),
main = "Proportion of NZ Chinese that are female")
abline(h = 0.5, lty = "dashed", col = "gray")
fit1.cnz <- vglm(cbind(female, male) ~ year, binomialff,
data = chinese.nz)
fit2.cnz <- vglm(cbind(female, male) ~ sm.poly(year, 2), binomialff,
data = chinese.nz)
fit4.cnz <- vglm(cbind(female, male) ~ sm.bs(year, 5), binomialff,
data = chinese.nz)
lines(fitted(fit1.cnz) ~ year, chinese.nz, col = "purple", lty = 1)
lines(fitted(fit2.cnz) ~ year, chinese.nz, col = "green", lty = 2)
lines(fitted(fit4.cnz) ~ year, chinese.nz, col = "orange", lwd = 2, lty = 1)
legend("bottomright", col = c("purple", "green", "orange"),
lty = c(1, 2, 1), leg = c("linear", "quadratic", "B-spline"))
plot(100*(male+female)/nz ~ year, chinese.nz, type = "b", ylab = "Percent",
ylim = c(0, max(100*(male+female)/nz)), col = "blue", las = 1,
main = "Percent of NZers that are Chinese")
abline(h = 0, lty = "dashed", col = "gray")
# }
Run the code above in your browser using DataLab