In R how to insert in a model a variable that is a function of a binary variable? -
i know how insert variable function of binary variable. sorry if question not sound clear, pretty new @ r. here example of trying do: using multiple linear regression, model consists of evaluating y predictors x1, x2, x3, x4 , x5 x1, x2, x3 normal (continuous?) variables , x4, x5 binary variables (take values 0 or 1) far model in r looks model<-lm(y~x1+x2+x3+x4+x5) change x1 variable dependant on rather x4 takes value 0 or 1 (x1 function of x4) , model y change. have absolutely no clue how this, if appreciated.
the "*" operator used build interactions in formulas. there's interaction
function it's sensibly used when both contribution variables categorical:
model<-lm( y ~ x1*x4 + x2+x3+x5)
that produce interaction term can interpreted change in slope x1 when x4 == 1. there terms slope of x1 (when x4==0) , x4. x4 term interpreted "level-shift". it's better use predict
function rather trying spend time decoding interactions. if x4 not factor variable might need:
model<-lm( y ~ x1*factor(x4) + x2+x3+x5)
Comments
Post a Comment