# Re: [R] Comparison of linear models

From: Rolf Turner <rolf_at_erdos.math.unb.ca>
Date: Fri 28 Jul 2006 - 22:10:21 EST

> I am a master student. I am currently doing an internship. I would
> like to get some advices about the following issue: I have 2 data
> sets, both containing the same variables, but the data were measured
> using two different procedures. I want to know if the two procedures
> are equivalent. Up to know, I have built one linear model for each
> dataset. The two models have the same form. I would like to compare
> these two models: are they identical? Are they different? By how
> much?
>
> Please, could you tell me which R procedure I should use? I have been
> searching the list archive, but without success...

```	This is not a question of ``which R procedure'' but rather a
question of understanding a bit about statistics and linear
models.  You say you are a ``master's student''; I hope you
are not a master's student in *statistics*, given that you
lack this (very) basic knowledge!  If you are a student in
some other discipline, I guess you may be forgiven.

The ``R procedure'' that you need to use is just lm()!

Briefly, what you need to do is combine your two data
sets into a *single* data set (using rbind should work),
add in a grouping variable (a factor with two levels,
one for each measure procedure) e.g.

my.data\$gp <- factor(rep(c(1,2),c(n1,n2)))

where n1 and n2 are the sample sizes for procedure 1 and
procedure 2 respectively.

Then fit linear models with formulae involving the
grouping factor (``gp'') as well as the other predictors,
and test for the ``significance'' of the terms in

fit <- lm(y~.*gp,data=my.data)
anova(fit)

where ``y'' is (of course) your reponse.

You ought to study up on the underlying ideas of inference
for linear models, and the nature of ``factors''.  John Fox's
book ``Applied Regression Analysis, Linear Models, and
Related Methods'' might be a reasonable place to start.

Bon chance.

cheers,

Rolf Turner
rolf@math.unb.ca

______________________________________________
```
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Fri Jul 28 22:21:58 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Sat 29 Jul 2006 - 08:17:19 EST.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.