sem_psm_predict: Posterior Predictive Distribution of PSM Risk

Description Usage Arguments Details Value

View source: R/sem_psm_predict.R

Description

Compute the posterior predictive distribution of PSM risk from a fitted SEM, possibly conditioned on specified values of the latent factor(s).

Usage

1
2
3
4
5
6
7
8
9
sem_psm_predict(
  fit,
  data,
  newsites = NULL,
  newZ = NULL,
  level = "site",
  transform = FALSE,
  gradient = FALSE
)

Arguments

fit

Object of class stanfit representing a fitted PSM SEM. Parameters mu_b0, sigma_b0, b0_std, and b0_Z must be monitored.

data

The data list passed to rstan::sampling() to estimate fit, as returned by SEMPSM::stan_data().

newsites

Optional numeric vector of length N_new giving the site numbers (coded as in data) for which predictions are to be made. If newsites is not specified, the default is to use all sites in data.

newZ

Optional matrix of dimension N_new x L giving the L factor scores for each new prediction. If NULL, the posterior samples of site-specific factor scores are used.

level

Level of grouping at which to predict. Options are "site" (site-specific interannual average, the default) or "year" (include year-within-site residual variation).

transform

Logical indicating whether to return the linear predictor (FALSE, the default) or inverse-logit transform it.

gradient

Logical indicating whether to compute the gradient of PSM risk with respect to the latent factor(s).

Details

Currently predictions can only be made for sites (with or without PSM data) used to fit the model, and for sample-average precipitation conditions (i.e., precipitation effects are set to zero). These restrictions will be lifted in a later version.

Value

List with elements

est

An iter x N_new matrix containing posterior samples of the predicted probability (or the linear predictor of logit probability, if transform == FALSE) of PSM.

gradient

An iter x N_new x L array whose [,,l] panel contains posterior samples of the gradient of PSM with respect to the l-th factor, evaluated at newZ.


ebuhle/SEMPSM documentation built on Aug. 8, 2020, 4:05 a.m.