【发布时间】:2013-05-31 00:20:11
【问题描述】:
我有这个代码
dens <- read.table('DensPiu.csv', header = FALSE)
fl <- read.table('FluxPiu.csv', header = FALSE)
mydata <- data.frame(c(dens),c(fl))
dat = subset(mydata, dens>=3.15)
colnames(dat) <- c("x", "y")
attach(dat)
我想对 dat 中包含的数据进行最小二乘回归,函数的形式为
y ~ a + b*x
并且我希望回归线通过特定点 P(x0,y0)(这不是原点)。
我正在尝试这样做
x0 <- 3.15
y0 <-283.56
regression <- lm(y ~ I(x-x0)-1, offset=y0)
(我认为在这种情况下不需要 data = dat)但我收到此错误:
Error in model.frame.default(formula = y ~ I(x - x0) - 1, : variable
lengths differ (found for '(offset)').
我不知道为什么。我想我没有正确定义偏移值,但我在网上找不到任何示例。
有人可以向我解释一下offset是如何工作的吗?
【问题讨论】:
-
您能否提供一个可重现的示例,并附上数据?
-
请问这个问题和你之前的问题有什么区别?
-
现在我要求定义 offset 中的对象。我之前的问题是关于如何对特定点进行回归传递。
-
帮助文件说这必须是一个向量而不是一个常数:
this can be used to specify an a priori known component to be included in the linear predictor during fitting. This should be NULL or a numeric vector of length equal to the number of cases. One or more offset terms can be included in the formula instead or as well, and if more than one are specified their sum is used. See model.offset. -
谢谢。我在上一个评论中问了这个问题,但没有人回答。因此,由于它是一个完全独立的主题(offset 的使用,而不是通过一个点的回归),我认为它可以单独处理。