[R-sig-ME] pedigreemm with one observation per individual

Bolker,Benjamin Michael bolker at ufl.edu
Mon Feb 22 23:05:35 CET 2010


  It would be nice if this could go into the main lme4 (or lme4a?) branch -- even nicer if it could be passed through from [g]lmer -- as mentioned before, there are legitimate cases for this (modeling overdispersion at the individual level ...) ... 
________________________________________
From: r-sig-mixed-models-bounces at r-project.org [r-sig-mixed-models-bounces at r-project.org] On Behalf Of Aaron Rendahl [arendahl at stat.umn.edu]
Sent: Monday, February 22, 2010 12:29 PM
To: David Duffy
Cc: r-sig-mixed-models at r-project.org
Subject: Re: [R-sig-ME] pedigreemm with one observation per individual

When trying to fit a mixed model using pedigreemm (which uses lme4)
with only one observation per individual, lme4 gives an error that the
"Number of levels of a grouping factor for the random effects must be
less than the number of observations"; which is not necessarily true
when modeling relationships between the individuals.

David Duffy suggested the kinship package, but in an off-list email,
commented on the need to get pedigreemm working, as kinship is much
slower because it uses nlme instead of lme4.

Here is a somewhat crude fix; it adds an additional parameter
(checklevels) to the lmer_finalize and glmer_finalize functions in
lme4 that turns off the unwanted sanity check.  The default is
checklevels=TRUE, which maintains the previous behavior.  The
pedigreemm function is then changed to set checklevels=FALSE before
calling the appropriate finalizing function.  I'm running these
changes locally and they seem to work fine.

Comments or suggestions are welcome, as is consideration of this
change or some variant on it for inclusion in the pedigreemm and lme4
packages.


----- in lmer.R in the lme4 package -----
lmer_finalize <- function(fr, FL, start, REML, verbose, checklevels=TRUE)
{
...
### This checks that the number of levels in a grouping factor < n
### Only need to check the first factor because it is the one with
### the most levels.
    if (checklevels & !(length(levels(dm$flist[[1]])) < length(Y)))
...

glmer_finalize <- function(fr, FL, glmFit, start, nAGQ, verbose,
checklevels=TRUE)
{
...
### This checks that the number of levels in a grouping factor < n
### Only need to check the first factor because it is the one with
### the most levels.
    if (checklevels & !(length(levels(dm$flist[[1]])) < ncol(dm$Zt)))
...

----- in pedigree.R in the pedigreemm package -----
pedigreemm <-
    function(formula, data, family = NULL, REML = TRUE, pedigree = list(),
...
    lmf$checklevels <- FALSE;
    ans <- do.call(if (!is.null(lmf$glmFit)) lme4:::glmer_finalize
else lme4:::lmer_finalize, lmf)
...



--
Aaron Rendahl, Ph.D.
Statistical Consulting Manager
School of Statistics, University of Minnesota

NEW OFFICE (as of June 2009):
48C McNeal Hall, St. Paul Campus
612-625-1062
www.stat.umn.edu/consulting

_______________________________________________
R-sig-mixed-models at r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-sig-mixed-models




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