Sunday, 15 April 2012

interaction with dummy variables in lm() in R -



interaction with dummy variables in lm() in R -

ref: http://www.r-bloggers.com/r-for-ecologists-putting-together-a-piecewise-regression/

in paper, confused argument:

y ~ x*(x < breaks[i]) + x*(x>=breaks[i])

in lm().

i know * in lm means interactions , main effects mean predictors x x (x < breaks[i]) (x < breaks[i]) , interactions?

this method of doing "segmented" regression. creating 2 different models, 1 section x < breaks[i] , opposite true. webpage seems pretty nice job of illustrating it's unclear missing. model formula might more clear if written as:

y ~ x*i(x < breaks[i]) + x*i(x>=breaks[i])

it means there 2 predictors: first 1 beingness x , sec 1 beingness logical vector 1 in part less breaks[i] , 0 in other region. in fact not need 2 terms in model if used:

y ~ x*i(x < breaks[i])

i thought predictions same, different, perhaps because 2 term model implicitly allowed independent intercepts.

r

No comments:

Post a Comment