biomodhub / biomod2

BIOMOD is a computer platform for ensemble forecasting of species distributions, enabling the treatment of a range of methodological uncertainties in models and the examination of species-environment relationships.
77 stars 21 forks source link

Need Help! Questions about "myBiomodData <- BIOMOD_FormatingData(......)" #428

Closed 691362 closed 3 months ago

691362 commented 3 months ago

Hi, I am a beginner in biomod2 and have encountered some problems that I cannot solve myself, so I want to ask for some help. When I use myBiomodData < -BIOMOD_FormatingData (......), I find that my output says "your dataset contains true absences, This should not be mixed with pseudo absences selection." However, my data set consists of real presence values (denoted by 1) and pseudo-presence points (denoted by 0). Then I checked the examples in biomod2 and it was consistent. So I want to know why this is happening. So my question may be rudimentary but I really need your help. Thank you!

My code pointcor<-read.csv(file="D:/R Data/Trachemys scripta/background.csv", header=TRUE, sep=",") pointcor <-cbind(pointcor[,2], pointcor[,3], pointcor[,4]) View(pointcor) colnames(pointcor)=c("lon","lat", "pb") View(pointcor) head(pointcor) lon lat pb [1,] 100.2327 26.88651 1 [2,] 102.8314 36.32027 1 [3,] 126.6404 45.79276 1 [4,] 126.4910 43.97847 1 ..... files<-list.files(path="D:/R Data/Trachemys scripta/2.5min",pattern='tif',full.names=TRUE) WDClim<- stack(files) names(WDClim)<-gsub("wc2.1_2.5mbio","bio",names(WDClim)) names(WDClim) chinaRange = extent(70,140,3,54) # define the extent chinacrop<-crop(WDClim, chinaRange) x<-readOGR("D:/R Data/Trachemys scripta/chinamap","bou1_4p") chinaenv<-mask(chinacrop, x) chinaraster <-stack(chinaenv) final.var<-c("bio3", "bio4", "bio6", "bio10","bio17", "bio18") rasters.selected <- subset(chinaraster, final.var) names(rasters.selected) library(biomod2) set.seed(2024) sinensis_data <- BIOMOD_FormatingData( resp.var = pointcor[,3], ## response variable 1 expl.var = rasters.selected, ## environmental variables resp.xy =pointcor[, 1:2], ## coordinates resp.name = "Trachemys scripta", ## name of the species PA.nb.rep = 0, ## ALREADY KNOW ABSENCE

PA.nb.rep = 3, ## background points: repeat 3 times

PA.nb.absences =9000, ## 500 background points PA.strategy = "random" )

Question on BIOMOD_FormatingData output

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= Trachemys scripta Data Formating -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

  ! Response variable name was converted into Trachemys.scripta
  ! No data has been set aside for modeling evaluation
  ! No data has been set aside for modeling evaluation

!!! Some data are located in the same raster cell. Please set filter.raster = TRUE if you want an automatic filtering.

Checking Pseudo-absence selection arguments...

  ! No data has been set aside for modeling evaluationError in .bm_PseudoAbsences.check.args(resp.var, expl.var, nb.rep, strategy,  : 

Your dataset contains true absences. This should not be mixed with pseudo absences selection

HeleneBlt commented 3 months ago

Hi there,

To avoid some confusion, we decide to use different denotations for pseudo-absences and real absences. So in biomod2, real absences are denoted with 0 and pseudo absences with NA. So in your case, as you have already known absences, you can choose to not select pseudo absences datasets.

sinensis_data <- BIOMOD_FormatingData(
resp.var = pointcor[,3], ## response variable 1
expl.var = rasters.selected, ## environmental variables
resp.xy =pointcor[, 1:2], ## coordinates
resp.name = "Trachemys scripta", ## name of the species
) 

Or if you want to select some pseudo-absences datasets into your pseudo-absences points, you need to change your 0s into NAs in your resp.var . Then, for example :

sinensis_data <- BIOMOD_FormatingData(
resp.var = pointcor[,3], ## response variable 1
expl.var = rasters.selected, ## environmental variables
resp.xy =pointcor[, 1:2], ## coordinates
resp.name = "Trachemys scripta", ## name of the species
PA.nb.rep = 3, 
PA.nb.absences =300,
PA.strategy = "random"
)

I hope that's clearer !

Hélène

691362 commented 3 months ago

Thank you very much for your help! Your help has been of great benefit to me as a novice. And now my problem has been solved under your guidance. Thanks again for your help, best wishes for you! .