I want to do a polynomial regression in R with one dependent variable y
and two independent variables x1
and x2
. In my mind the model shou
you can use polym
y ~ polym(x1, x2, degree=2, raw=TRUE) # is equivalent to
y ~ x1 + x2 + I(x1^2) + I(x2^2) + x1:x2
But be careful with the order of the coefficients they are not the same as the second formula.
If you use degree=3 then it will add interactions of higher order like this I(x1^2):x2 +I(x2^2):x1, thus you have to adapt your formula.
NB : polym is a wrapper for poly, so you can use this latter with the same call.