glmer with non-standard linksbinomial(link="identity")Simulate data:
set.seed(101)
x <- runif(500, min = 0.4, max = 0.6)
nf <- 10
f <- factor(sample(LETTERS[1:nf], size = 500, replace = TRUE))
u <- rnorm(nf, sd = 0.05)
eta <- 0.1 + x + u[f]
y <- rbinom(500, size = 1, prob = eta) ## identity link
d <- data.frame(x, f, eta, y)
summary(d)
## x f eta y
## Min. :0.401 A : 58 Min. :0.439 Min. :0.000
## 1st Qu.:0.449 B : 58 1st Qu.:0.537 1st Qu.:0.000
## Median :0.500 D : 57 Median :0.586 Median :1.000
## Mean :0.501 G : 54 Mean :0.587 Mean :0.574
## 3rd Qu.:0.551 E : 52 3rd Qu.:0.638 3rd Qu.:1.000
## Max. :0.600 I : 49 Max. :0.725 Max. :1.000
## (Other):172
Using the identity link fails in the stable version of lme4 (I have this version labelled as lme4.0 because I am working with the stable & development branches simultaneously, but these results should be identical with the stable version of lme4 on CRAN (0.999999-0))
library("lme4.0") ## STABLE version of lme4
packageVersion("lme4.0")
## [1] '0.999999.1'
m0 <- glmer(y ~ x + (1 | f), family = binomial, data = d)
fixef(m0)
## (Intercept) x
## -1.989 4.573
m1 <- glmer(y ~ x + (1 | f), family = binomial(link = "identity"), data = d)
## Error: mu[i] must be in the range (0,1): mu = -0.309168, i = 0
## (would like to use update() but it doesn't work ...)
detach("package:lme4.0", unload = TRUE)
library("lme4") ## STABLE version of lme4
packageVersion("lme4")
## [1] '0.99999911.1'
m0 <- glmer(y ~ x + (1 | f), family = binomial, data = d)
m1 <- update(m0, family = binomial(link = "identity"))
fixef(m0)
## (Intercept) x
## -1.989 4.573
fixef(m1)
## (Intercept) x
## 0.01386 1.11847