[R-sig-ME] Question regarding the glmer function from the LME4 package

Alexandra Lefebvre @|ex@ndr@@|e|ebvre @end|ng |rom m@th@cnr@@|r
Mon Sep 4 11:08:41 CEST 2023


Dear colleagues, 

I am using the LME4 package, in particular the glmer function, in the framework of an EM algorithm. I would need to retrieve individual log-likelihoods (for each observation) and I am wondering if that output can be obtained from the package. 

As an example, here is a short code (in blue) :

require(lme4)
set.seed(1)

theta.star = 2.5
beta.star = -2

z = rnorm(2000); 
x = rbinom(2000, 50, exp(beta.star + z * theta.star) / (1 + exp(beta.star + z * theta.star)))
dat = data.frame(x = x, id = 1: length(x))
fit = glmer(cbind(x, 50-x) ~ 1 + (1 | id), data = dat, family = "binomial")

theta = fit using theta 		# 2.499677
beta = fit using beta 		# -1.988883

#individual loglik
ind.loglik = rep(NA, length(x))
for (i in 1:length(x)) {
  f = function(u) dbinom(x[i], 50, exp(beta + theta * u) / (1 + exp(beta + theta * u))) * dnorm(u)
  ind.loglik[i] = log(integrate(f, -5, 5)$val)
}

As far as I understood you use Laplace or Gauss-Hermite method. I guess each individual log-likelihood is calculated for fitting the model.  Do you know any way for retrieving the vector of individual log-likelihood directly as an output from your package ? 

Alternatively, I read in your notes that The Laplace approximation correction terms for converting a conditional log-likelihood into a marginal log-likelihood are `gm1 using pp$sqrL(1)` and `gm1 using pp$ldL2()). Is it available at an individual level ? 

Furthermore, I am surprised that the results of the following two line codes are not almost equal and therefore I wonder if my understanding of the output in the above code is correct. 
sum(ind.loglik) 	# -6774.249
logLik(fit)	 		# 'log Lik.' -6807.348 (df=2)


King regards, 
Alexandra Lefebvre 

—————————————
Post-doctoral researcher at CIRB (Collège de France) and LJLL (Sorbonne Université, Paris, France)
CIRB - Collège de France, 11, place Marcelin-Berthelot, 75231 Paris Cedex 05.
Bat.B niveau 1 - Pièce 104.


	[[alternative HTML version deleted]]



More information about the R-sig-mixed-models mailing list