predict.svcTIntPGOcc | R Documentation |
The function predict
collects posterior predictive samples for a set of new locations given an object of class 'svcTIntPGOcc'. Detection prediction is not currently supported. Predictions are currently only possible for sampled primary time periods.
## S3 method for class 'svcTIntPGOcc'
predict(object, X.0, coords.0, t.cols, n.omp.threads = 1,
verbose = TRUE, n.report = 100,
ignore.RE = FALSE, type = 'occupancy', forecast = FALSE, ...)
object |
an object of class svcTIntPGOcc |
X.0 |
the design matrix of covariates at the prediction locations. This should be a three-dimensional array, with dimensions corresponding to site, primary time period, and covariate, respectively. Note that the first covariate should consist of all 1s for the intercept if an intercept is included in the model. If random effects are included in the occupancy (or detection if |
coords.0 |
the spatial coordinates corresponding to |
t.cols |
an indexing vector used to denote which primary time periods are contained in the design matrix of covariates at the prediction locations ( |
n.omp.threads |
a positive integer indicating
the number of threads to use for SMP parallel processing. The package must
be compiled for OpenMP support. For most Intel-based machines, we recommend setting
|
verbose |
if |
ignore.RE |
logical value that specifies whether or not to remove random unstructured occurrence (or detection if |
n.report |
the interval to report sampling progress. |
type |
a quoted keyword indicating what type of prediction to produce. Valid keywords are 'occupancy' to predict latent occupancy probability and latent occupancy values (this is the default), or 'detection' to predict detection probability given new values of detection covariates. Detection prediction is not currently supported for integrated models. |
forecast |
a logical value indicating whether prediction is occurring at non-sampled primary time periods (e.g., forecasting). |
... |
currently no additional arguments |
A list object of class predict.svcTIntPGOcc
. When type = 'occupancy'
, the list consists of:
psi.0.samples |
a three-dimensional object of posterior predictive samples for the latent occupancy probability values with dimensions corresponding to posterior predictive sample, site, and primary time period. |
z.0.samples |
a three-dimensional object of posterior predictive samples for the latent occupancy values with dimensions corresponding to posterior predictive sample, site, and primary time period. |
w.0.samples |
a three-dimensional array of posterior predictive samples for the spatial random effects, with dimensions corresponding to MCMC iteration, coefficient, and site. |
When type = 'detection'
, the list consists of:
p.0.samples |
a three-dimensional object of posterior predictive samples for the detection probability values with dimensions corresponding to posterior predictive sample, site, and primary time period. |
The return object will include additional objects used for standard extractor functions.
When ignore.RE = FALSE
, both sampled levels and non-sampled levels of unstructured random effects are supported for prediction. For sampled levels, the posterior distribution for the random intercept corresponding to that level of the random effect will be used in the prediction. For non-sampled levels, random values are drawn from a normal distribution using the posterior samples of the random effect variance, which results in fully propagated uncertainty in predictions with models that incorporate random effects.
Occurrence predictions at sites that are only sampled for a subset of the total number of primary time periods are obtained directly when fitting the model. See the psi.samples
and z.samples
portions of the output list from the model object of class svcTIntPGOcc
.
Jeffrey W. Doser doserjef@msu.edu,
Andrew O. Finley finleya@msu.edu
set.seed(332)
# Simulate Data -----------------------------------------------------------
# Number of locations in each direction. This is the total region of interest
# where some sites may or may not have a data source.
J.x <- 15
J.y <- 15
J.all <- J.x * J.y
# Number of data sources.
n.data <- 3
# Sites for each data source.
J.obs <- sample(ceiling(0.2 * J.all):ceiling(0.4 * J.all), n.data, replace = TRUE)
# Maximum number of years for each data set
n.time.max <- c(4, 8, 10)
# Number of years each site in each data set is sampled
n.time <- list()
for (i in 1:n.data) {
n.time[[i]] <- sample(1:n.time.max[i], J.obs[i], replace = TRUE)
}
# Replicates for each data source.
n.rep <- list()
for (i in 1:n.data) {
n.rep[[i]] <- matrix(NA, J.obs[i], n.time.max[i])
for (j in 1:J.obs[i]) {
n.rep[[i]][j, sample(1:n.time.max[i], n.time[[i]][j], replace = FALSE)] <-
sample(1:4, n.time[[i]][j], replace = TRUE)
}
}
# Total number of years across all data sets
n.time.total <- 10
# List denoting the specific years each data set was sampled during.
data.seasons <- list()
for (i in 1:n.data) {
data.seasons[[i]] <- sort(sample(1:n.time.total, n.time.max[i], replace = FALSE))
}
# Occupancy covariates
beta <- c(0, 0.4, 0.3)
trend <- TRUE
# Random occupancy covariates
psi.RE <- list()
p.occ <- length(beta)
# Detection covariates
alpha <- list()
alpha[[1]] <- c(0, 0.2, -0.5)
alpha[[2]] <- c(-1, 0.5, 0.3, -0.8)
alpha[[3]] <- c(-0.5, 1)
p.RE <- list()
p.det.long <- sapply(alpha, length)
p.det <- sum(p.det.long)
# Spatial parameters
svc.cols <- c(1, 2)
sigma.sq <- c(0.9, 0.5)
phi <- c(3 / .5, 3 / .8)
# Simulate occupancy data.
dat <- simTIntOcc(n.data = n.data, J.x = J.x, J.y = J.y, J.obs = J.obs,
n.time = n.time, data.seasons = data.seasons, n.rep = n.rep,
beta = beta, alpha = alpha, trend = trend,
psi.RE = psi.RE, p.RE = p.RE, sp = TRUE,
sigma.sq = sigma.sq, phi = phi, cov.model = 'exponential',
svc.cols = svc.cols)
y <- dat$y
X <- dat$X.obs
X.p <- dat$X.p
sites <- dat$sites
coords <- dat$coords.obs
# Package all data into a list
occ.covs <- list(trend = X[, , 2],
occ.cov.1 = X[, , 3])
det.covs <- list()
# Add covariates one by one
det.covs[[1]] <- list(det.cov.1.1 = X.p[[1]][, , , 2],
det.cov.1.2 = X.p[[1]][, , , 3])
det.covs[[2]] <- list(det.cov.2.1 = X.p[[2]][, , , 2],
det.cov.2.2 = X.p[[2]][, , , 3],
det.cov.2.3 = X.p[[2]][, , , 4])
det.covs[[3]] <- list(det.cov.3.1 = X.p[[3]][, , , 2])
data.list <- list(y = y, occ.covs = occ.covs, det.covs = det.covs,
sites = sites, seasons = data.seasons, coords = coords)
# Testing
occ.formula <- ~ trend + occ.cov.1
# Note that the names are not necessary.
det.formula <- list(f.1 = ~ det.cov.1.1 + det.cov.1.2,
f.2 = ~ det.cov.2.1 + det.cov.2.2 + det.cov.2.3,
f.3 = ~ det.cov.3.1)
# NOTE: this is a short run of the model, in reality we would run the
# model for much longer.
out <- svcTIntPGOcc(occ.formula = occ.formula,
det.formula = det.formula,
data = data.list,
NNGP = TRUE,
n.neighbors = 15,
cov.model = 'exponential',
n.batch = 3,
svc.cols = c(1, 2),
batch.length = 25,
n.report = 1,
n.burn = 25,
n.thin = 1,
n.chains = 1)
summary(out)
t.cols <- 1:n.time.total
out.pred <- predict(out, X.0 = dat$X.pred, coords.0 = dat$coords.pred,
t.cols = t.cols, type = 'occupancy')
str(out.pred)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.