updatePrior: Update priors in 'bdm' model

View source: R/updatePrior.R

updatePriorR Documentation

Update priors in bdm model

Description

This function can be used to update the priors for r and ln(K).

Usage

updatePrior(object, ...)

## S3 method for class 'bdm'
updatePrior(object, prior, ...)

Arguments

object

a bdm class object

...

additional arguments to generic function

prior

a prior class object or a list object containing information to update the prior

Details

The bdm package by default assumes that the prior on r is log-normal and the prior for ln(K) is uniform. If the function is supplied with a prior class object then it will extract the log-normal distribution parameters for r and use regular expression matching to update the model code. If the function is provided with a named list then it can be used to update the priors for r, ln(K) or the initial depletion x0, in a similar manner. See the examples for how the list arguments are specified.

By default this function only updates the model code. The model will need to be re-compiled before it is run for the changes to take effect.

Value

Returns a bdm object with updated model code.

Examples

# initialise default model
mdl <- bdm()

# update prior for r
mdl <- updatePrior(mdl, list(par = 'r', meanlog = -1.1, sdlog = 0.1))

# update prior for logK
mdl <- updatePrior(mdl, list(par = 'logK', min = 1, max = 100))

# update prior for initial depletion
mdl <- updatePrior(mdl, list(par = 'x0', meanlog = log(0.8), sdlog = 0.01))

# check updates
getr(mdl)
getlogK(mdl)

# update using a prior class
# object
library(lhm)

# create object containing
# vector of r values
iter <- 100
mu <- 0.1
cv <- 0.2
sd <- sqrt(log(1+cv^2))
x <- rlnorm(iter,log(mu)-sd^2/2,sd)
r <- prior(x)

# update model
mdl <- updatePrior(mdl, r)

# check update
mean(log(r))
getr(mdl)[['E[log(r)]']]


cttedwards/bdm documentation built on Oct. 11, 2022, 7:52 p.m.