Skip to content
Prev 2410 / 20628 Next

How to include a quadratic term in an lmer model

Le jeudi 04 juin 2009 ? 17:28 +0200, Linda Mortensen a ?crit :
So, your "x" is coded as a factor ? If so, x^2 isn't even defined.

To speak of a "curvature" *supposes* an a priori ordering of your "x"
variable. Two possibilities :

- code it as an *ordered* factor,
- code it as a continuous variable.

The second possibility entails more assumptions about x than the first
(additivity, fixed distances between levels, etc ...).

You might want to use poly(x,2) rather than x+I(x^2) : poly(x,order)
will use orthogonal polynomials, ensuring independence of the
coefficients of the linear and quadratic term estimators. However, the
coefficients have no easy interpretation, and getting back to the
original value might no be *that* easy. Therefore, you may use poly(x,2)
for testing purposes, and x+I(x^2) to get the numerical values :-). I'm
sure a better solution can be found by looking examples and R-help for
poly().