Home > Software design >  Error in eval(family$initialize, rho) : y values must be 0 <= y <= 1 when fitting a GLMM
Error in eval(family$initialize, rho) : y values must be 0 <= y <= 1 when fitting a GLMM

Time:11-23

Trying to fit a GLMM that incorporates random effects for isofemale and population, and includes fixed effects and interactions that test:

  1. Do males and females have different heat shock tolerance?
  2. Do flies from different regions have different heat shock tolerance?
  3. Do the base and hardening treatments differ, i.e., is there acclimation?
  4. Does the acclimation effect differ between the two regions?
  5. Does the acclimation effect differ between the two sexes?
  6. Does the effect of sex differ between the two regions?

I also need to use an 'individual level random effect' which is included in my code:

datheat$replicateID = factor(1:nrow(datheat))

mod = glmer(Survival ~ sex   region   treatment   treatment*region   
treatment*sex   sex*region   (1|isofemale)   (1|population)   
(1|replicateID), data = datheat, family =
binomial)
summary(mod)

However, I keep getting this error and I'm not sure how to fix it:

Error in eval(family$initialize, rho) : y values must be 0 <= y <= 1

Here is a sample of my data (datheat):

note abbreviated column names (pop=population, iso = isofemale, S*=Survival, X=X..<something>)

    region      pop treatment   iso sex     rep n   S*  X   proportion
1   Southwest   CAJ hardening   D1  Females 1   10  2   20  0.2
2   Southwest   CAJ hardening   D1  Females 2   10  1   10  0.1
3   Southwest   CAJ hardening   D1  Females 3   10  5   50  0.5
32  Southwest   REG hardening   R4  Females 1   10  3   30  0.3
33  Southwest   REG hardening   R4  Females 2   10  1   10  0.1
34  Southwest   REG hardening   R4  Females 3   10  3   30  0.3
60  Southwest   REG hardening   Southwest2  Females 1   10  5   50  0.5
61  Southwest   REG hardening   Southwest2  Females 2   10  3   30  0.3
62  Southwest   REG hardening   Southwest2  Females 3   10  0   0   0
74  Southwest   PAV hardening   Pa1 Females 1   10  2   20  0.2
75  Southwest   PAV hardening   Pa1 Females 2   10  3   30  0.3
76  Southwest   PAV hardening   Pa1 Females 3   10  4   40  0.4
136 Southwest   CAN hardening   C2  Females 1   10  0   0   0
137 Southwest   CAN hardening   C2  Females 2   10  1   10  0.1
138 Southwest   CAN hardening   C2  Females 3   10  0   0   0

Thanks!

CodePudding user response:

The ?binomial help page (in base R) explains how to specify binomial responses. Assuming that the n column in your data set is the number of individuals in each trial, you either need to specify the number of 'successes' and 'failures' as the columns of a two-column matrix:

glmer(cbind(Survival, n-Survival) ~ ..., ...)

or specify the proportion surviving and give the denominator (total number exposed) as the weights argument:

glmer(proportion ~ ..., ..., weights = n)

While the former is more common in R examples, I prefer the latter (but the answers should be identical).

  • Related