aab_env {gadget3}R Documentation

Gadget3 global environment

Description

Functions available to any gadget3 model

Details

g3_env is the top-level environment that any gadget3 model uses, populated with utility functions.

NB: Several functions have _vec variants. Due to TMB limitations these should be used when you have a vector not scalar input.

ADREPORT

TMB's ADREPORT function. See sdreport documentation

as_integer

C++ compatible equivalent to as.integer

as.numeric

R as.numeric or TMB asDouble

assert_msg

C++/R function that ensures expression is true, or stops model.

assert_msg(x > 0, "x must be positive")

avoid_zero / avoid_zero_vec

Adds small value to input to ensure output is never zero

bounded / bounded_vec

Ensures x is within limits a & b.

bounded_vec(x, 100, 1000)

g3_matrix_vec

Apply matrix transformation tf to vector vec, return resultant vector.

g3_matrix_vec(tf, vec)

lgamma_vec

Vector equivalent of lgamma

logspace_add / logspace_add_vec

TMB's logspace_add, essentially a differentiable version of pmax.

normalize_vec

Divide vector a by it's sum, i.e. so it now sums to 1

nvl

Return first non-null argument. NB: No C++ implementation.

pow_vec

Vector equivalent of ^

print_array

Utility to pretty-print array ar

ratio_add_vec

Sum orig_vec & new_vec according to ratio of orig_amount & new_amount

REPORT

TMB's REPORT function.

REprintf

Equivalent of RCpp REprintf

Rprintf

Equivalent of RCpp Rprintf

Examples

# Call g3's avoid_zero_vec directly from R
g3_env$avoid_zero_vec(c(0, 0.001, 1, 100))

[Package gadget3 version 0.11-1 Index]