^ character in R lm ()

Running regression in R:

fit = lm(y ~ x + log(x) + z + log(z) + (z-1)^2, data=data)

      

I get ridiculously high R ^ 2 values. I replaced (z-1) ^ 2 with a variable I named q, which is defined as (z-1) ^ 2, and I got a much smaller R ^ 2 value.

It's clear to me now that ^ does not act as an exponent in lm (), but what does it do? I looked here http://faculty.chicagobooth.edu/richard.hahn/teaching/FormulaNotation.pdf but I didn't get it.

+3


source to share


1 answer


the term (z-1)^2

coincides with the interaction (z-1)*(z-1)

, not the square power (z-1). If you want the formula to be taken literally, you must use I()

. You can see ?I

and ?formula

for future reference,



+3


source







All Articles