# PRACTICAL EXERCISE 10 # ===================== # Read data: path="http://www.uio.no/studier/emner/matnat/math/STK4080/h14/lungcancer.txt" lungcancer=read.table(path,header=T) # Question a # ---------- # Compute number of lung cancer cases and person years aggregated over cities: lung.aggr=aggregate(lungcancer,list(age.group=lungcancer$age),sum) cancer.cases=lung.aggr$cancer pyears=4*lung.aggr$population # Question b # ---------- # Compute the lung cancer rates and their standard errors: occexp=cancer.cases/pyears occexp.se=occexp/sqrt(cancer.cases) ? # Plot lung rates per 1000 person-years with 95% standard confidence limits: plot(c(47.5,57.5,62.5,67.5,72.5), 1000*occexp,type='l', ylim=c(0,6), xlim=c(45,75), xlab="Age",ylab="Lung cancer rates per 1000") lines(c(47.5,57.5,62.5,67.5,72.5), 1000*(occexp-1.96*occexp.se), lty=2) lines(c(47.5,57.5,62.5,67.5,72.5), 1000*(occexp+1.96*occexp.se), lty=2) # Question c # ---------- # Add 95% log-transformed confidence limits: lines(c(47.5,57.5,62.5,67.5,72.5), 1000*occexp*exp(-1.96/sqrt(cancer.cases)), lty=2,col='red') lines(c(47.5,57.5,62.5,67.5,72.5), 1000*occexp*exp(1.96/sqrt(cancer.cases)), lty=2,col='red')