1

I am trying to create a BRT model using the dismo package. When I simplify my model following the cran tutorial, and then try to respecify it I get an error saying: "Error in data[, gbm.x, drop = FALSE] : incorrect number of dimensions".

I am not sure what the problem is and any help would be appreciated.

> BRTsynoptic <- gbm.step(data=synoptic, gbm.x = 2:14,      gbm.y = 1,
 family = "bernoulli", tree.complexity = 10,
learning.rate = .001, bag.fraction = 0.75)
summary(BRTsynoptic)
#simplify the model
synoptic.simp <- gbm.simplify(BRTsynoptic, n.drops = 5)
#assign new model with simplification
synopticss.simp <- gbm.step(BRTsynoptic,
gbm.x=synoptic.simp$pred.list[[4]], gbm.y=1,
                               tree.complexity=10,learning.rate=0.001)

1 Answers1

0

If you look at the synoptic.simp$final.drops, it is a data frame. See below for a reproducible example:

library(dismo)
data(Anguilla_train)
Anguilla_train = Anguilla_train[1:200,]

mdl <- gbm.step(data=Anguilla_train, gbm.x = 3:14, 
gbm.y = 2, family = "bernoulli",
tree.complexity = 10, learning.rate = 0.001, bag.fraction = 0.75)
train.simp <- gbm.simplify(mdl, n.drops = 5)

train.simp$final.drops
        preds order
1       DSDam     1
2  USRainDays     2
3     USSlope     3
4  SegLowFlow     4
5    SegTSeas     5
6     SegSumT    NA
7      DSDist    NA
8  DSMaxSlope    NA
9      USAvgT    NA
10   USNative    NA
11     Method    NA
12     LocSed    NA

To re-run your model, you need to pull out the preds which are NAs in the second column:

var_names = with(train.simp$final.drops,preds[which(is.na(order))])
idx = match(var_names,colnames(Anguilla_train))

mdl.simp <- gbm.step(Anguilla_train,
gbm.x=idx, gbm.y=2,
tree.complexity=10,learning.rate=0.001)
StupidWolf
  • 45,075
  • 17
  • 40
  • 72
  • Is there a way to only use the variables with a NA. The variables without an NA are the ones that are not dropped from the model. Also, when running the code you provided I still get the same error. Is there an issue with my data frame? – Tyler Harrow-Lyle Mar 03 '20 at 16:44
  • Here is the output: dput(synoptic.simp$final.drops) structure(list(preds = structure(c(5L, 13L, 2L, 4L, 12L, 8L, 3L, 10L, 1L, 9L, 6L, 7L, 11L), .Label = c("Calcium", "Conductivity", "Depth", "DFBL", "Iron", "Magnesium", "Manganese", "pH", "Potassium", "Secchi", "Sodium", "TN", "TOC"), class = "factor"), order = c(1L, 2L, 3L, 4L, 5L, NA, NA, NA, NA, NA, NA, NA, NA)), .Names = c("preds", "order"), row.names = c(NA, -13L), class = "data.frame") – Tyler Harrow-Lyle Mar 03 '20 at 16:54
  • Ok. Is there an issue with my original data frame that I get this error still? Error in data[, gbm.x, drop = FALSE] : incorrect number of dimensions Thanks for your help as well! – Tyler Harrow-Lyle Mar 03 '20 at 17:02
  • Would changing the version of R correct this. It seems the bug is persistent? Thanks for all the help – Tyler Harrow-Lyle Mar 03 '20 at 17:11
  • I am now getting this error: Error in synoptic.simp$pred.list[[4]]$order : $ operator is invalid for atomic vectors – Tyler Harrow-Lyle Mar 03 '20 at 17:17
  • hmmm your regression did not work. If you try my example, you get the error as well. Sorry now I am beginning to understand the issue. I am on R 3.6.1 , dismo 1.1-4 – StupidWolf Mar 03 '20 at 17:18
  • Yes, when I ran your example I got this error code: Error in data[, gbm.x, drop = FALSE] : incorrect number of dimensions. Same error as my original attempt. All of your other code has worked, up until the last set with the $pred.list – Tyler Harrow-Lyle Mar 03 '20 at 17:19
  • After trying R 3.6.1 and R 3.6.3 and dismo 1.1.4 the problem persists. Am I missing something or is it a bug with R on my PC? – Tyler Harrow-Lyle Mar 03 '20 at 18:39
  • I have tried clearing all the caches, creating a new session and everything. I have also now tried on three separate computers. One computer had a fresh install. I am not sure what the issue could be now then. – Tyler Harrow-Lyle Mar 03 '20 at 20:27
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/208941/discussion-between-stupidwolf-and-tyler-harrow-lyle). – StupidWolf Mar 03 '20 at 20:31
  • Sorry I am very new to this site. How do I start a chat with you? – Tyler Harrow-Lyle Mar 05 '20 at 17:33
  • Use the link I have above? – StupidWolf Mar 05 '20 at 20:26