[R] Testing equality of regression model on multiple groups

Clara Yuan CYuan at transitchicago.com
Thu Dec 17 23:14:43 CET 2009


Hello,

I'm trying to test for the joint equality of coefficients of the same model across different subsets of the data (ie, is it necessary to estimate the same model on these different populations, or can I just estimate the model once on the whole dataset?).

My plan is to use the F-test on the reduced model and the full model. By full model, I mean a specification that mimics my regressions on separate subsets of data, but I have found that the full model's coefficient estimates don't correspond to my original model's estimates. I was under the impression that they would be identical.

Original model:
> lm.separate = by(data.ex, data.ex$t, function(x) lm(y ~ x1 * x2, data = x))

Full model:
> lm.together = lm(y ~ t * x1 * x2, data = data.ex)

The data are grouped by t.

When I examine the coefficients, I find that they are roughly in the same ballpark, but not nearly identical:
> sapply(lm.separate, coef)
                      1            2             3             4
(Intercept) 2.691272263 1.7153565472  1.8797914048  1.9282332240
x1          0.107520721 0.0472488208  0.0440171489  0.0198376096
x2          0.054694784 0.0396246366  0.0603665574  0.0300886164
x1:x2       0.002180749 0.0003653858 -0.0001488267 -0.0007409421

> coef(lm.together)
  (Intercept)           t.L           t.Q           t.C            x1
 2.0536633597 -0.4750933962  0.5121787674 -0.2809269719  0.0546560750
           x2        t.L:x1        t.Q:x1        t.C:x1        t.L:x2
 0.0461936485 -0.0595422428  0.0180461803 -0.0174386682 -0.0118682844
       t.Q:x2        t.C:x2         x1:x2     t.L:x1:x2     t.Q:x1:x2
-0.0076038969 -0.0194162097  0.0004140914 -0.0020749112  0.0006116237
    t.C:x1:x2
-0.0003083657

(Also, why are the coefficients renamed to t.L, t.Q, etc instead of t.1, t.2?)

What am I missing?

Thanks for the help,
Clara




More information about the R-help mailing list