0

I'm using the leaps package in R to run regsubsets:

a <- regsubsets(in_var~paste(predictors,collapse="+"),data=x,nbest=10,matrix=T)

And get an error message:

Error in model.frame.default(data = x, matrix = T, formula = rating ~  : variable lengths differ (found for '(matrix)')

(Note, it makes no difference if I copy out the predictors list manually or not).

I've just tried with the attitude dataset, e.g.:

data(attitude)
attitude <- na.omit(attitude)
regsubsets(rating~.,data=attitude,nbest=10,matrix=T)

And get the same error. My dataset is similar, but has more variables and the in_var is a 1-3 score (elsewhere I collapse it to a binary, for which I could later run a logistic). Not sure if I'm asking a statistics question or an R question here...

A few questions (e.g. Error in model.frame.default ...... variable lengths differ ; variable lengths differ in R ... ) deal with this, but I've already done na.omit on the dataframe, so I shouldn't have any missing values resulting in uneven vectors.

Community
  • 1
  • 1
sjgknight
  • 393
  • 1
  • 5
  • 19

1 Answers1

0

This works:

a <- regsubsets(y=as.matrix(x[c("in_var")]),x=as.matrix(x[c(predictors)]),nbest=10)

Presumably the issue is that regsubsets requires a matrix (not df)

sjgknight
  • 393
  • 1
  • 5
  • 19