I have a number of fish measurements I want to test, for example Condition, HSI, and GSI. These are to be tested against Parasitism (A factor, 0 being non-parasitized and 1 indicating parasitized). I am hoping to see no effect from parasitism.

I did preliminary T-Tests for four lakes (pooled over three years) comparing Parasitized and Non-Parasitized fish for the three metrics. All but one lake yielded no significant difference in Parasitized and Non Parasitized fish.

Overall I want test this as a model, and since I am seeing differences in one of the lakes, I believe this means I would have to treat Lake as a RANDOM effect, and Parasitism as a FIXED effect. Please correct me if I am wrong.

My question is... how do I test for significance (where I can obtain a P-value) by comparing a linear mixed model and a simple linear model?

Can this be done similarly using likelihood ratios? For example: anova(LMM1, LM1)

All help, suggestions and links are much appreciated...


marked as duplicate by amoeba, Peter Flom regression Mar 9 '18 at 12:38

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • $\begingroup$ What fixed linear model do you have in mind and why do you think you need it? Do you want to find out whether including the random effect for LAKE is warranted? $\endgroup$ – vkehayas Mar 8 '18 at 15:02
  • $\begingroup$ Yes, I want to see if there is significant differences between lakes with respect to parasitism. So ultimately I want to test lake as an effect or interaction I believe for one model, and then test my metrics with parasitism with lakes not having an effect. $\endgroup$ – Justin SlingerVanland Mar 8 '18 at 18:34
  • $\begingroup$ For example: lm1 <- lm(K ~ Parasites) for my linear model and lmer1 <- lmer(K ~ Parasites + (1|Lake)) for my mixed model $\endgroup$ – Justin SlingerVanland Mar 8 '18 at 18:35

You can certainly do it, i.e. you won't get an error:


## Loading required package: Matrix

lme1 = lmer('mpg ~ 1 + hp + (1|vs)', data = mtcars)

## Linear mixed model fit by REML ['lmerMod']
## Formula: mpg ~ 1 + hp + (1 | vs)
##    Data: mtcars
## REML criterion at convergence: 181.4
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -1.4603 -0.6050 -0.2401  0.4277  2.1212 
## Random effects:
##  Groups   Name        Variance Std.Dev.
##  vs       (Intercept)  1.379   1.174   
##  Residual             14.577   3.818   
## Number of obs: 32, groups:  vs, 2
## Fixed effects:
##             Estimate Std. Error t value
## (Intercept) 29.33120    2.03135  14.439
## hp          -0.06254    0.01207  -5.183
## Correlation of Fixed Effects:
##    (Intr)
## hp -0.849

lm2 = lm('mpg ~ 1 + hp', data = mtcars)

## Call:
## lm(formula = "mpg ~ 1 + hp", data = mtcars)
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -5.7121 -2.1122 -0.8854  1.5819  8.2360 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept) 30.09886    1.63392  18.421  < 2e-16 ***
## hp          -0.06823    0.01012  -6.742 1.79e-07 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## Residual standard error: 3.863 on 30 degrees of freedom
## Multiple R-squared:  0.6024, Adjusted R-squared:  0.5892 
## F-statistic: 45.46 on 1 and 30 DF,  p-value: 1.788e-07

anova(lme1, lm2)

## refitting model(s) with ML (instead of REML)

## Data: mtcars
## Models:
## lm2: "mpg ~ 1 + hp"
## lme1: mpg ~ 1 + hp + (1 | vs)
##      Df    AIC    BIC  logLik deviance Chisq Chi Df Pr(>Chisq)
## lm2   3 181.24 185.64 -87.619   175.24                        
## lme1  4 183.24 189.10 -87.619   175.24     0      1          1

The AIC that is returned by anova is also commonly used to compare nested models.

However, I would urge you to reconsider why you want to test the effect of the random effect for LAKE in the first place. If the variable was part of your experimental design (as it appears to be the case to me), then some would argue that you must include it in your model no matter the difference its inclusion to the model produces (see Testing the significance of random effects for more discussion). If what you are after is to examine the effect in specific lakes, then perhaps the BLUPs are what you are after:

ranef(lme1, condVar = TRUE)

If instead, you initial question was if some lakes are more conductive for parasitism, then I would advise you to include the variable LAKE as a fixed factor and include an interaction with your other variables.

[...] since I am seeing differences in one of the lakes, I believe this means I would have to treat Lake as a RANDOM effect...

No, this is not a valid reason of why you want to select a variable as a random effect. This issue has been discussed elsewhere, for example: What is the difference between fixed effect, random effect and mixed effect models? In my opinion, you treat a variable as a random effect if you care about its influence but the specific instantiations are not important. In your case, if it is true that you want to include the effect of LAKE in the model but you wouldn't expect a difference whether the specific lakes in your sample were {Tanganyika, Victoria} or {Caspian, Baikal}, then I would include the variable LAKE as a random factor regardless of if it contributed anything to the model based on any test or metric.

  • 1
    $\begingroup$ +1 but this threads looks a duplicate of stats.stackexchange.com/questions/141746 (which does not have a very good answer btw, so you might want to post one there too). $\endgroup$ – amoeba Mar 9 '18 at 9:31
  • $\begingroup$ @amoeba This even earlier Q&A appears to be very related to the subject as well. For future reference, the leading answer there suggests to bootstrap the likelihood ratio test statistic. $\endgroup$ – vkehayas Mar 12 '18 at 11:10
  • $\begingroup$ That one is a bit different because the models are not nested, no? It's comparing random effect to fixed effect, not random effect to an absence of random effect. $\endgroup$ – amoeba Mar 12 '18 at 11:17
  • $\begingroup$ (But the leading answer is indeed about testing the random effect, so does not really answer that question :-) $\endgroup$ – amoeba Mar 12 '18 at 11:24

Not the answer you're looking for? Browse other questions tagged or ask your own question.