Learn R Programming

R2admb (version 0.7.10)

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)

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
  • value
{the value of the data} data_type{character: possible va

Value

  • An object of class admb.

item

  • params
  • bounds
  • phase
  • re
  • data_type
  • safe
  • profile
  • profile.opts
  • mcmc
  • mcmc.opts
  • impsamp
  • verbose
  • run.opts
  • objfunname
  • workdir
  • admb_errors
  • extra.args

describe

  • valuestarting value of the parameter (default 0)
  • boundstwo-element vector of lower and upper bounds
  • phaseinteger, specifying phase: not implemented yet

code

checkparam

itemize

  • pars

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
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