I've been trying to get a better grasp of statistics lately, and have been wondering why exactly independent observations matter when building a model? This is a broad question, but I'm curious about the math behind the idea and also interested in tying the concept to an application.
In my efforts, I have been experimenting with the ChickWeight
dataset in R. This dataset contains repeated measures of chickens at different times while eating different diets. The main question of this data set is, "Does diet have an effect on weight?"
I'm hoping this application narrows down my question.
I have run two different models, one not accounting for repeated measures and another that does account for repeated measures in the data.
Why are the fixed effect coefficients different for both models?
What is it about accounting for repeated measures that changes the fixed effect coefficients?
If the coefficients didn't change, would that indicate that there is no strong interdependence in the observations?
Is there a way to see this change in the diagnostic plots of the model?
Here is my code:
library(lme4)
head(ChickWeight)
#> Grouped Data: weight ~ Time | Chick
#> weight Time Chick Diet
#> 1 42 0 1 1
#> 2 51 2 1 1
#> 3 59 4 1 1
#> 4 64 6 1 1
#> 5 76 8 1 1
#> 6 93 10 1 1
dependent.glm <- glm(weight ~ Diet, data = ChickWeight,
family = Gamma(link = 'log'))
summary(dependent.glm)
#>
#> Call:
#> glm(formula = weight ~ Diet, family = Gamma(link = "log"), data = ChickWeight)
#>
#> Deviance Residuals:
#> Min 1Q Median 3Q Max
#> -1.0694 -0.5614 -0.1212 0.3113 1.3284
#>
#> Coefficients:
#> Estimate Std. Error t value Pr(>|t|)
#> (Intercept) 4.63128 0.03788 122.256 < 2e-16 ***
#> Diet2 0.17778 0.06376 2.788 0.00548 **
#> Diet3 0.33121 0.06376 5.194 2.86e-07 ***
#> Diet4 0.27594 0.06411 4.304 1.97e-05 ***
#> ---
#> Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#>
#> (Dispersion parameter for Gamma family taken to be 0.3157066)
#>
#> Null deviance: 193.02 on 577 degrees of freedom
#> Residual deviance: 182.34 on 574 degrees of freedom
#> AIC: 6372.4
#>
#> Number of Fisher Scoring iterations: 5
par(mfrow = c(2,2))
plot(dependent.glm)
independent.glm <- glmer(weight ~ Diet + (1 | Chick), data = ChickWeight,
family = Gamma(link = 'log'))
summary(independent.glm)
#> Generalized linear mixed model fit by maximum likelihood (Laplace
#> Approximation) [glmerMod]
#> Family: Gamma ( log )
#> Formula: weight ~ Diet + (1 | Chick)
#> Data: ChickWeight
#>
#> AIC BIC logLik deviance df.resid
#> 6344.1 6370.2 -3166.0 6332.1 572
#>
#> Scaled residuals:
#> Min 1Q Median 3Q Max
#> -1.4614 -0.8268 -0.1679 0.7333 2.8152
#>
#> Random effects:
#> Groups Name Variance Std.Dev.
#> Chick (Intercept) 0.02743 0.1656
#> Residual 0.26793 0.5176
#> Number of obs: 578, groups: Chick, 50
#>
#> Fixed effects:
#> Estimate Std. Error t value Pr(>|z|)
#> (Intercept) 4.56520 0.06687 68.269 < 2e-16 ***
#> Diet2 0.21009 0.11283 1.862 0.06260 .
#> Diet3 0.37956 0.11286 3.363 0.00077 ***
#> Diet4 0.33147 0.11299 2.934 0.00335 **
#> ---
#> Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#>
#> Correlation of Fixed Effects:
#> (Intr) Diet2 Diet3
#> Diet2 -0.591
#> Diet3 -0.592 0.350
#> Diet4 -0.591 0.349 0.350
plot(independent.glm)
Broad Question: Independence matters, by why does it matter? What is happening when observations are dependent?
Narrow Question: Okay, independence matters (not sure why), but I'll account for it in my model using a multi-level structure. Why are the fixed effect coefficients changing? My understanding is that I've just fit a model at varying intercepts and not sure how that ties into fixed effects?