[R] Linear Regression with lm Forcing the Slope to Equal 1

Washington Leite Junger wjunger at terra.com.br
Sun Nov 18 03:11:57 CET 2007


or simply insert the offset term into the formula
lm(y~offset(x))

Washington


On 17/11/2007 8:29 PM, Tom La Bone wrote:
> Is there a way to do a linear regression with lm (having one predictor
> variable) and constrain the slope of the line to equal 1?
> 

You could use the offset parameter to do this, e.g.

x <- 1:20
y <- x + rnorm(20)
lm(y ~ 1, offset=x)

Duncan Murdoch

______________________________________________
R-help at r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


-- 
Washington Leite Junger
wjunger at terra.com.br



More information about the R-help mailing list