Hi Folks, No doubt a question with a well-known answer, but I'm unfortunately not managing to find it readily ... ! I have a quantitative variable Y and a 4-level ordered factor A (with very unequal numbers at the different levels, by the way). The command lm(Y ~ A) returns (amongst other stuff) an intercept, and coefficients A.L, A.Q and A.C for the Linear, Quadratic and Cubic effects. I'm trying to verify how R computes A.L, A.Q and A.C (equivalently, and preferably, what are the definitions of these that correspond to how R computes them). I haven't touched whatever R's default settings may be for this operation. Can some kind soul enlighten me? With thanks, Ted. -------------------------------------------------------------------- E-Mail: (Ted Harding) <Ted.Harding at nessie.mcc.ac.uk> Fax-to-email: +44 (0)870 167 1972 Date: 22-Nov-03 Time: 08:40:10 ------------------------------ XFMail ------------------------------
On Sat, 22 Nov 2003 Ted.Harding at nessie.mcc.ac.uk wrote:> Hi Folks, > > No doubt a question with a well-known answer, but I'm unfortunately > not managing to find it readily ... ! > > I have a quantitative variable Y and a 4-level ordered factor A > (with very unequal numbers at the different levels, by the way). > > The command > > lm(Y ~ A) > > returns (amongst other stuff) an intercept, and coefficients > A.L, A.Q and A.C for the Linear, Quadratic and Cubic effects. > > I'm trying to verify how R computes A.L, A.Q and A.C (equivalently, > and preferably, what are the definitions of these that correspond > to how R computes them). I haven't touched whatever R's default > settings may be for this operation. > > Can some kind soul enlighten me??contr.poly, as the default contrasts set by options("contrasts") specify that for ordered factors. For more details, including how R uses contrasts, see Chapter 6 of MASS (any edition). -- Brian D. Ripley, ripley at 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
On 22-Nov-03 Ted Harding wrote:> [...] > I have a quantitative variable Y and a 4-level ordered factor A > (with very unequal numbers at the different levels, by the way). > > The command > > lm(Y ~ A) > > returns (amongst other stuff) an intercept, and coefficients > A.L, A.Q and A.C for the Linear, Quadratic and Cubic effects. > > I'm trying to verify how R computes A.L, A.Q and A.C [...]Thanks to Brian Ripley ('"contr.poly" and see MASS Ch 6'), and Berwin Turlach (private response). In particular, Berwin's revelation fm <- lm(Y ~ A) model.matrix(fm) shows me exactly what is going on! Best wishes to all, Ted. -------------------------------------------------------------------- E-Mail: (Ted Harding) <Ted.Harding at nessie.mcc.ac.uk> Fax-to-email: +44 (0)870 167 1972 Date: 22-Nov-03 Time: 10:35:23 ------------------------------ XFMail ------------------------------