I have continuous variables x, y, z. The plot of the data looks like this: y | z=1(o), 2(@), 3(#), 4(*) | |* * * | | |# # # # | | |@ @ @ @ | | o | o | o | o |o ------------------------ x The correct model appears to be: if z==1, y~x+z; else y~z (y~z + z:x isn't it) How can I express this model in lm()? If I can't express it properly in lm(), what is the best way to fit the model? Thanks for any help. Bill Simpson
Thanks very much John & Peter for your help. Bill
Dear Bill, I believe that lm(y ~ z + I((z == 1)*x)) will give you what you want. I hope that this helps, John At 08:40 AM 11/18/2003 -0500, you wrote:>I have continuous variables x, y, z. The plot of the data looks like this: > >y >| z=1(o), 2(@), 3(#), 4(*) >| >|* * * >| >| >|# # # # >| >| >|@ @ @ @ >| >| o >| o >| o >| o >|o >------------------------ x >The correct model appears to be: if z==1, y~x+z; else y~z >(y~z + z:x isn't it) > >How can I express this model in lm()? If I can't express it properly in >lm(), what is the best way to fit the model?____________________________ John Fox Department of Sociology McMaster University email: jfox at mcmaster.ca web: http://www.socsci.mcmaster.ca/jfox
Bill Simpson <William.Simpson at drdc-rddc.gc.ca> writes:> I have continuous variables x, y, z. The plot of the data looks like this: > > y > | z=1(o), 2(@), 3(#), 4(*) > | > |* * * > | > | > |# # # # > | > | > |@ @ @ @ > | > | o > | o > | o > | o > |o > ------------------------ x > The correct model appears to be: if z==1, y~x+z; else y~z > (y~z + z:x isn't it)Not if z really is continuous...> How can I express this model in lm()? If I can't express it properly in > lm(), what is the best way to fit the model?I'd try something like x2 <- ifelse(z==1, x, 0) z2 <- factor(z) y ~ x2+z2 -- O__ ---- Peter Dalgaard Blegdamsvej 3 c/ /'_ --- Dept. of Biostatistics 2200 Cph. N (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907