YTP
2012-Jul-02 13:29 UTC
[R] Specify model with polynomial interaction terms up to degree n
I would like to specify a model with all polynomial interaction terms between two variables, say, up to degree 6. For example, terms like a^6 + (a^5 * b^1) + (a^4 * b^2) + ... and so on. The documentation states The ^ operator indicates crossing to the specified degree. so I would expect a model specified as y ~ (a+b)^6 to produce these terms. However doing this only returns four slope coefficients, for Intercept, a, b, and a:b. Does anyone know how to produce the desired result? Thanks in advance. -- View this message in context: http://r.789695.n4.nabble.com/Specify-model-with-polynomial-interaction-terms-up-to-degree-n-tp4635130.html Sent from the R help mailing list archive at Nabble.com.
David Winsemius
2012-Jul-02 14:51 UTC
[R] Specify model with polynomial interaction terms up to degree n
On Jul 2, 2012, at 9:29 AM, YTP wrote:> I would like to specify a model with all polynomial interaction > terms between > two variables, say, up to degree 6. For example, terms like a^6 + > (a^5 * > b^1) + (a^4 * b^2) + ... and so on. The documentation states > > The ^ operator indicates crossing to the specified degree. > > so I would expect a model specified as y ~ (a+b)^6 to produce these > terms. > However doing this only returns four slope coefficients, for > Intercept, a, > b, and a:b. Does anyone know how to produce the desired result? > Thanks in > advance.You might try: poly(a,6)*poly(b,6) (untested ... and it looks somewhat dangerous to me.) -- David Winsemius, MD West Hartford, CT