[R] difficulties getting coef() to work in some lmer() calls

Douglas Bates bates at stat.wisc.edu
Wed Dec 12 20:57:04 CET 2007


On Dec 3, 2007 1:45 PM, David Park <dkp at gwu.edu> wrote:
> I'm working with Andrew Gelman on a book project and we're having some
> difficulties getting coef() to work in some lmer() calls.
>
> Some versions of the model work and some do not.  For example, this works
> (in that we can run the model and do coef() from the output):
>
> R2 <- lmer(y2 ~ factor(z.inc) + z.st.inc.full + z.st.rel.full + (1 + factor(
> z.inc) | st.num), family=binomial(link="logit"))
>
> But this does not (the model runs but coef() doesn't work):
>
> R3 <- lmer(y2 ~ factor(z.inc) + z.st.inc.full + z.st.rel.full + (1 + z.inc |
> st.num ), family=binomial(link="logit"))
>
> We get the following error:
> Error in coef(R3) : unable to align random and fixed effects

Which indicates that the coefficients being estimated for each level
of st.num do not correspond to any of the fixed-effects coefficients,
hence the coef method, in the sense that it is used in nlme and lme4,
cannot be applied.

You will need to change the fixed-effects specification so that it
includes z.inc.  This may mean modifying the contrasts from
factor(z.inc).  I would suggest switching to polynomial contrasts then
replacing the linear term by z.inc

> The data are at
> http://www.stat.columbia.edu/~gelman/temp/lmerexample.txt<http://www.stat.columbia.edu/%7Egelman/temp/lmerexample.txt>
> The file to read the data are at:
> http://www.stat.columbia.edu/~gelman/temp/lmerexample.R<http://www.stat.columbia.edu/%7Egelman/temp/lmerexample.txt>
>
> Any help would be appreciated.
>
> David K. Park
>
> --
> David K. Park
> Visiting Researcher (Fall 2007 / Spring 2008)
> Applied Statistics Center
> Columbia University
> 1016 Social Work Bldg
> (Amsterdam Ave. at 122 St.)
> New York, NY 10027
>
> Assistant Professor
> Department of Political Science
> George Washington University
> Monroe Hall
> 2115 G Street, NW
> Washington, D.C. 20052
> http://home.gwu.edu/~dkp/ <http://home.gwu.edu/%7Edkp/>
>
> Direct: (202) 994-2331
> Dept: (202) 994-6290
> Fax: (202) 994-7743
>
> "The great tragedy of Science - the slaying of a beautiful hypothesis
> by an ugly fact."
> -- Thomas H. Huxley
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



More information about the R-help mailing list