Skip to content
Prev 205795 / 398506 Next

how to get perfect fit of lm if response is constant

Thanks for the answer.
The situation is that I don't know anything of y a priori. Of course I then would not do a regression on constant y's, but isn't it a problem of stability of the algorithm, if I get an adj RSquare of 0.6788 for 
a least square fit on this type of data? I think lm should give me a correct result even in case of y is perfectly fittable, because the situation is that I never know if my data could become so. If I have to offset y in this case, then my question becomes how noisy do my y's have to be, so that I can rely on the lm result, if I specify the formula y~x without offset. What if my y's become nearly linear (or nearly perfect fittable with another linear model). I think my question now becomes 'how to rely on lm's result if the formula is specified the way y~x without offset? or 'How do I prevent my result to become numerically incorrect if I may get nearly perfect fittable y's'. 

Greetings

Henrik


-----Urspr?ngliche Nachricht-----
Von: Peter Ehlers [mailto:ehlers at ucalgary.ca] 
Gesendet: Freitag, 8. Januar 2010 19:44
An: Jan-Henrik P?tter
Cc: r-help at r-project.org
Betreff: Re: [R] how to get perfect fit of lm if response is constant

You need to review the assumptions of linear models:
y is assumed to be the realization of a random variable,
not a constant (or, more precisely: there are assumed to
be deviations that are N(0, sigma^2).

If you 'know' that y is a constant, then you have
two options:

1. don't do the regression because it makes no sense;
2. if you want to test lm()'s handling of the data:

fm <- lm(y ~ x, data = df, offset = rep(1, nrow(df)))

(or use: offset = y)

  -Peter Ehlers
Jan-Henrik P?tter wrote: