Description Usage Arguments Details Value Note Author(s) Examples
Compile an ADMB model, run it, collect output
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | do_admb(fn, data, params,
bounds=NULL,
phase=NULL,
re = NULL,
data_type = NULL,
safe = TRUE,
profile = FALSE,
profpars = NULL,
mcmc = FALSE,
mcmc.opts = mcmc.control(),
impsamp = FALSE,
verbose=FALSE,
run.opts=run.control(),
objfunname="f",
workdir=getwd(),
admb_errors=c("stop","warn","ignore"),
extra.args)
|
fn |
(character) base name of a TPL function, located in the working directory |
data |
a list of input data variables (order must match TPL file) |
params |
a list of starting parameter values (order must match TPL file) |
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. |
safe |
(logical) compile in safe mode? |
profile |
(logical) generate likelihood profiles? (untested!) |
profpars |
(character) vector of names of parameters to profile |
mcmc |
(logical) run MCMC around best fit? |
mcmc.opts |
options for MCMC (see
|
impsamp |
(logical) run importance sampling? |
verbose |
(logical) print details |
run.opts |
options for ADMB run (see
|
objfunname |
(character) name for objective function in TPL file
(only relevant if |
workdir |
temporary working directory (dat/pin/tpl files will be copied) |
admb_errors |
how to treat ADMB errors (in either compilation or run): use at your own risk! |
extra.args |
(character) extra argument string to pass to admb |
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.
An object of class admb
.
1. Mixed-case file names are ignored by ADMB; this function makes a temporary copy with the file name translated to lower case. 2. Parameter names containing periods/full stops will not work, because this violates C syntax (currently not checked). 3. There are many, many, implicit restrictions and assumptions: for example, all vectors and matrices are assumed to be indexed starting from 1.
Ben Bolker
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | ## Not run:
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"))
unlink("tadpole.tpl")
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.