r - Regression with indicator -


i have dataset 1 dependent variable y, , 2 independent x(continuous) , z(indicator 0 or 1). model fit is

y = a*1(z==0) + b*x*1(z==1), 

in other words, if z==0 estimate should intercept, otherwise estimate should intercept plus b*x part.

the thing have come in 2 steps, ie first take mean of y z==0 (this estimate of intercept), , subtract value rest of ys , run simple regression estimate slope.

i (almost) sure work, ideally estimates in one-liner in r using lm or similar. there way achieve this? in advace!

you can define new variable 0 if z 0, , equal x otherwise:

y ~ ifelse(z, x, 0) 

Comments

Popular posts from this blog

ios - UICollectionView Self Sizing Cells with Auto Layout -

node.js - ldapjs - write after end error -

DOM Manipulation in Wordpress (and elsewhere) using php -