[R] Summary Orthogonal Polynomials
Bill.Venables@cmis.csiro.au
Bill.Venables at cmis.csiro.au
Wed Oct 9 06:38:31 CEST 2002
I agree that it doesn't matter a damn what coding you use, but sometimes it
is useful to look at an integer version of the contrast matrix just to see
what's going on. This is useful for teaching. Here is the way I have done
it in the past using a function from the MASS library. Not automatic, but
this is not the kind of thing you need to do every day... I have trimmed
the output a bit to make it more readable, too.
> library(MASS)
> X <- poly(1:8, 5)
> dim(X)
[1] 8 5
> fractions(X/rep(X[1, ], each=nrow(X))) # gets rid of surds.
1 2 3 4 5
[1,] 1 1 1 1 1
[2,] 5/7 1/7 -5/7 -13/7 -23/7
[3,] 3/7 -3/7 -1 -3/7 17/7
[4,] 1/7 -5/7 -3/7 9/7 15/7
[5,] -1/7 -5/7 3/7 9/7 -15/7
[6,] -3/7 -3/7 1 -3/7 -17/7
[7,] -5/7 1/7 5/7 -13/7 23/7
[8,] -1 1 -1 1 -1
> fractions(X/rep(X[1, ], each = nrow(X)))*7
1 2 3 4 5
[1,] 7 7 7 7 7
[2,] 5 1 -5 -13 -23
[3,] 3 -3 -7 -3 17
[4,] 1 -5 -3 9 15
[5,] -1 -5 3 9 -15
[6,] -3 -3 7 -3 -17
[7,] -5 1 5 -13 23
[8,] -7 7 -7 7 -7
In fact I find fractions() useful for a lot of things, somewhat to my
surprise.
Bill Venables.
-----Original Message-----
From: Bliese, Paul D MAJ WRAIR-Wash DC
[mailto:Paul.Bliese at NA.AMEDD.ARMY.MIL]
Sent: Wednesday, October 09, 2002 10:57 AM
To: 'r-help at stat.math.ethz.ch'
Subject: [R] Summary Orthogonal Polynomials
As usual, the R newsgroup set me straight (thanks to Douglas Bates, Robert
Balshaw and Albyn Jones).
There is really no difference between using orthogonal polynomials of the
form:
Linear -3 -1 1 3
Quadratic 1 -1 -1 1
Cubic -1 3 -3 1
Versus
> poly(c(1:4),3)
1 2 3
[1,] -0.6708204 0.5 -0.2236068
[2,] -0.2236068 -0.5 0.6708204
[3,] 0.2236068 -0.5 -0.6708204
[4,] 0.6708204 0.5 0.2236068
My observation that different coding schemes yielded different results was
based upon a colleague's analysis of some data (though the jumping to the
wrong conclusion was my own doing). The newsgroup's responses motivated me
to run my own comparisons in R, and of course the coding scheme doesn't make
a bit of difference.
The reason why the contrasts look different is that R is rescaling the
variables to have unit length. The unit length of the first row, for
instance is 20, so R divides -3, -1, 1, 3 by sqrt(20) and returns:
> c(-3,-1,1,3)/sqrt(20)
[1] -0.6708204 -0.2236068 0.2236068 0.6708204
Paul Bliese
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.
-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._.
_._
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
More information about the R-help
mailing list