[R] Dummies multiplied with other variable

Andreas Goesele Goesele at hfph.mwn.de
Wed Nov 29 21:46:04 CET 2006


Hi,

I would like to estimate something like y = a + b*d2*y + c*d3*y where
the dummies are created from some vector d with three (actually many
more) levels using factor(). But either there is included the variable
y or d1*y. How could I get rid of these?

Example:

x = c(1,2,3,4,5,6,7,8)
y = c(3,6,2,8,7,6,2,4)
d = c(1,1,1,2,3,2,3,3)
fd = factor(d)

lm(x ~ fd*y)
gives:

Coefficients:
(Intercept)         fd2         fd3           y       fd2:y       fd3:y  
     2.4231      9.5769      6.1822     -0.1154     -0.8846     -0.3320

lm(x ~ fd*y - y)
gives:

Coefficients:
(Intercept)         fd2         fd3       fd1:y       fd2:y       fd3:y  
     2.4231      9.5769      6.1822     -0.1154     -1.0000     -0.4474

What I would like to get is:

Coefficients:
(Intercept)         fd2         fd3       fd2:y       fd3:y

Is there an easy way to achieve this?

Maybe it's obvious how to do it, but I'm new to R did quite some
searching without finding the solution.

Thanks a lot in advance!

Andreas Goesele

-- 
Andreas Gösele



More information about the R-help mailing list