# [R] Summary Orthogonal Polynomials

Douglas Bates bates at stat.wisc.edu
Wed Oct 9 15:31:47 CEST 2002

```Bill.Venables at CMIS.CSIRO.AU writes:

> 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.

I did try fractions() on the example that Paul gave, poly(1:4, 3), and
the result is hard to interpret.

> fractions(poly(1:4, 3))
1                2                3
[1,] -5494877/8191279              1/2    -98209/439204
[2,]    -98209/439204             -1/2    208010/310083
[3,]    208010/930249             -1/2 -5494877/8191279
[4,]    208010/310083              1/2    208010/930249
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._

```