我对卫星标记的海龟有 608 次观察。我想用包括海面温度、当前速度、风速等在内的环境数据对这些进行建模。当然,标记和环境数据都会在空间和时间上发生变化。我使用从这里改编的下面的代码生成了伪缺席数据。但是,我现在意识到我生成的数据点只是空间样本。有什么方法可以编辑此代码以进行临时采样,以便生成的 csv 具有每个点的日期/时间,以便我可以将其与我的环境数据相匹配?或者,我可以尝试一个不同的包来允许我这样做吗?
dir.create(path = "data")
library("sp")
library("raster")
library("maptools")
library("rgdal")
library("dismo")
bioclim.data <- getData(name = "worldclim",
var = "bio",
res = 2.5,
path = "data/")
# Read in observations
obs.data <- read.csv(file = "data/Presence.csv")
# Determine geographic extent of data
max.lat <- ceiling(max(obs.data$Latitude))
min.lat <- floor(min(obs.data$Latitude))
max.lon <- ceiling(max(obs.data$Longitude))
min.lon <- floor(min(obs.data$Longitude))
geographic.extent <- extent(x = c(min.lon, max.lon, min.lat, max.lat))
# Use the bioclim data files for sampling resolution
bil.files <- list.files(path = "data/wc2-5",
pattern = "*.bil$",
full.names = TRUE)
# only need one file, so use the first one in the list of .bil files
mask <- raster(bil.files[1])
# Randomly sample points (same number as our observed points)
background <- randomPoints(mask = mask, # Provides resolution of sampling points
n = nrow(obs.data), # Number of random points
ext = geographic.extent, # Spatially restricts sampling
extf = 1.25) # Expands sampling a little bit
write.csv(background, "pseudo-absence.csv")