par(mfrow = c(1, 2))
plot(female / (male + female) ~ year, chinese.nz, type = "b",
ylab = "Proportion", col = "blue", las = 1,
main = "Proportion of NZ Chinese that are female")
abline(h = 0.5, lty = "dashed", col = "gray")
fit1.cnz <- vglm(cbind(female, male) ~ year, binomialff, chinese.nz)
fit2.cnz <- vglm(cbind(female, male) ~ poly(year, 2), binomialff, chinese.nz)
fit4.cnz <- vglm(cbind(female, male) ~ bs(year, 5), binomialff, chinese.nz)
lines(fitted(fit1.cnz) ~ year, chinese.nz, col = "purple")
lines(fitted(fit2.cnz) ~ year, chinese.nz, col = "green")
lines(fitted(fit4.cnz) ~ year, chinese.nz, col = "orange", lwd = 2)
legend("bottomright", col = c("purple", "green", "orange"),
lty = 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