0

When running this code:

predict(rfm, x[split.idx[[i]], sig_otu], type="prob")

I get this error message:

Error in x[, vname, drop = FALSE] : subscript out of bounds

Does this error message arise from incorrect bracketing? I've tried re-arranging brackets, adding parentheses, etc. However, I will still get this error message.

split.idx is a list of 8 str(split.idx)

List of 8

 $ 1: Named int [1:10] 2 3 13 17 34 40 72 70 30 27
  ..- attr(*, "names")= chr [1:10] "01" "09" "017" "025" ...
 $ 2: Named int [1:10] 21 32 67 52 12 55 36 37 24 31
  ..- attr(*, "names")= chr [1:10] "02" "010" "018" "026" ...
 $ 3: Named int [1:10] 49 58 64 8 54 62 1 41 39 35
  ..- attr(*, "names")= chr [1:10] "03" "011" "019" "027" ...
 $ 4: Named int [1:10] 46 59 20 43 47 4 57 76 33 29
  ..- attr(*, "names")= chr [1:10] "04" "012" "020" "028" ...
 $ 5: Named int [1:10] 42 45 69 71 44 38 7 10 9 78
  ..- attr(*, "names")= chr [1:10] "05" "013" "021" "029" ...
 $ 6: Named int [1:10] 15 5 73 61 63 25 28 48 53 14
  ..- attr(*, "names")= chr [1:10] "06" "014" "022" "030" ...
 $ 7: Named int [1:10] 68 6 23 11 65 16 66 26 22 56
  ..- attr(*, "names")= chr [1:10] "07" "015" "023" "031" ...
 $ 8: Named int [1:9] 51 60 74 75 50 19 77 18 79
  ..- attr(*, "names")= chr [1:9] "08" "016" "024" "032" ...

This is the type of variable sig_otu is:

str(sig_otu)
Named int [1:56] 12 26 44 50 79 131 144 178 240 253 ...
   - attr(*, "names")= chr [1:56] "" "" "" "" ...

This is the value assigned to rfm:

rfm <- randomForest(x[-split.idx[[i]]], sig_otu], y[-split.idx[[i]]])

X is a large matrix with dim [1] 79, 1924.

Y is discrete factor with length 79 and 2 levels.

I hope that my question is clear enough to answer.

i refers to this line that I ran earlier in the code: for(i in 1:k) and I set k=8.

> dim(x)[2] [1] 1924

> max(sig_otu) [1] 1921

Brian Lee
  • 39
  • 7
  • 3
    If you want to see why/where this is failing, you need to debug the particular method for `predict()` that is being called. In this case it is `predict.randomForest()` but as this is not exported from the package namespace if randomForest you need `debugonce(randomForest:::predict.randomForest`)` to set the debug status on it. Then run the `predict()` line again and step through the code to see where it is failing. – Gavin Simpson Aug 28 '14 at 21:18
  • `rfm <- randomForest(x[-split.idx[[i]]], sig_otu], y[-split.idx[[i]]])` this expression looks like it needs a bit more attention or explanation or both. The square brackets are incorrect (count them). Also, does `i` have a value or is it a loop variable - or is it suppose to represent some formula mode (or should it not be there)? – Rusan Kax Aug 28 '14 at 22:18
  • The error code says 'vname' is not in the column names or numbers of 'x'. Since we cannot see where 'x' was created, can only suggest you look at `max(sig_otu)` and `dim(x)[2]` – IRTFM Aug 28 '14 at 22:55
  • @RusanKax `i` comes from this line: `for(i in 1:k)`, k=8. – Brian Lee Aug 29 '14 at 15:35
  • @BrianLee, I don't see that in the question..so you need to edit the question and add all the details...we cannot guess or mind read, right? Is `k` defined in the question, also? Use the edit button on your question. – Rusan Kax Aug 29 '14 at 15:37
  • @BondedDust I edited my post to include it – Brian Lee Aug 29 '14 at 15:40

1 Answers1

0

Somthing that worked for me was:

  1. Editing the predict.randomForest function. To do so type randomForest:::predict.randomForest (I assume the randomForest package is loaded).
  2. Renaming the function. For example, myrandomForestpredictfun=prediccion.rf=function (object, newdata, type = "response", norm.votes = TRUE, predict.all = FALSE, proximity = FALSE, nodes = FALSE, cutoff, ...)
  3. Commenting the line that contains "x <- x[, vname, drop = FALSE]"
  4. Using your new function to get predictions on the training set.