Use of offset in lm regression - R

痴心易碎 提交于 2019-11-30 22:27:43

Your offset term has to be a variable, like x and y, not a numeric constant. So you need to create a column in your dataset with the appropriate values.

dat$o <- 283.56
lm(y ~ I(x - x0) - 1, data=dat, offset=o)

In fact, the real issue here is that you should specify offset with a vector whose length is the same as the number of rows (or the length, if data is composed as a vector) of your data. The following code will do your job as expected:

regression <- lm(y ~ I(x-x0)-1, offset = rep(y0, length(y))

Here is a good explanation for those who are interested: http://rfunction.com/archives/223

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!