Linear Regression with a known fixed intercept in R

前端 未结 3 1585
花落未央
花落未央 2020-11-29 20:51

I want to calculate a linear regression using the lm() function in R. Additionally I want to get the slope of a regression, where I explicitly give the intercept to lm

3条回答
  •  醉梦人生
    2020-11-29 21:03

    I see that you have accepted a solution using I(). I had thought that an offset() based solution would have been more obvious, but tastes vary and after working through the offset solution I can appreciate the economy of the I() solution:

    with(lin, plot(y,x) )
    lm_shift_up <- lm(x ~ y +0 + 
                           offset(rep(1, nrow(lin))), 
                 data=lin)
    abline(1,coef(lm_shift_up))
    

提交回复
热议问题