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

Aaron Rendahl arendahl at stat.umn.edu
Mon Feb 22 18:29:22 CET 2010


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




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