Re: [R] Creating unique combinations of factors (was Problem in lme4)

From: Prof Brian Ripley <ripley_at_stats.ox.ac.uk>
Date: Sat 03 Jul 2004 - 02:28:58 EST


On Fri, 2 Jul 2004, Douglas Bates wrote:

> Doran, Harold wrote:
>
>
> > I was able to run the following in nlme successfully, but the same model
> > and code (same dataset) failed to run in lme4 and gave me the error
> > message below. Any thoughts?
> >
> >
> > lme(math~year, data=egsingle, random=~year|schoolid/childid)
> >
> >
> > Error in lme(formula = math ~ year, data = egsingle, random =
> > structure(list( :
> >
> > Unable to invert singular factor of downdated X'X
>
> Is childid unique? If not, you will need to generate a unique id for
> the child for the lme4 version of lme. (This change is required because
> the lme4 package can fit models with crossed or partially crossed
> grouping factors.)
>
> A simple way of creating the necessary factor (thanks to Martin Maechler
> for showing me this) is
>
> egsingle$chld <- (egsingle$schoolid : egsingle$childid)[drop = TRUE]

interaction(egsingle$schoolid, egsingle$childid, drop=TRUE)

is very similar and might be a bit more self-documenting (so I tend to prefer it).

-- 
Brian D. Ripley,                  ripley@stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

______________________________________________
R-help@stat.math.ethz.ch mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Received on Sat Jul 03 02:33:50 2004

This archive was generated by hypermail 2.1.8 : Wed 03 Nov 2004 - 22:54:39 EST