Error when using a categorical predictor in ENMeval

331 views
Skip to first unread message

Adriana Uzqueda

unread,
Mar 10, 2017, 1:55:20 AM3/10/17
to Maxent
Hi all,

I am using ENMeval for model optimisation and coming across the below error when I include a categorical layer as a predictor. The categorical layer (BVGPRE) consists of 36 vegetation categories. Does anyone have any ideas on what the issue could be?



Sce1935_1955C<- ENMevaluate(occ, Stack1935_1955C, bg.coords = NULL, occ.grp = NULL,
                              bg.grp = NULL, RMvalues = seq(0.5, 5, 0.5), fc = c("L", "LQ", "LQH", "LQHP","LQHPT"),
                              categoricals = BVGPRE, n.bg = 10000, method = "randomkfold", 
                              overlap = TRUE, kfolds = 5, bin.output = TRUE, clamp = TRUE,
                              rasterPreds = TRUE, parallel = TRUE, numCores = 4, progbar = TRUE)

Doing random k-fold evaluation groups...
Error in `[.data.frame`(pres, , categoricals[i]) : 
  undefined columns selected

> traceback()
7: stop("undefined columns selected")
6: `[.data.frame`(pres, , categoricals[i])
5: pres[, categoricals[i]]
4: is.factor(x)
3: as.factor(pres[, categoricals[i]])
2: tuning(occ, env, bg.coords, occ.grp, bg.grp, method, maxent.args, 
       args.lab, categoricals, aggregation.factor, kfolds, bin.output, 
       clamp, rasterPreds, parallel, numCores, progbar, updateProgress, 
       userArgs)
1: ENMevaluate(occ, Stack1935_1955C, bg.coords = NULL, occ.grp = NULL, 
       bg.grp = NULL, RMvalues = seq(0.5, 5, 0.5), fc = c("L", "LQ", 
           "LQH", "LQHP", "LQHPT"), categoricals = BVGPRE, n.bg = 10000, 
       method = "randomkfold", overlap = TRUE, kfolds = 2, bin.output = TRUE, 
       clamp = TRUE, rasterPreds = TRUE, parallel = TRUE, numCores = 4, 
       progbar = TRUE)

Jamie M. Kass

unread,
Mar 21, 2017, 10:57:16 PM3/21/17
to Maxent
Looks like you need to put quotes around the categorical raster's name.

Jamie

Nolan Helmstetter

unread,
Dec 23, 2018, 6:27:47 PM12/23/18
to Maxent
Did you have any luck solving this issue? I am currently having the same problem.

Thanks,

N

Jamie M. Kass

unread,
Dec 23, 2018, 6:33:18 PM12/23/18
to Maxent
Did you put quotes around the name of the categorical raster like I mentioned in my last post?

Jamie

Nolan Helmstetter

unread,
Dec 26, 2018, 1:28:06 PM12/26/18
to Maxent
Hey Jamie,

Yes, I did put quotes around it. I am importing rasters from ArcMap into R to use in ENMeval. The categorical raster I am using is fire interval which is broken up into categories (e.g. 3-5 years, 6-8 years, etc...). Each category is specified as a numerical value that represents each category. I am using the Raster package to import them. I have tried ratify and as.factor but still cannot get ENMeval to work (I get the same error). Also, when I examine the raster it says "as.factor: TRUE." So I believe it is being recognized as categorical. I will try to upload some code/images soon if that would help.

Thanks,

Nolan

Jamie M. Kass

unread,
Dec 29, 2018, 3:42:43 PM12/29/18
to Maxent
Nolan, yes I think that would help. Can you also specify the particular problem you're having with ENMeval? Thanks.

Jamie

Nolan Helmstetter

unread,
Jan 2, 2019, 1:57:32 PM1/2/19
to Maxent
Hi Jamie,

I figured it out. It's one of those "doh" mistakes on my part but I'll post the "solution" in case anyone else has the issue (I'll make it brief by not including the whole script).

I loaded my environmental variables using package raster, they were all ArcMap rasters.

##Load variables (fire is a categorical variable, I also loaded many other variables and stacked them all)
fire<-raster("E:/filename/fireint")

I then tried to run ENMeval

##ENMeval

eval_test<-ENMevaluate(occ=occs, env=envs, bg.coords=bg,RMvalues = c(1,2),
            fc=c('L','LQ'),n.bg=10000,
            method='block',categoricals='fire',overlap=FALSE,algorithm='maxnet')

When I ran it as above I got the error:

Error in `[.data.frame`(pres, , categoricals[i]) : 
  undefined columns selected

then I realized that in all the outputs (when I tested it without a categorical), the actual file name was used. So instead of 
categoricals='fire'
I had to use
categoricals='fireint'

eval_test<-ENMevaluate(occ=occs, env=envs, bg.coords=bg,RMvalues = c(1,2),
            fc=c('L','LQ'),n.bg=10000,
            method='block',categoricals='fireint',overlap=FALSE,algorithm='maxnet')

It ran fine and recognized that variable as categorical.

I did have another question however, and perhaps it is better to post it in another thread, but I was wondering if it is possible to export the partitioned occurrences as a shapefile with coordinates. For example, I would like to export the results of the Block method in order to compare different model algorithms using the same partitioning method. Essentially, can I export the coordinates along with the number (1-4) for the group it was partitioned in to? 

Thanks,

Nolan

Jamie M. Kass

unread,
Jan 8, 2019, 2:59:30 PM1/8/19
to max...@googlegroups.com
Great that you figured it out, and thanks for posting the solution for everyone.

Jamie

--
You received this message because you are subscribed to a topic in the Google Groups "Maxent" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/maxent/vAB5G3Eo1ho/unsubscribe.
To unsubscribe from this group and all its topics, send an email to maxent+un...@googlegroups.com.
To post to this group, send email to max...@googlegroups.com.
Visit this group at https://groups.google.com/group/maxent.
For more options, visit https://groups.google.com/d/optout.


--
-----------------------------------------------------------
Jamie M. Kass
PhD Candidate, Dept. of Biology
City College of New York, CUNY Graduate Center
Reply all
Reply to author
Forward
0 new messages