Learn R Programming

R2admb (version 0.7.16.3)

do_admb: Compile and/or run an ADMB model, collect output

Description

Compile an ADMB model, run it, collect output

Usage

do_admb(fn, data = NULL, params = NULL, bounds = NULL, phase = NULL,
  re = NULL, data_type = NULL, safe = TRUE, profile = NULL,
  profile.opts = NULL, mcmc = NULL, mcmc.opts = mcmc.control(),
  impsamp = FALSE, verbose = FALSE, run.opts = run.control(),
  objfunname = "f", workdir = getwd(), admb_errors = c("stop", "warn",
  "ignore"), extra.args)

Value

An object of class admb.

Arguments

fn

(character) base name of a TPL function, located in the working directory

data

a named list of input data variables (order must match TPL file): each element of the list can either be a single value, or a list containing elements

  • valuethe value of the data

  • data_typecharacter: possible values as in storage.mode, typically "integer" or "numeric": this overrides R2admb's attempts to guess whether variables are supposed to be integers or floats (default NA)

params

a named list of starting parameter values (order must match TPL file): each element of the list can either be a single value, or a list containing elements

value

starting value of the parameter (default 0)

bounds

two-element vector of lower and upper bounds

phase

integer, specifying phase: not implemented yet

bounds

named list of 2-element vectors of lower and upper bounds for specified parameters

phase

named numeric vector of phases (not implemented yet)

re

a named list of the identities and dimensions of any random effects vectors or matrices used in the TPL file

data_type

a named vector specifying (optional) data types for parameters, in parname="storage mode" format (e.g. c(x="integer",y="numeric"))

safe

(logical) compile in safe mode?

profile

(logical) generate likelihood profiles? (untested!)

profile.opts

(list) list of options, including

  • parsvector of names of parameters to profile

mcmc

(logical) run MCMC around best fit?

mcmc.opts

options for MCMC (see mcmc.control for details)

impsamp

(logical) run importance sampling?

verbose

(logical) print details

run.opts

options for ADMB run (see run.control for details)

objfunname

(character) name for objective function in TPL file (only relevant if checkparam is set to "write")

workdir

temporary working directory (dat/pin/tpl files will be copied)

admb_errors

how to treat ADMB errors (in either compilation or run): use "ignore" option at your own risk!

extra.args

(character) extra argument string to pass to admb

Author

Ben Bolker

Details

do_admb will attempt to do everything required to start from the model definition (TPL file) specified by fn, the data list, and the list of input parameters, compile and run (i.e. minimize the objective function of) the model in AD Model Builder, and read the results back into an object of class admb in R. If checkparam or checkdata are set to "write", it will attempt to construct a DATA section, and construct or (augment an existing) PARAMETER section (which may contain definitions of non-input parameters to be used in the model). It copies the input TPL file to a backup (.bak); on finishing, it restores the original TPL file and leaves the auto-generated TPL file in a file called [fn]_gen.tpl.

Examples

Run this code

if (FALSE) {
setup_admb()
file.copy(system.file("tplfiles","ReedfrogSizepred0.tpl",package="R2admb"),"tadpole.tpl")
tadpoledat <-
 data.frame(TBL = rep(c(9,12,21,25,37),each=3),
            Kill = c(0,2,1,3,4,5,0,0,0,0,1,0,0,0,0L),
            nexposed=rep(10,15))
m1 <- do_admb("tadpole",
             data=c(list(nobs=15),tadpoledat),
             params=list(c=0.45,d=13,g=1),
             bounds=list(c=c(0,1),d=c(0,50),g=c(-1,25)),
             run.opts=run.control(checkparam="write",
               checkdata="write",clean="all"))
m2 <- do_admb("tadpole",
             data=c(list(nobs=15),tadpoledat),
             params=list(c=list(0.45,bounds=c(0,1)),
                         d=list(13,bounds=c(0,50)),
                         g=list(1,bounds=c(-1,25))),
             run.opts=run.control(checkparam="write",
               checkdata="write",clean="all"))
unlink("tadpole.tpl")
}

Run the code above in your browser using DataLab