jamiemkass / ENMeval

R package for automated runs and evaluations of ecological niche models.
https://jamiemkass.github.io/ENMeval/
48 stars 30 forks source link

ENMnulls error argument is of length zero #120

Closed GM-Crowley closed 2 years ago

GM-Crowley commented 2 years ago

I have run a series of models using ENMeval version 2.0.3.

e.mx.l <- ENMeval::ENMevaluate(occs = occs, envs = envs2, bg = bg, algorithm = 'maxnet', partitions = "user", user.grp = user.grp, categoricals = c("Geology","Land.zone","Vegetation"), fc = c("L","LQ","LQH","H"), RMvalues=seq(0.5, 1.5, 0.5), parallel = TRUE)

The optimum model has fc = "L", rm = 1.5 However, when I run mod.null <- ENMnulls(e.mx.l, mod.settings = list(fc = "L", rm = 1.5), no.iter = 100) I get the following error

Building and evaluating null ENMs with 100 iterations... | | 0%Error in if (eval.type == "kspatial") { : argument is of length zero

Is this something I am doing wrong, or is it a code glitch?

Many thanks Gabriel

jamiemkass commented 2 years ago

Seems you did not specify the argument user.eval.type, which is needed for user partitions. Please see the documentation. This argument is needed because the function needs to know if the partitions are spatial or not. If they are, the null cross-validation is also spatial and null records must be sampled from the training background (representing the spatial extent for model training) and not the full background (as with random k-fold, for example).

GM-Crowley commented 2 years ago

Thanks Jamie I do not have a programming background, so sometimes find the instructions confusing. I have been following your tutorial at https://jamiemkass.github.io/ENMeval/articles/ENMeval-2.0.0-vignette.html, which has been really helpful. But I guess my use case is a little different to the one in the null model example. I have two cluster-based partitions (Background partitions: red and black, occurrence partitions: blue and green). The study area will be larger in the final model, but I am trying to get the bugs out before I run it fully. [image: image.png] I added the argument "user.eval.type" as you instructed, but still have an issue. Have I left something else out? My code is now e.mx.l <- ENMeval::ENMevaluate(occs = occs, envs = envs2, bg = bg, algorithm = 'maxnet', partitions = "user", user.grp = user.grp, categoricals = c("Geology","Land.zone","Vegetation"), fc = c("L","LQ","LQH","H"), RMvalues=seq(0.5, 2, 0.5), # overlap=TRUE, overlapStat = c("D", "I"), parallel = TRUE) opt.seq <- res %>% filter(or.10p.avg == min(or.10p.avg)) %>% filter(auc.val.avg == max(auc.val.avg)) opt.seq # identifies fc = "L", rm = 1.5 as the optimum model mod.null <- ENMnulls(e.mx, mod.settings = list(fc = "L", rm = 1.5), user.eval.type = "kspatial", no.iter = 100, parallel = TRUE)

The null model runs all the way through and then gives this error

Building and evaluating null ENMs with 100 iterations... | | 0% Of 8 total cores using 8... Running in parallel using doSNOW... |=============================================================================================================| 100% Error in x[[jj]][iseq] <- vjj : replacement has length zero

Many thanks for your assistance Gabriel

On Wed, Mar 30, 2022 at 6:41 PM Jamie M. Kass @.***> wrote:

Seems you did not specify the argument user.eval.type, which is needed for user partitions. Please see the documentation. This argument is needed because the function needs to know if the partitions are spatial or not. If they are, the null cross-validation is also spatial and null records must be sampled from the training background (representing the spatial extent for model training) and not the full background (as with random k-fold, for example).

— Reply to this email directly, view it on GitHub https://github.com/jamiemkass/ENMeval/issues/120#issuecomment-1082763449, or unsubscribe https://github.com/notifications/unsubscribe-auth/AVO3MMO2N6IKC7KDBBJUUITVCQEEFANCNFSM5SAL3QSQ . You are receiving this because you authored the thread.Message ID: @.***>

-- Gabriel Crowley Gabriel Crowley Consulting Pty Ltd ABN 24 853 567 289 http://maps.google.com.au/maps?f=q&source=s_q&hl=en&geocode=&q=21+Twelfth+Avenue+Atherton,+QLD+4883&ie=UTF8&hq=&hnear=21+Twelfth+Ave,+Atherton+Queensland+4883&t=m&z=16&vpsrc=010-14 Falie Court American River Kartan Country (Kangaroo Island) SA 5221

jamiemkass commented 2 years ago

Hm, the error is pretty cryptic. Can you do me a favor and update all your packages first, restarting Rstudio, then rerunning the null models with 1 iteration? If it still doesn't work, the only thing I can do is take a look at your data and fiddle around. If you send me an RDS file of your ENMevaluation object that would be best.

GM-Crowley commented 2 years ago

Thanks Jamie

I have followed those instructions and still get the same error

mod.null <- ENMnulls(e.mx.L1.5, mod.settings = list(fc = "L", rm = 1.5), user.eval.type = "kspatial", no.iter = 1, parallel = TRUE) Building and evaluating null ENMs with 1 iterations... | | 0% Of 8 total cores using 8... Running in parallel using doSNOW...

|==============================================================================================================| 100% Error in x[[jj]][iseq] <- vjj : replacement has length zero

I have sent you a Dropbox link to ENMevaluation object to your gmail account, as it is a very large file

Thanks so much

Gabriel

On Sat, Apr 2, 2022 at 11:44 AM Jamie M. Kass @.***> wrote:

Hm, the error is pretty cryptic. Can you do me a favor and update all your packages first, restarting Rstudio, then rerunning the null models with 1 iteration? If it still doesn't work, the only thing I can do is take a look at your data and fiddle around. If you send me an RDS file of your ENMevaluation object that would be best.

— Reply to this email directly, view it on GitHub https://github.com/jamiemkass/ENMeval/issues/120#issuecomment-1086449023, or unsubscribe https://github.com/notifications/unsubscribe-auth/AVO3MMIJAM6GQS3YKKDIVOTVC6NO5ANCNFSM5SAL3QSQ . You are receiving this because you authored the thread.Message ID: @.***>

-- Gabriel Crowley Gabriel Crowley Consulting Pty Ltd ABN 24 853 567 289 http://maps.google.com.au/maps?f=q&source=s_q&hl=en&geocode=&q=21+Twelfth+Avenue+Atherton,+QLD+4883&ie=UTF8&hq=&hnear=21+Twelfth+Ave,+Atherton+Queensland+4883&t=m&z=16&vpsrc=010-14 Falie Court American River Kartan Country (Kangaroo Island) SA 5221

jamiemkass commented 2 years ago

@Gay-MC, thanks for waiting. I hadn't realized up to now, but if you specify the tuning parameters in a different order for ENMnulls() than you did for ENMevaluate(), you get this error. I'll make sure to automatically switch it in the next version so no one runs into this problem. Please just specify mod.settings = list(rm = 1.5, fc = "L") and it should run fine.

jamiemkass commented 2 years ago

Another thing I did notice is that there seems to be heavy clustering -- just making sure you addressed this by spatially thinning if applicable.

GM-Crowley commented 2 years ago

Thanks. I will try that and report back. No worries about the wait. I really appreciate the work that goes into such a package, and makes analyses impossible possible.

GM-Crowley commented 2 years ago

Thanks Jamie. With that fix, it works well now.

jamiemkass commented 2 years ago

Fixing this issue in v2.0.4. If the order is wrong, it will fix it internally.