[R] polynomial contrasts in R

kjetil brinchmann halvorsen kjetil at entelnet.bo
Fri Jan 17 00:58:46 CET 2003


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




More information about the R-help mailing list