[R-sig-ME] How to include a quadratic term in an lmer model

Ryan Hope rmh3093 at gmail.com
Thu Jun 4 18:12:26 CEST 2009


I believe you can only do I(x^2) if x is a continuous variable.

On 6/4/09, Linda Mortensen <Linda.Mortensen at psy.ku.dk> wrote:
> Hi list members,
>
> I have recently e-mailed this list asking for some advice on how to use
> mixed-effects models on ordinal responses (see posts entitled "How to use
> mixed-effects models on multinomial data"). This query concerns the same
> data set, but since the topic is a different one, I post the query under a
> different header.
> Following several list members advice, I'm using a linear mixed-effects
> model to analyse the data described in the earlier posts, so I'm still
> working within this model framework. But when trying to decide on the
> best-fitting model, I have run into a problem: In the data set, there is a
> curved relationship between one of the explanatory variables (i.e., the
> serial position of items in a list) and the response variable. A model that
> includes both a linear and a quadratic term for this variable would most
> likely describe this relationship better than a model that includes only a
> linear variable. But when I try to include the quadratic term in the model,
> using the formula "lmer(y ~ x + I(x^2)", I get the following error message:
>
> "Error in `contrasts<-`(`*tmp*`, value = "contr.treatment") :
>   contrasts can be applied only to factors with 2 or more levels"
> And the following warnings:
> "In addition: Warning messages:
> 1: In Ops.factor(cposition, 2) : ^ not meaningful for factors
> 2: In Ops.factor(cposition, 2) : ^ not meaningful for factors"
>
> Judging from the error message, the problem seems to be that I have coded
> the serial position variable using the (default) contrast coding system. The
> serial position variable has five levels (positions 1 through 5), so I don't
> understand why R is complaining about the number of levels. - There are 5
> levels, so the serial position factor has "2 or more levels". Is it the
> coding system that is the problem? Can someone explain to me what I'm doing
> wrong here? Any suggestions are greatly appreciated.
>
> Linda
>
>
> Linda Mortensen
> Post-doctoral research fellow
> Department of Psychology
> University of Copenhagen
> Øster Farimagsgade 2A
> 1353 Copenhagen K
> Denmark
> Tel.: +45 3532 4889
> E-mail: linda.mortensen at psy.ku.dk
>
> _______________________________________________
> 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