library(speedglm)
df <- data.frame(y = numeric(30), x = numeric(30), weights = numeric(30))
df$y <- c(5,3,8,3,8,9,3,1,3,5,6,7,8,9,1,4,3,2,4,7,2,5,9,2,3,1,4,5,5,7)
df$x <- c(7,5,3,6,8,9,5,3,1,2,3,6,9,6,3,8,9,0,7,5,3,1,2,3,4,9,7,5,3,2)
df$weights <- c(.3,.4,.6,.8,.4,.3,.4,.9,.6,.7,.4,.1,.2,.3,.6,.3,.7,.5,.3,.1,.5,.9,.6,.1,.2,.1,.5,.3,.9,.6)
lmModel <- lm(y ~ x, data = df)
summary(lmModel)
speedLmModel <- speedlm(y ~ x, data = df)
summary(speedLmModel)
到目前为止,输出相同。
lmModel2 <- lm(y ~ x, data = df, weights = weights)
summary(lmModel2)
speedLmModel2 <- speedlm(y ~ x, data = df, weights = df$weights)
summary(speedLmModel2)
我得到的错误是
> speedLmModel2 <- speedlm(y ~ x, data = df, weights = df$weights) Error in switch(method, eigen = { : EXPR must be a length 1 vector
来自'speedglm'软件包的文档,
权重:与函数lm相同,但必须指定为数据$ weights
请帮忙吗?