1
$\begingroup$

I want to check the effect on mass of crickets, I have a fixed linear effect (AltitudeAge), fixed quadratic effect (AltitudeAge^2), random effects (Nymph IDs, population and the incubators they are reared at).
I have tried both, 4 different glms i.e 4 different models because the crickets were measured on 4 different days of there age. 1 model which included all the 4 different ages.

Glm with all ages included - Finalformula <- glm(Mass ~ Altitude*Age..days. +crick$Altitude*crick$Age..days.^2+ 1/Nymph.ID + 1/Population + Temperature*Altitude + 1/Incubator, data = crick)


Day0 <- glm(Mass ~ Altitude*Age..days. + Altitude*Age..days.^2+ 1/Nymph.ID + 1/Population + Temperature*Altitude + 1/Incubator, data = crick[crick$Age..days.== 0,])

Day13 <-  glm(Mass ~ Altitude*Age..days. + Altitude*Age..days.^2+ 1/Nymph.ID + 1/Population + Temperature*Altitude + 1/Incubator, data = crick[crick$Age..days.== 13,])

Day26 <-  glm(Mass ~ Altitude*Age..days. + Altitude*Age..days.^2+ 1/Nymph.ID + 1/Population + Temperature*Altitude + 1/Incubator, data = crick[crick$Age..days.== 26,])


Day39 <-  glm(Mass ~ Altitude*Age..days. + Altitude*Age..days.^2+ 1/Nymph.ID + 1/Population + Temperature*Altitude + 1/Incubator, data = crick[crick$Age..days.== 39,])





> summary(Finalformula)

Call:
glm(formula = Mass ~ Altitude * Age..days. + crick$Altitude * 
    crick$Age..days.^2 + 1/Nymph.ID + 1/Population + Temperature * 
    Altitude + 1/Incubator, data = crick)

Deviance Residuals: 
    Min       1Q   Median       3Q      Max  
-11.745   -1.795   -0.676    1.724   49.221  

Coefficients: (3 not defined because of singularities)
                                    Estimate Std. Error t value Pr(>|t|)    
(Intercept)                        -11.16236    1.50812  -7.402 1.94e-13 ***
AltitudeLow                         -6.09392    2.16680  -2.812  0.00496 ** 
Age..days.                           0.27606    0.01158  23.841  < 2e-16 ***
crick$AltitudeLow                         NA         NA      NA       NA    
crick$Age..days.                          NA         NA      NA       NA    
Temperature                          0.46645    0.05885   7.925 3.65e-15 ***
AltitudeLow:Age..days.               0.08203    0.01665   4.925 9.08e-07 ***
crick$AltitudeLow:crick$Age..days.        NA         NA      NA       NA    
AltitudeLow:Temperature              0.22874    0.08452   2.706  0.00686 ** 
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

(Dispersion parameter for gaussian family taken to be 22.81318)

    Null deviance: 90517  on 2112  degrees of freedom
Residual deviance: 48067  on 2107  degrees of freedom
  (1771 observations deleted due to missingness)
AIC: 12612

Number of Fisher Scoring iterations: 2

> summary(Day0)

Call:
glm(formula = Mass ~ Altitude * Age..days. + Altitude * Age..days.^2 + 
    1/Nymph.ID + 1/Population + Temperature * Altitude + 1/Incubator, 
    data = crick[crick$Age..days. == 0, ])

Deviance Residuals: 
     Min        1Q    Median        3Q       Max  
-1.15935  -0.09167  -0.00167   0.09208   1.02462  

Coefficients: (2 not defined because of singularities)
                         Estimate Std. Error t value Pr(>|t|)    
(Intercept)              1.217597   0.074453  16.354   <2e-16 ***
AltitudeLow              0.272723   0.108389   2.516   0.0120 *  
Age..days.                     NA         NA      NA       NA    
Temperature              0.003492   0.002909   1.200   0.2303    
AltitudeLow:Age..days.         NA         NA      NA       NA    
AltitudeLow:Temperature -0.009955   0.004231  -2.353   0.0188 *  
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

(Dispersion parameter for gaussian family taken to be 0.0270779)

    Null deviance: 26.429  on 970  degrees of freedom
Residual deviance: 26.184  on 967  degrees of freedom
AIC: -742.8

Number of Fisher Scoring iterations: 2

> summary(Day13)

Call:
glm(formula = Mass ~ Altitude * Age..days. + Altitude * Age..days.^2 + 
    1/Nymph.ID + 1/Population + Temperature * Altitude + 1/Incubator, 
    data = crick[crick$Age..days. == 13, ])

