Skip to contents

Compute negative log-likelihood for EcoState model

Usage

compute_nll(
  p,
  taxa,
  years,
  noB_i,
  type_i,
  n_species,
  project_vars,
  Bobs_ti,
  Cobs_ti,
  Nobs_ta_g2,
  Wobs_ta_g2,
  log_prior,
  fit_eps,
  fit_nu,
  sem,
  stanza_data,
  settings,
  control,
  simulate_data = FALSE,
  simulate_random = FALSE
)

Arguments

p

list of parameters

taxa

Character vector of taxa included in model.

years

Integer-vector of years included in model

noB_i

Boolean vector indicating which taxa have no B value

type_i

character vector indicating whether a taxon is "hetero", "auto", or "detritus"

n_species

number of species

project_vars

function to integrate differential equation

Bobs_ti

formatted matrix of biomass data

Cobs_ti

formatted matrix of catch data

Nobs_ta_g2

formatted list of age-comp data

Wobs_ta_g2

formatted list of weight-at-age data

log_prior

A list of sampling statements representing parameter priors, or a user-provided function that takes as input the list of parameters out$obj$env$parList() where out is the output from ecostate(), and returns a numeric vector where the sum is the log-prior probability. For example log_prior = function(p) dnorm( p$logq_i[1], mean=0, sd=0.1, log=TRUE) specifies a lognormal prior probability for the catchability coefficient for the first taxa with logmean of zero and logsd of 0.1. See evaluate_prior for details.

fit_eps

Character-vector listing taxa for which the model should estimate annual process errors in dB/dt

fit_nu

Character-vector listing taxa for which the model should estimate annual process errors in consumption Q_ij

sem

Optional specification for time-series structural equation model structure including lagged or simultaneous effects. Process errors for biomass, consumption, and recruitment can be included for a given taxa by prefixing taxa names for "eps_", "nu_", and "phi_", respectively. E.g., to specify an autoregressive process on biomass errors for a taxon named "i", we can specify a path eps_i -> eps_i, 1, rho_i, 0 where 1 indicates a lagged effect, rho_i is a user-provided parameter name, and 0 is a starting value. See make_dsem_ram for an introduction to DSEM path notation. make_dsem_ram for introduction to DSEM path notation.

stanza_data

output from make_stanza_data

settings

Output from stanza_settings(), used to define age-structured dynamics (called stanza-groups).

control

output from ecostate_control

simulate_data

Whether to simulate new data instead of computing the objective function, as used in the ecostate simulator routine

simulate_random

Whether to simulate new values of random effects. Only applies when simulate_data==TRUE

Value

The joint negative log-likelihood including contribution of priors and fit to data.

Details

Given a list of parameters, calculates the joint negative log-likelihood, where the Laplace approximation is then used to marginalize across random effects to calculate the log-marginal likelihood of fixed effects. The joint likelihood includes the fit to fishery catches, biomass indices, age-composition data, weight-at-age data, priors, and the distribution for random effects.