sem_psm: Fit Structural Equation Model of Pre-Spawning Mortality

Description Usage Arguments Value

View source: R/sem_psm.R

Description

Fit a hierarchical Bayesian structural equation model to data on pre-spawning mortality and landscape and climatic variables using Stan.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
sem_psm(
  psm,
  X,
  normal_indx,
  gamma_indx,
  L = 1,
  fit = NULL,
  I0_Z = 1,
  I_su = 1,
  I_su_Z = 1,
  I_fa = 1,
  I_fa_Z = 1,
  I_fit = rep(1, nrow(psm)),
  I_lpd = rep(1, nrow(psm)),
  pars = c("a0", "A", "Z", "phi", "g_mu_X", "mu_b0", "b0_Z", "sigma_b0", "b0",
    "mu_b_su", "b_su_Z", "sigma_b_su", "b_su", "mu_b_fa", "b_fa_Z", "sigma_b_fa", "b_fa",
    "sigma_psm", "p_psm", "ll_psm"),
  chains = 3,
  iter = 12000,
  warmup = 2000,
  thin = 5,
  ...
)

Arguments

psm

A data frame with rows corresponding to observations, including columns named

site

A factor giving site names.

ppt_su

A numeric variable giving summer precipitation in mm.

ppt_fa

A numeric variable giving fall precipitation in mm.

n

An integer variable giving the number of carcasss sampled.

n_psm

An integer variable giving the number of pre-spawning mortalities in each sample.

X

A matrix with rows corresponding to sites and columns corresponding to landscape variables, to be modeled as either normal- or gamma-distributed.

normal_indx

An integer vector giving indices of columns of X to be modeled as normally distributed.

gamma_indx

An integer vector giving indices of columns of X to be modeled as gamma-distributed.

L

Integer giving the number of latent landscape factors to fit.

fit

Stanfit object as returned by a previous call to SEMPSM::sem_psm(). If not NULL, initial values will be drawn randomly from the posterior samples in fit using SEMPSM::stan_init_cv(); otherwise they will be generated using SEMPSM::stan_init().

I0_Z

Integer (0/1) indicating whether to include main effects of latent landscape factors on pre-spawning mortality risk.

I_su

Integer (0/1) indicating whether to include a main effect of summer precipitation on pre-spawning mortality risk.

I_su_Z

Integer (0/1) indicating whether to include interactions between summer precipitation and latent landscape factors on pre-spawning mortality risk.

I_fa

Integer (0/1) indicating whether to include a main effect of fall precipitation on pre-spawning mortality risk.

I_fa_Z

Integer (0/1) indicating whether to include interactions between fall precipitation and latent landscape factors on pre-spawning mortality risk.

I_fit

Integer vector (0/1) of length nrow(psm) indicating whether each pre-spawning mortality observation should be included in the likelihood. This may be useful for fitting some observations while simulating from the posterior predictive distribution for others.

I_lpd

Integer vector (0/1) of length nrow(psm) indicating whether to evaluate the log posterior predictive density for each observation.

pars

A character vector specifying parameters of interest to be saved.

chains

A positive integer specifying the number of Markov chains.

iter

A positive integer specifying the number of iterations for each chain (including warmup).

warmup

A positive integer specifying the number of warmup (aka burnin) iterations per chain.

thin

A positive integer specifying the period for saving samples.

...

Other arguments to be passed to rstan::sampling().

Value

An object of S4 class rstan::stanfit.


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