# [R] lm fitting with a specified slope

Peter Dalgaard BSA p.dalgaard at biostat.ku.dk
Thu Oct 3 22:53:57 CEST 2002

```"Warnes, Gregory R" <gregory_r_warnes at groton.pfizer.com> writes:

> Assume the model:
>
>   X1 <- rnorm(1000)
>   X2 <- rnorm(1000)
>
>   B1 = 1.75 # known a-priorori
>   B2 = 0.5  # unknown a-priorori
>
>   Y  <- 1.75 * X1 + 0.5 * X2  + rnorm(1000,sd=0.25)
>
> Then wouldn't this do the trick? :
>
>   reg <- lm( (Y - 1.75 * X1) ~ X2 )

I'd prefer

lm(Y ~ X2 + offset(1.75*X1))

This allows you to do things like

>  predict(lm( Y ~ X2 + offset(1.75*X1) ), data.frame(X1=10,X2=10))
[1] 22.41585

whereas

>  predict(lm( (Y - 1.75*X1) ~ X2 ), data.frame(X1=10,X2=10))
[1] 4.915847

--
O__  ---- Peter Dalgaard             Blegdamsvej 3
c/ /'_ --- Dept. of Biostatistics     2200 Cph. N
(*) \(*) -- University of Copenhagen   Denmark      Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)             FAX: (+45) 35327907
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._

```