I am trying to determine what factors best predict/explain where deer fawns are being killed by predators based on the kill site's distance to clear-cuts (which I've grouped into three different age categories, as well as an overall distance to all of the clear cuts: distcut_all, distcut_0to5, distcut_6to10, distcut_11to15) as well as a distance to the nearest trail (dist_trail). Finally, I have also included a categorical habitat covariate (hab), which signifies with habitat type is most prevalent in a buffer around each kill site. I have about 300 actual kill sites (coded "1") and about 300 random "false" kill sites (coded "0"), given the name "event_code". I am using a mixed effects model because these kill sites are from 20 different individual animals and therefore are not all independent of each other (i.e., each kill site [or trial] is not a unique occurrence independent of each other kill for a given individual predator).

I ran a for() loop for all of my numeric covariates to calculate a z-score because my "distance to" measurements are on different scales, with some being very small, like 1 meter, and some being 4000 meters away (which I relabeled covariateNorm, see code below).

I have run the following code with "animal" as a random effect. You'll also notice that I have included the logit link:

glmm.1 <- glmer(event_code ~ distcut_allNorm + hab + 
                 distcut_0to5Norm + distcut_6to10Norm + 
                 discut_11to15Norm + dist_trailNorm + (1|animal),
                 family=binomial(link = "logit"), data=fawnkill,)

and I get the following error:

Error: Response is constant

I can find close to nothing online about why this error is occurring. Also, I would like to ask if anyone sees any errors in my thought process for doing this analysis. Your advice is welcome.

  • $\begingroup$ It seems that (among the various combinations of covariates) the error is constant. Confirm the coding of response, and also that if you remove covariates or do other "sanity checks" is able to converge. $\endgroup$
    – AdamO
    Commented Mar 6, 2020 at 16:04
  • $\begingroup$ @AdamO, thanks for your response. Can you be more specific, I am relatively new to R? What do you mean by "confirm the coding of response"? I removed each covariate, one at a time, and tried to run, but had the same error. I will add, that all of the "random" or false kills have no animal associated with them because they are random. Could this be an issue? Could it also be an issue that certain animals only have 1 or 2 kills associated with them? $\endgroup$
    – ahomkes
    Commented Mar 6, 2020 at 16:18
  • $\begingroup$ what is the output of table(fawnkill[, 'event_code'])? $\endgroup$
    – AdamO
    Commented Mar 6, 2020 at 16:30
  • $\begingroup$ 0 1 300 303 This is what I get from that. Except of course its 0 and 1 above 300 and 303. $\endgroup$
    – ahomkes
    Commented Mar 6, 2020 at 16:59

1 Answer 1


This is quite an old question, however it seems important to answer if someone else encounters this error. Adam0 alluded to what is going on here, but to be more specific, your response variable seems to be coded in a way that it always ends up with the same response. I have simulated some data below as an example, which fits a logistic GLMM with a response variable that is only coded as "1".

#### Simulate Binomial GLMM Data ####
y <- rep(1,100)
x <- rnorm(n=100)
fac <- factor(
      each = 10)
df <- data.frame(x,y,fac)

#### Fit Model ####
fit <- glmer(
  y ~ x + (1|fac),
  family = binomial,
  data = df

The error term is immediately present:

Error: Response is constant

If you fit this same data to a regular logistic regression without random effects:

#### Fit to Standard GLM ####
fit <- glm(y ~ x, family=binomial)

You get fairly nonsensical output:

glm(formula = y ~ x, family = binomial)

Deviance Residuals: 
      Min         1Q     Median         3Q        Max  
2.409e-06  2.409e-06  2.409e-06  2.409e-06  2.409e-06  

             Estimate Std. Error z value Pr(>|z|)
(Intercept) 2.657e+01  4.197e+04   0.001    0.999
x           1.945e-08  4.035e+02   0.000    1.000

(Dispersion parameter for binomial family taken to be 1)

    Null deviance: 0.0000e+00  on 99  degrees of freedom
Residual deviance: 5.8016e-10  on 98  degrees of freedom
AIC: 4

Number of Fisher Scoring iterations: 25

As he mentioned, you probably have some misspecification going on, but without more information it is hard to tell exactly why, as your tabled values seem to be binary, though they appear very close to being an exact split in responses (49.8% vs 50.2%).


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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