[R] Specify model with polynomial interaction terms up to degree n
Rui Barradas
ruipbarradas at sapo.pt
Tue Jul 3 09:51:41 CEST 2012
Hello,
Sorry, but it was you that misread some of the suggestions. I have
written raw=TRUE not raw=raw. Just see
m <- matrix(1:6, ncol=2) # your example
p2 <- poly(m, degree=2, raw=TRUE) # it's raw=TRUE, not raw=raw !!!
deg2 <- attr(p2, 'degree') == 2
p2[, deg2]
p6 <- poly(m, degree=6, raw=TRUE) # now degree 6
deg6 <- attr(p6, 'degree') == 6
p6[, deg6]
Hope this helps,
Rui Barradas
Em 02-07-2012 23:52, YTP escreveu:
> I think you have taken my toy example seriously. Perhaps I wasn't clear, but
> I am in fact not working with a dataset of 3 observations of the numbers 1
> through 6 and trying to estimate anything; that was an example to illustrate
> what I am asking for, namely, turning two variables like this
>
> X1 X2
> 1 4
> 2 5
> 3 6
>
>
> into a dataset like this
>
> 1 4 16
> 4 10 25
> 9 18 36
>
>
> where each column is the interaction between certain polynomial terms of the
> original variables, such that each column has a sum of exponents equal to 2
> (or whatever degree n is desired). My apologies if I wasn't clear, any other
> ideas would be appreciated. It appears the poly command you mentioned is
> only taking powers of a single vector.
>
>
>
> --
> View this message in context: http://r.789695.n4.nabble.com/Specify-model-with-polynomial-interaction-terms-up-to-degree-n-tp4635130p4635217.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
More information about the R-help
mailing list