[R] lm help: using lm when one point is known (not y intercept)

Martin Maechler maechler at stat.math.ethz.ch
Mon Nov 29 10:36:22 CET 2004

```>>>>> "JohnF" == John Fox <jfox at mcmaster.ca>
>>>>>     on Sat, 27 Nov 2004 23:49:08 -0500 writes:

JohnF> Dear Seth,

JohnF> You don't say which variable is the explanatory
JohnF> variable and which is the response, but assuming that
JohnF> prob is to be regressed on effect, you can fit
JohnF> lm(prob - 50 ~ I(effect + 37.25) - 1). That is you
JohnF> can shift the point through which the regression is
JohnF> to go to the origin and then force the regression
JohnF> through the origin.

JohnF> I hope this helps,
yes, nice!

Even a bit more useful {though slightly uglier} is to use offset():

mfit <- lm(prob ~ offset(50+ 0*effect) + I(effect + 37.25) - 1)

such that e.g. predict(mfit, ...) will still predict 'prob'

Note however that for both solutions, the regression abline()
will look wrong {and I hoped it would also be ok when using offset()},
plot(prob ~ effect)  ; abline(mfit)

Martin

JohnF> John

JohnF> --------------------------------
JohnF> John Fox
JohnF> Department of Sociology
JohnF> McMaster University
JohnF> Hamilton, Ontario
JohnF> 905-525-9140x23604
JohnF> http://socserv.mcmaster.ca/jfox
JohnF> --------------------------------

>> -----Original Message-----
>> To: r-help at stat.math.ethz.ch
>> Subject: [R] lm help: using lm when one point is known (not y intercept)
>>
>> Hello-
>>
>> My question is a short one.  How can I specify a single point
>> which through the fitted linear model has to go through?  To
>> illustrate my problem, the fit to following data must go
>> through the point (-37.25(effect), 50(prob)).  Note: you can
>> ignore the label column.
>>
>> Effect      Prob Label
>>
>> 1 -1143.75  7.142857     L
>> 2  -572.75 21.428571     D
>> 3  -223.75 35.714286    GL
>> 4   123.25 50.000000    DG
>> 5   359.75 64.285714     G
>> 6   374.75 78.571429   DGL
>> 7   821.75 92.857143    DL
>>