Warning messages: 1: In matrix(as.numeric(d)) : NAs introduced by coercion 2: In cor(x, y) : the standard deviation is zero

230 views
Skip to first unread message

Lays

unread,
Apr 2, 2021, 2:06:07 AM4/2/21
to Maxent
Hello, I'm currently trying to run an analyses of niche breadth using the ENMTools package and I am getting an error when running the function env.breadth.

Error in if (max(pred) == 0) { : missing value where TRUE/FALSE needed

I figured out the error is related to my enmtools.maxent file, but I can't figure out how to debug this.

Does anyone here know how to fix it?


my code is

files <- stack(list.files(path = "south_america", pattern='.asc', full.names=TRUE))
names(files) <- c("Bio1", "Bio2", "Bio3", "Bio4", "Bio5", "Bio6", "Bio7",
                  "Bio8", "Bio9", "Bio10", "Bio11", "Bio12", "Bio13", "Bio14", "Bio15",
                  "Bio16", "Bio17", "Bio18", "Bio19", "Alt", "Srad", "Vapr", "Wind", "Aridity")

sp <- enmtools.species()
sp$species.name <- "xol"
sp$presence.points <- read.csv2("path.csv", sep=";", dec = ",")
#sp$range <- background.raster.buffer(sp$presence.points, 100000, files)
sp$background.points <- background.points.buffer(points = sp$presence.points,
                                                        radius = 20000, n = 1000, mask = files[[1]])
sp$range <- NULL
#sp$background.points <- NULL

sp <- check.species(sp)
#interactive.plot.enmtools.species(sp)
sp.maxent <- enmtools.maxent(sp, files, test.prop = "block", bg.source = "points", verbose= TRUE, env.nback = 1000,
                             args =c("betamultiplier=4","autofeature=FALSE",  "linear", "quadratic", "noproduct",
                                     "hinge", "randomseed=TRUE","jackknife=TRUE", "doclamp=FALSE",
                                     "extrapolate=FALSE", "applythresholdrule=Maximum training sensitivity plus specificity"))

#####
Warning messages:
1: In matrix(as.numeric(d)) : NAs introduced by coercion
2: In cor(x, y) : the standard deviation is zero
3: In cor(x, y) : the standard deviation is zero
4: In cor(x, y) : the standard deviation is zero
5: In cor(x, y) : the standard deviation is zero

nichebreadth <- env.breadth (sp.maxent, files)

######
Error in if (max(pred) == 0) { : missing value where TRUE/FALSE needed


thank you in advance,

Lays

Dan Warren

unread,
Apr 2, 2021, 4:54:38 AM4/2/21
to Maxent
My best guess without having the data in front of me is that there's an NA value for one of your environmental layers at one of your occurrence points.  Can you extract the environmental values at your points and check whether that is the case?

Lays Viturino de Freitas

unread,
Apr 2, 2021, 10:51:22 AM4/2/21
to max...@googlegroups.com
Yea. That was my first thought too. I did that before posting here. And it seems to be something with my environmental layers, but I can't find where is the issue. Is there a way enmtools/dismo should read the environmental layers that I am not aware of? 

--
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/sygh_R2JmU4/unsubscribe.
To unsubscribe from this group and all its topics, send an email to maxent+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/maxent/5f4e0123-29d9-443c-9dd8-93b0a7a47588n%40googlegroups.com.

Dan Warren

unread,
Apr 4, 2021, 6:53:34 PM4/4/21
to Maxent
Unfortunately this is one of those things where it's really hard to tell from here what's going on.  If you can share your data with me I can probably figure out what's going on, but I know that's not always possible.

Lays Viturino de Freitas

unread,
Apr 4, 2021, 6:59:38 PM4/4/21
to max...@googlegroups.com
Oh. It's no problem. I can share it with you. I would really appreciate if you can look into that, actually. Can I send it to your gmail? 

Thank you for your time. :)

Dan Warren

unread,
Apr 5, 2021, 4:50:45 AM4/5/21
to Maxent
Sure!

Dan Warren

unread,
Apr 5, 2021, 10:38:58 PM4/5/21
to Maxent
Thank you very much for sending the data!  It's allowed me to figure out two things:

1.  The env.breadth function gets mad if you don't run setMinMax on your environment layers sometimes, so after you read in your env stack you should do env <- setMinMax(env).

2.  More importantly, in some recent update we managed to screw up the test.prop = "block" functionality, which was causing you to get models that didn't make any predictions.  I'm pushing a fix for this to the github develop branch right now, so you'll want to do this:

install.packages("devtools") # If you don't have it already
devtools::install_github("danlwarren/ENMTools", ref = "develop")
library(ENMTools)

After that you should be able to run your models and get reasonable results.  It's working for me now, anyway.  Do let me know if that doesn't fix it on your end!

Lays Viturino de Freitas

unread,
Apr 8, 2021, 3:43:18 PM4/8/21
to max...@googlegroups.com
Thank you so much. I just tried and it's working normally here as well. ^^



--

Lays Viturino de Freitas
___________________________________________________________________
Bióloga/UFPE
Msc. em Biologia Animal - Universidade Federal de Pernambuco
Laboratório de Ecologia,  Biogeografia e Evolução de Aves/Ornitolab UFPE (http://ornitolab.wix.com/ufpe)
Observadores de Aves de Pernambuco

Lays Viturino de Freitas

unread,
Apr 29, 2021, 1:55:54 AM4/29/21
to max...@googlegroups.com
Hello again, Dan. 

Somehow, the function enmtools.maxent it's not working anymore. The error of NAs showing up on my presence points out of nowhere is back and my response.plots don't show suitability. I have checked my occurrence points for NAs and the problem is not there. I even ran with the same occurrences of before and the NAs are back there as well... :( 


Dan Warren

unread,
Apr 29, 2021, 6:23:58 PM4/29/21
to Maxent
I don't seem to be able to duplicate it here; everything is working fine for me on the data you sent me.  Out of curiosity, if you run the code you sent me and then type "sp.maxent$model", what do you get?

Lays Viturino de Freitas

unread,
May 2, 2021, 2:19:10 AM5/2/21
to max...@googlegroups.com
The html file is normal, but idk why I am getting these NAs on my presence points and why the response.plots is bugged. I made sure to extract the values of the variables using them to check and there's nothing. I tried the same script I sent here and the same files I sent to you. I can't even generate my predict file anymore... are you sure nothing changed in the package that could be causing that?  

Dan Warren

unread,
May 2, 2021, 5:28:49 AM5/2/21
to Maxent
Okay I still can't duplicate the whole problem, but I can duplicate a bit of it.  The "NA" message is actually coming from dismo's maxent function, and the thing is that the error message itself is wrong - there aren't any NAs at your presence points, but there are NAs at four of the background points.  We should insert a check for that in ENMTools for sure, but even with those I'm still getting predictions and response plots from your data.  However if you want to try removing them and see if that fixes things for you you can just do this (modifying your code):

test.points <- background.points.buffer(points = sp$presence.points, radius = 200000, n = 1000, mask = files[[1]])
test.points <- cbind(test.points, extract(files, test.points))
test.points <- test.points[complete.cases(test.points),1:2]

sp$background.points <- test.points

That gets rid of the background points with NAs.  For what it's worth those background points do have values for everything but the aridity layer, which seems to have NAs in some cells that your other rasters don't have.

Lays Viturino de Freitas

unread,
Jun 28, 2021, 5:29:12 PM6/28/21
to max...@googlegroups.com
Hey, Dan. Thank you so much for your help. The problem was indeed with my aridity layer. I removed it and my script worked without issues.
But something weird is happening now. I am trying to run some analyses again, but now it seems a new issue has shown up when I try to run enmtools.maxent(), even if I try to run the same script from April with the suggestion to setMinMax for my env layers.

The error msg is

Error in data.frame(..., check.names = FALSE) : 
  arguments imply differing number of rows: 1, 2, 0

Do you have any suggestions?


Dan Warren

unread,
Jun 29, 2021, 5:16:59 AM6/29/21
to Maxent
Just out of curiosity, does it suddenly get fixed when you get rid of the test.prop = "block" argument?  

Lays Viturino de Freitas

unread,
Jun 30, 2021, 3:14:31 AM6/30/21
to max...@googlegroups.com
I just tried replacing "block" for some percent and indeed, it worked... The issue is probably there again...

Dan Warren

unread,
Jun 30, 2021, 4:49:33 AM6/30/21
to Maxent
Actually I believe this is a fun NEW problem.  It's one with a relatively easy solution, though.  Try installing the version of ENMTools I just pushed to the "develop" branch on github and see if that fixes it.  

library(devtools)
install_github("danlwarren/ENMTools", ref = "develop")

Lays Viturino de Freitas

unread,
Jun 30, 2021, 9:34:57 AM6/30/21
to max...@googlegroups.com
I just tried and it worked even with the aridity layer containing NAs. :)
Thank you so much again. :)

Reply all
Reply to author
Forward
0 new messages