sample_variable: Sample from predictive distribution of a variable

View source: R/sample_variable.R

sample_variableR Documentation

Sample from predictive distribution of a variable

Description

sample_variable samples from the joint distribution of random and fixed effects to approximate the predictive distribution for a variable

Using sample_fixed=TRUE (the default) in sample_variable is similar to using type=3 in simulate_data, while using sample_fixed=TRUE in sample_variable is similar to using type=4 in simulate_data. Sampling fixed effects will sometimes cause numerical under- or overflow (i.e., output values of NA) in cases when variance parameters are estimated imprecisely. In these cases, the multivariate normal approximation being used is a poor representation of the tail probabilities, and results in some samples with implausibly high (or negative) variances, such that the associated random effects then have implausibly high magnitude.

Usage

sample_variable(
  Sdreport,
  Obj,
  variable_name,
  n_samples = 100,
  sample_fixed = TRUE,
  seed = 123456
)

Arguments

Sdreport

TMB output from 'TMB::sdreport(Obj)'

Obj

Fitted TMB object from package 'VAST', i.e., output from 'fit_model(...)$tmb_list$Obj'

variable_name

name of variable available in report using Obj$report() or parameters using Obj$env$parList()

n_samples

number of samples from the joint predictive distribution for fixed and random effects. Default is 100, which is slow.

sample_fixed

whether to sample fixed and random effects, sample_fixed=TRUE as by default, or just sample random effects, sample_fixed=FALSE

seed

integer used to set random-number seed when sampling variables, as passed to set.seed(.)

Examples

## Not run: 
# Run model using selected inputs, but also with getJointPrecision=TRUE
fit = fit_model( ...,
    getJointPrecision=TRUE )

# Run sample_variable
sample = sample_variable( Sdreport=fit$parameter_estimates$SD,
    Obj=fit$tmb_list$Obj, variable_name="D_gct" )

## End(Not run)


James-Thorson/FishStatsUtils documentation built on Feb. 6, 2024, 4:26 a.m.