In S-Plus, I can obtain polynomial contrasts for an ordered factor with contr.poly(). The function also exists in R, however is limited to factors where the levels are equally spaced. In S-Plus, one can obtain the contrasts for a set of numeric values representing unequally spaced ordered factors. Has anyone implemented this in R? I see that the S-Plus function calls another function (poly.raw()) that calls a Fortran routine. Thanks for your assistance. Cheers, George =================================================================George W. Gilchrist Email #1: gwgilc at wm.edu Department of Biology, Box 8795 Email #2: kitesci at cox.net College of William & Mary Phone: (757) 221-7751 Williamsburg, VA 23187-8795 Fax: (757) 221-6483
On 16 Jan 2003 at 17:19, George W. Gilchrist wrote:> In S-Plus, I can obtain polynomial contrasts for an ordered factor with > contr.poly(). The function also exists in R, however is limited to factors > where the levels are equally spaced. In S-Plus, one can obtain the contrasts > for a set of numeric values representing unequally spaced ordered factors. > Has anyone implemented this in R? I see that the S-Plus function calls > another function (poly.raw()) that calls a Fortran routine. Thanks for your > assistance. >This can be done "by hand" easily in R. From some notes of mine: dummy <- poly(c(1,2,3,5), 3) dimnames(dummy) <- list(c(1,2,3,5), c(".L", ".Q", ".C")) # orthogonal polinomial over the set {1,2,3,5} muscles$Ltreat <- C(muscles$Ltreat, dummy, 3) dummy <- poly(c(1,3,6), 2) dimnames(dummy) <- list(c(1,3,6), c(".L", ".Q")) muscles$Ntreat <- C(muscles$Ntreat, dummy, 2) Kjetil Halvorsen> Cheers, George > > =================================================================> George W. Gilchrist Email #1: gwgilc at wm.edu > Department of Biology, Box 8795 Email #2: kitesci at cox.net > College of William & Mary Phone: (757) 221-7751 > Williamsburg, VA 23187-8795 Fax: (757) 221-6483 > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > http://www.stat.math.ethz.ch/mailman/listinfo/r-help
You are wrong about S-PLUS! contr.poly only takes as argument the number of levels required (and uses pre-computed sets for up to 12 levels). You get orthogonal polynomials for equally-space values from contr.poly in both systems, as documented. I don't think you are describing contrasts for an ordered factor, but orthogonal polynomials in a numeric variable. The latter are computed by the function poly() in both R and S-PLUS. You could set them up to give a contrasts matrix if you want, but not a contrasts function (as that is only passed the number of levels, AFAIR). On Thu, 16 Jan 2003, George W. Gilchrist wrote:> In S-Plus, I can obtain polynomial contrasts for an ordered factor with > contr.poly(). The function also exists in R, however is limited to factors > where the levels are equally spaced. In S-Plus, one can obtain the contrasts > for a set of numeric values representing unequally spaced ordered factors. > Has anyone implemented this in R? I see that the S-Plus function calls > another function (poly.raw()) that calls a Fortran routine. Thanks for your > assistance.-- 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