# PRACTICAL EXERCISE 11 # ===================== # Read data: path="http://www.uio.no/studier/emner/matnat/math/STK4080/h14/lungcancer.txt" lungcancer=read.table(path,header=T) # Question a # ---------- # Use the glm-command to compute the logarithm of the occurrence/exposure rates: fit.age=glm(cancer~offset(log(4*population))+factor(age)-1, family=poisson, data=lungcancer) summary(fit.age) # Question b # ---------- # Read a function that computes the exponentials of the coefficients # from a glm-fit with corresponding confidence intervals: expcoef=function(glmobj) { regtab=summary(glmobj)\$coef expcoef=exp(regtab[,1]) lower=expcoef*exp(-1.96*regtab[,2]) upper=expcoef*exp(1.96*regtab[,2]) cbind(expcoef,lower,upper) } # Compute occurrence/exposure rates with log-transformed confidence limits: expcoef(fit.age) # Question c # ---------- # Fit a model with age and city: fit.age.city=glm(cancer~offset(log(4*population))+factor(age)+factor(city)-1, family=poisson, data=lungcancer) summary(fit.age.city) expcoef(fit.age.city) # Question d # ---------- # Test if there is an effect of city: anova(fit.age,fit.age.city,test="Chisq")