Deviance Residuals: 
    Min       1Q   Median       3Q      Max  
-3.3620  -1.0891  -0.3191   0.7510  11.0952  

Coefficients: (2 not defined because of singularities)
                        Estimate Std. Error t value Pr(>|t|)    
(Intercept)             -8.17653    1.04106  -7.854 1.74e-14 ***
AltitudeLow             -2.07808    1.49382  -1.391    0.165    
Age..days.                    NA         NA      NA       NA    
Temperature              0.44719    0.04031  11.094  < 2e-16 ***
AltitudeLow:Age..days.        NA         NA      NA       NA    
AltitudeLow:Temperature  0.10340    0.05798   1.783    0.075 .  
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

(Dispersion parameter for gaussian family taken to be 3.318842)

    Null deviance: 3123.3  on 634  degrees of freedom
Residual deviance: 2094.2  on 631  degrees of freedom
  (336 observations deleted due to missingness)
AIC: 2569.8

Number of Fisher Scoring iterations: 2

> summary(Day26)

Call:
glm(formula = Mass ~ Altitude * Age..days. + Altitude * Age..days.^2 + 
    1/Nymph.ID + 1/Population + Temperature * Altitude + 1/Incubator, 
    data = crick[crick$Age..days. == 26, ])

Deviance Residuals: 
   Min      1Q  Median      3Q     Max  
-8.675  -2.794  -0.812   1.105  49.715  

Coefficients: (2 not defined because of singularities)
                        Estimate Std. Error t value Pr(>|t|)    
(Intercept)             -24.7101     4.8041  -5.144 4.72e-07 ***
AltitudeLow              -5.7208     6.6253  -0.863    0.389    
Age..days.                    NA         NA      NA       NA    
Temperature               1.2121     0.1822   6.653 1.25e-10 ***
AltitudeLow:Age..days.        NA         NA      NA       NA    
AltitudeLow:Temperature   0.2684     0.2521   1.065    0.288    
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

(Dispersion parameter for gaussian family taken to be 29.75619)

    Null deviance: 13042.4  on 322  degrees of freedom
Residual deviance:  9492.2  on 319  degrees of freedom
  (648 observations deleted due to missingness)
AIC: 2018.6

Number of Fisher Scoring iterations: 2

> summary(Day39)

Call:
glm(formula = Mass ~ Altitude * Age..days. + Altitude * Age..days.^2 + 
    1/Nymph.ID + 1/Population + Temperature * Altitude + 1/Incubator, 
    data = crick[crick$Age..days. == 39, ])

Deviance Residuals: 
    Min       1Q   Median       3Q      Max  
-19.975   -6.254   -2.120    3.653   39.435  

Coefficients: (2 not defined because of singularities)
                        Estimate Std. Error t value Pr(>|t|)    
(Intercept)             -44.1094    14.6523  -3.010  0.00298 ** 
AltitudeLow             -37.6635    20.8613  -1.805  0.07268 .  
Age..days.                    NA         NA      NA       NA    
Temperature               2.1893     0.5447   4.019 8.58e-05 ***
AltitudeLow:Age..days.        NA         NA      NA       NA    
AltitudeLow:Temperature   1.6028     0.7775   2.062  0.04069 *  
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

(Dispersion parameter for gaussian family taken to be 130.16)

    Null deviance: 32669  on 183  degrees of freedom
Residual deviance: 23429  on 180  degrees of freedom
  (787 observations deleted due to missingness)
AIC: 1424

Number of Fisher Scoring iterations: 2
$\endgroup$
3
  • $\begingroup$ This is a statistics question, not a programming one, so it should go on stats.stackexchange. (You may also want to clarify the question... I'm not really sure what you're asking and what you're confused about.) The programming advice I would give is that using the data = crick argument like you do is very good, and when you do that don't use crick$ in your model formula. You should change, e.g., + crick$Altitude to + Altitude $\endgroup$ Jul 18 '19 at 14:17
  • $\begingroup$ Thank you sir. Will do. My confusion is what to make off my results, what would be the best plot for the model, which model would answer my question i.e seeing what is affecting the mass and how it is being affected. Thank you. $\endgroup$ Jul 18 '19 at 14:21
  • $\begingroup$ The above code doesn't appear to correctly specify quadratic terms. You can also see there is no coefficient for any quadratic terms in the model summary. It should be something like I(x^2). See this archived thread for an explanation. $\endgroup$
    – olooney
    Jul 18 '19 at 21:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.