Use of offset in lm regression - R
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