Closed ptitle closed 4 years ago
Hi @ptitle
Thanks for reporting this. Have you had a look at the fitted variogram model? If possible could you send me your raster data for further checking?
Thanks, Roozbeh email: rvalavi@student.unimelb.edu.au
Dear @ptitle Indeed the problem is because of the nature of your data. If you have a look at the variogram model of your layer (the following figure that quantifies the structure of spatial autocorrelation of your layer), it does not flat out and the range cannot be identified! I recommend you to choose the block size based on other methods e.g. the range of spatial autocorrelation of your model residual. As mentioned in the associated paper the spatialAutoRange is not an absolute solution to choosing block size!
Following your suggestion, I generated a correlogram to estimate at what distance spatial autocorrelation drops to zero, and then used that distance for producing spatial blocks.
# sample a set of points across the raster and generate correlogram
dat <- as.data.frame(coordinates(bio1))
dat <- cbind.data.frame(dat, val = values(bio1))
dat <- dat[complete.cases(dat),]
dat <- dat[sample(1:nrow(dat), 10000),]
co1 <- ncf::correlog(dat$x, dat$y,dat$val, increment = 1, resamp = 0, latlon = T, na.rm=TRUE)
plot(co1$mean.of.class, co1$correlation, type='b', cex=0.5, ylab='correlation', xlab='distance class')
abline(h=0, lty=3)
abline(v=co1$x.intercept, lty=3)
# the dotted vertical line shows where spatial autocorrelation = 0.
zeroSA <- co1$x.intercept #in kilometers
folds <- spatialBlock(PA, rasterLayer=bio1, theRange=zeroSA*1000, k=5, biomod2Format=F)
Using that distance for spatialBlock()
, I get the following:
Hi @ptitle Sorry for the late response. I do not receive any warning for a message if you do not mention me in the message. Well, this is still the spatial autocorrelation in the predictor raster. If you have presence-absence data, you can fit a simple model like a GLM, calculate the residuals and check the spatial autocorrelation in the residuals (e.g. with your correlogram).
I recommend having a look at Roberts et al., 2017, Cross-validation strategies for data with temporal, spatial, hierarchical, or phylogenetic structure, Ecography. There are good recommendation and background about the impacts of spatial autocorrelation on model evaluation.
I find that if I provide an unprojected raster to spatialAutoRange(), it finds one enormous block. I think this is incorrect.