[R] constructing appropriate non-intercept formula
Ben Bolker
bolker at ufl.edu
Thu Oct 2 04:57:03 CEST 2008
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Trying to work out a model formula that will do what I want ... suppose
I want to model
y = b_i x + epsilon
(i.e. a linear model with zero intercept and with slopes differing
by groups), and I want to parameterize the slopes
in the "usual" way of having a baseline slope value
for the first level of the factor b and (n-1) values
representing the differences of every other level from
the first.
x = rep(1:10,2)
f = factor(rep(1:2,each=10))
b = c(2,3)
y = rnorm(20,b[f]*x,1)
dat = data.frame(f,x,y)
lm(y~f:x-1,data=dat)
gives values for the slope of each group independently
lm(y~f*x-f-1,data=dat)
gives a coefficient for x which is actually the slope
of group 2, a coefficient for f1:x which is (slope 1 - slope 2),
and NA for f2:x
For a subset of data
f x
1 1
1 2
2 1
2 2
I would want the model matrix
x f2:x
1 0
2 0
1 1
2 2
Is there any elegant way to do this?
(I could get the estimates I wanted in this case by
switching the order of the levels or the contrasts,
but I would still get an overspecified model/NA coefficient.)
Or am I missing a reason that I just shouldn't do it?
Ben Bolker
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iD8DBQFI5Dh/c5UpGjwzenMRAqGGAJ9Da6s9m+w/ArX4tvMsmvSedw1QeACeM48E
tLcHlnqDHRDHUCXFDW4ScRg=
=47J/
-----END PGP SIGNATURE-----
More information about the R-help
mailing list