I’m trying to sample random points to use as background in a species distribution model. I’m using 30 second predictors from worldclim and soilgrids. The majority of the sampled random points are on the ocean, as if there were values in those cells, outside my masked area.
This is my code:
bg<-as.data.frame(sampleRandom(env.pred[[1]], size=10000, na.rm=F, xy=TRUE))
env.pred is a rasterstack with all predictors masked:
> pred.mask class : RasterBrick dimensions : 21600, 43200, 933120000, 24 (nrow, ncol, ncell, nlayers) resolution : 0.008333333, 0.008333333 (x, y) extent : -180, 180, -90, 90 (xmin, xmax, ymin, ymax) crs : +proj=longlat +datum=WGS84 +no_defs source : r_tmp_2024-05-03_142200_7224_49931.grd names : bio1, bio10, bio11, bio12, bio13, bio14, bio15, bio16, bio17, bio18, bio19, bio2, bio3, bio4, bio5, ... min values : 9.283334, 11.466667, 6.466667, 502.000000, 58.000000, 0.000000, 5.105296, 157.000000, 1.000000, 79.000000, 1.000000, 5.566667, 36.323528, 86.614578, 16.600000, ... max values : 26.15417, 27.68333, 24.81667, 3249.00000, 403.00000, 163.00000, 103.06243, 1157.00000, 549.00000, 1157.00000, 841.00000, 14.12500, 78.41881, 465.92282, 33.30000, ...
When I try na.rm=T I only get 61 points.
Has anyone experienced this situation?
My expectation was that all the sampled points would be inside my mask area.