[R] [EXTERNAL] Re: Question About lm()
Bromaghin, Jeffrey F
jbrom@gh|n @end|ng |rom u@g@@gov
Thu Feb 10 22:50:04 CET 2022
Rolf,
Yes, that is what is happening. I thought that lm() recognized the presence of a categorical variable as a replacement, if you will, for the intercept, but either my memory is faulty or the behavior of the function changed somewhere along the way.
Thank you,
Jeff
-----Original Message-----
From: Rolf Turner <r.turner using auckland.ac.nz>
Sent: Thursday, February 10, 2022 12:09 PM
To: David Winsemius <dwinsemius using comcast.net>; r-help using r-project.org
Cc: Bromaghin, Jeffrey F <jbromaghin using usgs.gov>
Subject: [EXTERNAL] Re: [R] Question About lm()
This email has been received from outside of DOI - Use caution before clicking on links, opening attachments, or responding.
On Wed, 9 Feb 2022 23:16:13 -0800
David Winsemius <dwinsemius using comcast.net> wrote:
> The models are NOT equivalent. Why would you’ll think they were?
'Scuse me, David, but they *are* "equivalent". They are simply different parametrisations of the same model. *However* the different parametrisations imply, according to the conventions of lm(), different
*null* models.
For yResp ~ xCat + xCont, the null model is yResp ~ 1.
For yResp ~ -1 + xCat + xCont, the null model is yResp ~ 0.
For the first null model, the residual sum of squares is
ssr1 = sum((yResp-mean(yResp))^2).
For the second null model, the residual sum of squares is
ssr2 = sum(yResp^2).
Thus for the first parametrisation one gets
RSquared = 1 - ssr1/ssr
and for the second parametrisation one gets
RSquared = 1 - ssr2/ssr
in both cases "ssr" is the sum of squares of the residuals from the full model (which is of course the same in both cases).
I hope that this clarifies things a bit for the OP.
One further comment: RSquared is a bit of a dubious concept; it is particularly dubious for models with no intercept. Caveat utilitor.
cheers,
Rolf
--
Honorary Research Fellow
Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276
More information about the R-help
mailing list