[R] Comparison of linear models

Rolf Turner rolf at erdos.math.unb.ca
Fri Jul 28 14:10:21 CEST 2006

Fabien Lebugle wrote:

> 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
	the model that contain ``gp''.  You might start with

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

	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.


					Rolf Turner
					rolf at math.unb.ca

More information about the R-help mailing list