Linear Regression with a known fixed intercept in R

前端 未结 3 1599
花落未央
花落未央 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 20:59

    I have used both offset and I(). I also find offset easier to work with (like BondedDust) since you can set your intercept.

    Assuming Intercept is 10.

    plot (lin$x, lin$y) fit <-lm(lin$y~0 +lin$x,offset=rep(10,length(lin$x))) abline(fit,col="blue")

提交回复
热议问题