I am running a Poisson model using glmer to look at the effect of a treatment on fat scores (scale from 1-5, hence the Poisson) of an animal. There are multiple timepoints in which fat scores were taken, so since there are repeated measures, I have a random effect of Animal ID added to the model.
The model looks something like this:
glmer(Fat ~ Treatment + Sex + Timepoint + Sex:Treatment + Timepoint:Treatment +
(1 | AnimalID))
However, every single time I try to run the model, it gives me a singularity error. Essentially, it says the random effect's variance is 0. Since I have repeated measures, though, I do have to keep it in the model, correct? I tried finding multiple ways to fix the singularity (taking out individuals that have the same exact fat score throughout the experiment, removing scores that appear to be from one time point, etc.), but nothing is fixing it. The model will still run, but it says the variance is 0, which is puzzling to me. Will anything fix this, or should I just keep the model as is with the singular random effect?
Edit for clarity: I have three different timepoints: one before treatment and two after treatment. There are 2 treatment groups with samples from animals in each treatment group taken during all 3 timepoints (all individuals were sampled 3 times). I have the Timepoint:Treatment interaction in there as I hypothesize that the effect of treatment will be different at each timepoint (ie. there should not be an effect during the first timepoint, but there could be if I happened to have put leaner animals in one treatment vs another). This is the output for this model:
> summary(resultsfat)
Generalized linear mixed model fit by maximum likelihood (Laplace
Approximation) [glmerMod]
Family: poisson ( log )
Formula: as.integer(FatScore) ~ Timepoint + Sex + Treatment + Sex:Treatment +
Timepoint:Treatment + (1 | AnimalID)
Data: parentdata
AIC BIC logLik deviance df.resid
421.7 447.6 -201.9 403.7 122
Scaled residuals:
Min 1Q Median 3Q Max
-1.3137 -0.6158 -0.2114 0.4213 2.0945
Random effects:
Groups Name Variance Std.Dev.
AnimalID (Intercept) 1.738e-16 1.318e-08
Number of obs: 131, groups: AnimalID, 41
Fixed effects:
Estimate Std. Error z value Pr(>|z|)
(Intercept) 0.5495 0.1831 3.002 0.00268 **
TimepointBtrt1 0.1642 0.2156 0.761 0.44639
TimepointCtrt2 0.5557 0.1993 2.787 0.00531 **
SexM 0.1287 0.1596 0.807 0.41990
TreatmentS 0.1545 0.2495 0.619 0.53584
SexM:TreatmentS -0.1987 0.2370 -0.838 0.40183
TimepointBtrt1:TreatmentS -0.3985 0.3133 -1.272 0.20334
TimepointCtrt2:TreatmentS -0.3202 0.2849 -1.124 0.26106
Signif. codes: 0 ‘*’ 0.001 ‘’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Correlation of Fixed Effects:
(Intr) TmpnB1 TmpnC2 SexM TrtmnS SxM:TS TB1:TS
TimpntBtrt1 -0.658
TimpntCtrt2 -0.712 0.597
SexM -0.485 0.017 0.019
TreatmentS -0.734 0.483 0.522 0.356
SxM:TrtmntS 0.326 -0.012 -0.013 -0.673 -0.479
TmpntBt1:TS 0.453 -0.688 -0.411 -0.012 -0.613 -0.001
TmpntCt2:TS 0.498 -0.418 -0.700 -0.013 -0.678 0.010 0.536
optimizer (Nelder_Mead) convergence code: 0 (OK)
boundary (singular) fit: see help('isSingular')
```
(1|AnimalID)is probably sub-optimal also. This has been explained quite a few time here by Prof. Harrell; might as well start with this writeup by him: Longitudinal Data: Think Serial Correlation First, Random Effects Second. – dipetkov Oct 11 '23 at 13:48