Closed rogerio-bio closed 1 year ago
I solved the problem
The extract function of the terra package creates a dataframe when creating pres and contrast. However, enmSdmX only accepts numeric objects.
To solve the problem
#Use unlist in the data.frame object pres <- unlist(pres)
#Transform to numeric and the problem is solved. pres <- as.numeric(pres)
The same process should be applied to the contrast object.
Hello,
I used to use enmSdm, but since all packages are migrating to the terra package, I changed my script to work with this package. My R in version 4.2.2, and i'm using package SDMTune in the latest version.
However, always this same error when calculating the CBI:
Here is my script:
CBI
Create spatial Points object from species presence dataframe
species <- vect(species_presence_data, geom = c("Longitude", "Latitude"), crs="WGS84")
Extract values of prediction raster at species presence points
pres <- extract(prediction, species)
Create spatial Points object from bg dataframe
bg_CBI <- vect(bg, geom = c("Longitude", "Latitude"), crs="WGS84")
Extract values of prediction raster at background points
contrast <- extract(prediction, bg_CBI)
Calculate Boyce Index using evalContBoyce function
cbiMax <- evalContBoyce(pres, contrast, na.rm = TRUE)
Error in min(c(pres, contrast), na.rm = na.rm) : invalid 'type' (list) of argument
How can i solve this? All my packages are updated.