You do not need to make your variable names look like the term I(x)
. Just use "x" in the newdata argument.
The reason lm(y~x*I(x^2))
and lm(y~x*x^2)
are different is that "^" and "*" are reserved symbols for formula in R. That's not the case with the log
function. It is also incorrect that interactions can only be constructed with I()
. If you wanted a second degree polynomial in R you should use poly(x, 2)
. If you build with I(log(x)) or with just log(x)
you should get the same model. Both of them will get transformed to the predictor value properly with predict
if you use:
newdata=dataframe( x=seq( min(x), max(x), length=10) )
Using poly
will protect you from incorrect inferences that are so commonly caused by the use of I(x^2)
.