1
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)

So far, identical output.

lmModel2 <- lm(y ~ x, data = df, weights = weights)
summary(lmModel2)
speedLmModel2 <- speedlm(y ~ x, data = df, weights = df$weights)
summary(speedLmModel2)

The error I am getting is

> speedLmModel2 <- speedlm(y ~ x, data = df, weights = df$weights)
Error in switch(method, eigen = { : EXPR must be a length 1 vector

From ‘speedglm’ package's documentation,

weights: the same of function lm, but it must be specified as data$weights

Any help please?

Tony
  • 781
  • 6
  • 22
  • Seems that specifying a `method` works: `speedlm(y ~ x, data = df, weights = df$weights,method="qr")`. But it looks like a bug: in the internal `speedglm:::speedlm.wfit` a line like `method<-match.arg(method)` is missing and this leads to the `method` argument being a vector by default and as such cannot be handled by `switch`. You should contact the maintainer. – nicola Jan 05 '17 at 11:57
  • Thank you, will do. In the current example, any of the three available methods (''qr'', ''eigen'', "Cholesky") will return the same output. But the method used in lm (the only one supported, from what I read in lm {stats} documentation) is ''qr''. – Tony Jan 05 '17 at 12:09

0 Answers0