Skip to contents

This function is mostly used internally, but may occasionally be called directly to help diagnose sampling problems or for simulation testing.

Usage

stan_init(
  stan_model = c("IPM_SS_np", "IPM_SSiter_np", "IPM_SS_pp", "IPM_SSiter_pp",
    "IPM_SMS_np", "IPM_SMS_pp", "IPM_SMaS_np", "IPM_LCRchum_pp", "RR_SS_np", "RR_SS_pp"),
  stan_data,
  chains = 1
)

Arguments

stan_model

Character string specifying the salmonIPM model to be fit.

stan_data

Named list of input data for fitting either an IPM or run-reconstruction spawner-recruit model in Stan, as returned by stan_data().

chains

A positive integer specifying the number of Markov chains.

Value

A length-chains list of named lists containing starting values for the primitive parameters and states in the model. Passed to rstan::sampling() as the init argument when fitting salmonIPM models.

Examples

# Simulate data for a multi-population spawner-to-spawner model
set.seed(1234)
N_pop <- 10
N_year <- 20
N <- N_pop*N_year

pars <- list(mu_alpha = 2, sigma_alpha = 0.5, mu_Rmax = 5, sigma_Rmax = 0.5, 
             rho_alphaRmax = 0.3, rho_R = 0.7, sigma_year_R = 0.5, sigma_R = 0.3, 
             tau = 0.5, mu_p = c(0.05, 0.55, 0.4), sigma_pop_p = c(0.1, 0.2), 
             R_pop_p = diag(2), sigma_p = c(0.5, 0.5), R_p = diag(2), S_init_K = 0.7)

fd <- data.frame(pop = rep(1:N_pop, each = N_year), year = rep(1:N_year, N_pop),
                 A = 1, p_HOS = 0, F_rate = rbeta(N,7,3), B_rate = 0,
                 n_age_obs = 50, n_HW_obs = 0)

sim_out <- simIPM(pars = pars, fish_data = fd, N_age = 3, max_age = 5)

# Prepare simulated data for Stan
dat <- stan_data("IPM_SS_pp", fish_data = sim_out$sim_dat)

# Generate inits for 3 chains
inits <- stan_init("IPM_SS_pp", stan_data = dat, chains = 3)