Dear all, I found a problem with 'lme4'. Basically, once you load the package 'aod' (Analysis of Overdispersed Data), the functions 'lmer' and 'glmer' don't work anymore: library(lme4) (fm1 <- lmer(Reaction ~ Days + (Days|Subject), sleepstudy)) (gm1 <- glmer(cbind(incidence, size - incidence) ~ period + (1 | herd), family = binomial, data = cbpp)) install.packages("aod") library(aod) (fm1 <- lmer(Reaction ~ Days + (Days|Subject), sleepstudy)) (gm1 <- glmer(cbind(incidence, size - incidence) ~ period + (1 | herd), family = binomial, data = cbpp)) Taking into account that this package is used to perform similar analyses, this could be a problem. All the best Antonio Gasparrini Public and Environmental Health Research Unit (PEHRU) London School of Hygiene & Tropical Medicine Keppel Street, London WC1E 7HT, UK Office: 0044 (0)20 79272406 - Mobile: 0044 (0)79 64925523 http://www.lshtm.ac.uk/people/gasparrini.antonio ( http://www.lshtm.ac.uk/pehru/ ) -------------- next part -------------- An embedded message was scrubbed... From: <Antonio.Gasparrini at lshtm.ac.uk> Subject: bug? Date: Wed, 20 Aug 2008 02:49:10 +0100 Size: 1019 URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20080820/8d6656f3/attachment.mht>
Antonio.Gasparrini at lshtm.ac.uk wrote:> Dear all, > > I found a problem with 'lme4'. Basically, once you load the package 'aod' (Analysis of Overdispersed Data), the functions 'lmer' and 'glmer' don't work anymore: > > library(lme4) > (fm1 <- lmer(Reaction ~ Days + (Days|Subject), sleepstudy)) > (gm1 <- glmer(cbind(incidence, size - incidence) ~ period + (1 | herd), > family = binomial, data = cbpp)) > install.packages("aod") > library(aod) > (fm1 <- lmer(Reaction ~ Days + (Days|Subject), sleepstudy)) > (gm1 <- glmer(cbind(incidence, size - incidence) ~ period + (1 | herd), > family = binomial, data = cbpp)) > > Taking into account that this package is used to perform similar analyses, this could be a problem. > > All the best > > Antonio Gasparrini > Public and Environmental Health Research Unit (PEHRU) > London School of Hygiene & Tropical Medicine > Keppel Street, London WC1E 7HT, UK > Office: 0044 (0)20 79272406 - Mobile: 0044 (0)79 64925523 > http://www.lshtm.ac.uk/people/gasparrini.antonio ( http://www.lshtm.ac.uk/pehru/ ) > > > ------------------------------------------------------------------------ > > Subject: > bug? > From: > <Antonio.Gasparrini at lshtm.ac.uk> > Date: > Wed, 20 Aug 2008 02:49:10 +0100 > To: > <r-sig-mixed-models at r-project.org> > > To: > <r-sig-mixed-models at r-project.org> > > > Dear all, > > I found a problem with 'lme4'. Basically, once you load the package 'aod' (Analysis of Overdispersed Data), the functions 'lmer' and 'glmer' don't work anymore: > > library(lme4) > (fm1 <- lmer(Reaction ~ Days + (Days|Subject), sleepstudy)) > (gm1 <- glmer(cbind(incidence, size - incidence) ~ period + (1 | herd), > family = binomial, data = cbpp)) > install.packages("aod") > library(aod) > (fm1 <- lmer(Reaction ~ Days + (Days|Subject), sleepstudy)) > (gm1 <- glmer(cbind(incidence, size - incidence) ~ period + (1 | herd), > family = binomial, data = cbpp)) > > Taking into account that this package is used to perform similar analyses, this could be a problem. >In which sense is this a bug in lme4?? I'd say that aod has the problem. You can't write an R package so that it is guaranteed not be clobbered by something loaded subsequently. -- O__ ---- Peter Dalgaard ?ster Farimagsgade 5, Entr.B c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907
>>>>> <Antonio.Gasparrini at lshtm.ac.uk> >>>>> on Wed, 20 Aug 2008 03:03:29 +0100 writes:> Dear all, > I found a problem with 'lme4'. Basically, once you load the package 'aod' (Analysis of Overdispersed Data), the functions 'lmer' and 'glmer' don't work anymore: > library(lme4) > (fm1 <- lmer(Reaction ~ Days + (Days|Subject), sleepstudy)) > (gm1 <- glmer(cbind(incidence, size - incidence) ~ period + (1 | herd), > family = binomial, data = cbpp)) > install.packages("aod") > library(aod) > (fm1 <- lmer(Reaction ~ Days + (Days|Subject), sleepstudy)) > (gm1 <- glmer(cbind(incidence, size - incidence) ~ period + (1 | herd), > family = binomial, data = cbpp)) > Taking into account that this package is used to perform > similar analyses, this could be a problem. It is a problem, and it *is* a bug; thank you for reporting it, Antonio. Since lme4 uses a NAMESPACE, it could and probably should make sure to protect itself from incompatible function redefinitions such as the one the 'aod' package "provides" : Arguably, the bug is really in package 'aod' rather than 'lme4': 'aod' redefines the AIC() method for 'logLik' objects in a not quite backward-compatible way: The standard method (S3 alas, in package 'stats') is > stats:::AIC.logLik function (object, ..., k = 2) -2 * c(object) + k * attr(object, "df") <environment: namespace:stats> The redefinition from package 'aod' is > selectMethod(AIC, "logLik") Method Definition: function (object, ..., k = 2) { npar <- attr(object, "df") nobs <- attr(object, "nobs") c(AIC = -2 * c(object) + k * npar, AICc = -2 * c(object) + k * npar + 2 * npar * (npar + 1)/(nobs - npar - 1)) } <environment: 0x1cd22b80> Signatures: object target "logLik" defined "logLik" which returns a (named) numeric vector of length 2, and the code in lme4 was expecting length 1. As a matter of fact, I even like the idea to extend AIC() to also compute newer versions of AIC; but probably 'aod' should have done so in a different way {maybe with an additional 'kind' argument to the method}. Martin > All the best > Antonio Gasparrini > Public and Environmental Health Research Unit (PEHRU) > London School of Hygiene & Tropical Medicine > Keppel Street, London WC1E 7HT, UK > Office: 0044 (0)20 79272406 - Mobile: 0044 (0)79 64925523 > http://www.lshtm.ac.uk/people/gasparrini.antonio ( http://www.lshtm.ac.uk/pehru/ )