## weight age.years lat site
## 1 12615.13 41 2.690077 Site 1
## 2 12539.55 50 2.974857 Site 2
## 3 13753.97 21 -4.868759 Site 1
## 4 17269.26 50 -28.437431 Site 2
## 5 16945.27 16 -26.414605 Site 1
## 6 14723.24 39 -11.392111 Site 2
first = glm(weight~age.years+site+age.years:site)
second = glm(weight~age.years+site)
third = glm(weight~age.years*site)
fourth = glm(weight~poly(age.years,2)+site
The First and Third (same model/design matrix, but different code syntax) allow the effect of slope to be different at each level of site. These are interactions b/w variables, such that the variables co-depend on each other.
The Second allows there to be a site-level differences but the same slope
The fourth also allows a site level difference of a quadratic effect, but the same quadratic effect
Main take away - all allow for different effects of age.years by site, but the First and Third let the effect/slope be different, while the other models just move the same slope up and down due to site.
glm(weight~age.years+site)
The plot should have weight on the y-axis and age.years on the x-axis. There should be two lines, representing the slopes of age.years for each site. The slopes should be parallel with site 2 lower than site 1. The slope for site 2 should be lower on the y-axis than site 1.
glm(weight~age.years+site)
glm(weight~age.years*site)
## (Intercept) age.years siteSite 2
## 1 1 41 0
## 2 1 50 1
## 3 1 21 0
## 4 1 50 1
## 5 1 16 0
## 6 1 39 1
## (Intercept) age.years siteSite 2 age.years:siteSite 2
## 1 1 41 0 0
## 2 1 50 1 50
## 3 1 21 0 0
## 4 1 50 1 50
## 5 1 16 0 0
## 6 1 39 1 39
When there are many levels of the categorical variable and not a lot of replicate data at each or some levels. Also, when the hypothesis is an effect of difference by each level, but the same slope.
dat$age.yeras.sc = scale(dat$age.years,center=TRUE, scale=FALSE)
summary(glm(weight~age.yeras.sc*site,data=dat))
##
## Call:
## glm(formula = weight ~ age.yeras.sc * site, data = dat)
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 14574.77 241.92 60.245 < 2e-16 ***
## age.yeras.sc -65.32 24.35 -2.682 0.00861 **
## siteSite 2 -188.06 342.00 -0.550 0.58367
## age.yeras.sc:siteSite 2 108.48 32.14 3.375 0.00107 **
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## (Dispersion parameter for gaussian family taken to be 2908337)
##
## Null deviance: 313494594 on 99 degrees of freedom
## Residual deviance: 279200364 on 96 degrees of freedom
## AIC: 1778
##
## Number of Fisher Scoring iterations: 2
Intercept = the mean weight of elephants at the observed mean age of elephants at site 1
age.yeras.sc = the one year change in mean weight of elephants at site 1
siteSite 2 = the mean weight effect difference of site 2 from site 1 (intercept) at the mean observed age of elephants.
age.yeras.sc:siteSite 2 - the change in the slope or one year change in mean weight of elephants at site 2 from site 1