##### Code for Lecture on Poisson regression ###Example - effects of age and birth location (wild or captive) on litter sizes in red wolves ### Litter size is not normally distribution (skewed to the left) and isn't continuous ###import the data datum=read.csv(file.choose()) ###Analyze the data using glm help(glm) #glm is the same as lm, but requires an additional argument - family, which specifies what the error structure is results=glm(LitterSize~Age+BirthLoc,data=datum,family=poisson) ### runs a Poisson regression summary(results) #examine the results #Call: #glm(formula = LitterSize ~ BirthLoc + Age, family = poisson, # data = datum) # #Deviance Residuals: # Min 1Q Median 3Q Max #-2.2591 -1.1052 -0.1177 0.6177 2.8361 # #Coefficients: # Estimate Std. Error z value Pr(>|z|) #(Intercept) -0.21178 0.15463 -1.370 0.171 #BirthLoc 1.70471 0.12722 13.400 < 2e-16 *** #Age 0.10908 0.01627 6.703 2.05e-11 *** #--- #Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 # # #(Dispersion parameter for poisson family taken to be 1) # # Null deviance: 443.85 on 98 degrees of freedom #Residual deviance: 122.54 on 96 degrees of freedom #AIC: 411.91 # #Number of Fisher Scoring iterations: 5 # Note that coefficient estimates cannot be interpreted as is. # To make conclusions about effect, must take exp to the coefficient power # Value represents a multiplier effect of dependent variable on average outcome ### Examples ## Effect of Birth Location exp(1.70471) # Wild born wolves have 5.5 times as many pups per litter (on average) as captive born wolves # to calculate confidence limits exp(confint(results)) # Wild born individuals have 5.5 times (4.26 - 7.09; 95% CL; p<0.0001) # as many pups as captive born individuals ## Effect of Age exp(0.10908) # For each 1 year increase in age, wolves had 1.11 times as many pups exp(0.10908*(5)) # For each 5-year increase in age, wolves had 1.73 times as many pups min(datum$Age) #minimum age in data-set was 1 max(datum$Age) #maximum age in data-set was 10 exp(0.10908*(10-1))) # the oldest wolves had 2.66 times as many pups as the youngest wolves ###Prediction #How many pups does a wild-born, 5-year-old wolf have, on average? exp(-0.21178+1.70471+0.10908*5)