简体   繁体   中英

R Multivariate polynomials parameters (polym function)

I am looking for the best fit for some data containing three variables: x, y, m, by using R.

For that I use the function "polym" like:

fit <- lm(y~polym(x, m, degree = 2, raw=TRUE))         

I do the same with degree 3, and then I compare with an ANOVA test to see which is better.

However, for a given degree, the polynom created has all possible combinations. For example, if I put degree=2 the polynom created will be:

y = C0 + C1*x + *C2*x^2 + C3*x*m + C4*m^2

when actually, a 2-degree polynom could also be:

y = C0 + C1*x + *C2*x^2 + C3*x*m 

or

y = C0 + C1*x + C2*x*m + C3*m^2

(without the term x^2 or m^2)

I don't think the function "polym" is considering those cases, since I've generated 110 regressions (by changing the values on x and y), and all relations at 2 degree have all possible coefficients (the same for other degrees).

How can "polym" (or a better function if you know...) produce polynomials as the last two I wrote?

Firstly, your second equation is just the first equation with the (original) c3= 0. Unless you have theoretical reasons to omit the mixed term, lm will decide for you whether the coefficient for the mixed term should be zero or not. If you insist, the output of poly by column are the various degrees. Inspection shows that the 4th column of poly is the mixed term you don't want to consider, so fit <- lm(y~polym(x, m, degree = 2, raw=TRUE)[,-4]) would force the regression to consider all terms except the mixed term.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM