Title: | Interface to 'LibBi' |
---|---|
Description: | Provides a complete interface to 'LibBi', a library for Bayesian inference (see <https://libbi.org> and Murray, 2015 <doi:10.18637/jss.v067.i10> for more information). This includes functions for manipulating 'LibBi' models, for reading and writing 'LibBi' input/output files, for converting 'LibBi' output to provide traces for use with the coda package, and for running 'LibBi' to conduct inference. |
Authors: | Pierre E. Jacob [aut], Anthony Lee [ctb], Lawrence M. Murray [ctb], Sebastian Funk [aut, cre], Sam Abbott [ctb] |
Maintainer: | Sebastian Funk <[email protected]> |
License: | GPL-3 |
Version: | 1.0.0 |
Built: | 2024-10-31 21:24:19 UTC |
Source: | https://github.com/sbfnk/RBi |
Add a block to a LibBi model. If that block exists, it will be removed first.
## S3 method for class 'bi_model' add_block(x, name, lines, options, ...)
## S3 method for class 'bi_model' add_block(x, name, lines, options, ...)
x |
a |
name |
name of the block |
lines |
character vector, lines in the block |
options |
any options to the block |
... |
ignored |
a bi_model
object containing the new block
libbi
objectAdds an (output, obs, etc.) file to a libbi
object. This is
useful to recreate a libbi
object from the model and output
files of a previous run
The bi_write
options append
and overwrite
determine what exactly the file will contain at the end of this. If they
are both FALSE (the default), any existing file will be ignored. If
append
is TRUE, the existing data in the file will be preserved, and
any data set passed as data
and not already in the file will be
added. If overwrite
is TRUE, existing data in the file will be
preserved except for variables that exist in the passed data
.
## S3 method for class 'libbi' attach_data( x, file, data, in_place = FALSE, append = FALSE, overwrite = FALSE, quiet = FALSE, time_dim = character(0), coord_dims = list(), ... )
## S3 method for class 'libbi' attach_data( x, file, data, in_place = FALSE, append = FALSE, overwrite = FALSE, quiet = FALSE, time_dim = character(0), coord_dims = list(), ... )
x |
a |
file |
the type of the file to attach, one of "output", "obs", "input" or "init" |
data |
name of the file to attach, or a list of data frames that contain the outputs; it will be assumed that this is already thinned |
in_place |
if TRUE, replace the file in place if it already exists in
the libbi object; this can speed up the operation if append=TRUE as
otherwise the file will have to be read and used again; it should be used
with care, though, as it can render existing |
append |
if TRUE, will append variables if file exists; default: FALSE |
overwrite |
if TRUE, will overwrite variables if file exists; default: FALSE |
quiet |
if TRUE, will suppress the warning message normally given if replace=TRUE and the file exists already |
time_dim |
the name of the time dimension, if one exists; default: "time" |
coord_dims |
the names of the coordinate dimension, if any; should be a named list of character vectors, they are matched to variables names |
... |
any options to |
an updated libbi
object
bi <- libbi(model = system.file(package = "rbi", "PZ.bi")) example_output <- bi_read(system.file(package = "rbi", "example_output.nc")) bi <- attach_data(bi, "output", example_output)
bi <- libbi(model = system.file(package = "rbi", "PZ.bi")) example_output <- bi_read(system.file(package = "rbi", "example_output.nc")) bi <- attach_data(bi, "output", example_output)
This function gets the name of all the variables in the passed file, list or
libbi
object
bi_contents(read, ...)
bi_contents(read, ...)
read |
either a path to a NetCDF file, or a NetCDF connection created
using |
... |
any parameters for |
character vector of variable names
example_output_file <- system.file(package = "rbi", "example_output.nc") bi_contents(example_output_file)
example_output_file <- system.file(package = "rbi", "example_output.nc") bi_contents(example_output_file)
This function prints a little summary of the content
of a NetCDF file, as well as its creation time. You can
then retrieve variables of interest using bi_read
.
bi_file_summary(...)
bi_file_summary(...)
... |
Any extra parameters to |
No return value
example_output_file <- system.file(package = "rbi", "example_output.nc") bi_file_summary(example_output_file)
example_output_file <- system.file(package = "rbi", "example_output.nc") bi_file_summary(example_output_file)
This function is deprecated and has been renamed to
generate_dataset
bi_generate_dataset(..., output_every = 1)
bi_generate_dataset(..., output_every = 1)
... |
arguments to be passed to |
output_every |
real; if given, |
a libbi
object, the generated data set
bi_model
creates a model object for Rbi
from a libbi file, URL
or character vector. Once the instance is created, the model can be fed to
a libbi
object.
bi_model(filename, lines, ...)
bi_model(filename, lines, ...)
filename |
the file name of the model file |
lines |
lines of the model (if no |
... |
ignored |
a {bi_model}
object containing the newly created model
fix
, insert_lines
,
remove_lines
, replace_all
,
get_name
, set_name
, write_model
model_file_name <- system.file(package = "rbi", "PZ.bi") PZ <- bi_model(filename = model_file_name)
model_file_name <- system.file(package = "rbi", "PZ.bi") PZ <- bi_model(filename = model_file_name)
This function reads all variable from a NetCDF file or the output of a
libbi
object.
The file can be specified as a string to the filepath, in which
case a NetCDF connection is opened, or directly as a NetCDF connection.
bi_read( x, vars, dims, model, type, file, missval_threshold, coord_dims = list(), thin, verbose = FALSE, clear_cache = FALSE, init_to_param = FALSE, burn = 0 )
bi_read( x, vars, dims, model, type, file, missval_threshold, coord_dims = list(), thin, verbose = FALSE, clear_cache = FALSE, init_to_param = FALSE, burn = 0 )
x |
either a path to a NetCDF file, or a NetCDF connection created using
|
vars |
variables to read; if not given, all will be read |
dims |
factors for dimensions |
model |
model file or a |
type |
vector of types of variable to read (out of "param", "state",
"noise", "obs"). This needs 'x' to be a |
file |
which file to read (if |
missval_threshold |
upper threshold for the likelihood |
coord_dims |
any |
thin |
thinning (keep only 1/thin of samples) |
verbose |
if TRUE, will print variables as they are read |
clear_cache |
if TRUE, will clear the cache and re-read the file even if cached data exists |
init_to_param |
logical; if TRUE, convert states to initial values |
burn |
number of initial samples to discard; default: 0 |
a list of data frames and/or numbers that have been read
example_output_file <- system.file(package = "rbi", "example_output.nc") d <- bi_read(example_output_file)
example_output_file <- system.file(package = "rbi", "example_output.nc") d <- bi_read(example_output_file)
This function creates (or appends to) a NetCDF file for LibBi from the given
list of vectors and/or data frames. Since any files can be passed to
libbi
directly via the init
, input
and
obs
options, this is mostly used internally, this is mostly used
internally.
bi_write( filename, variables, append = FALSE, overwrite = FALSE, time_dim, coord_dims, dim_factors, value_column = "value", guess_time = FALSE, verbose )
bi_write( filename, variables, append = FALSE, overwrite = FALSE, time_dim, coord_dims, dim_factors, value_column = "value", guess_time = FALSE, verbose )
filename |
a path to a NetCDF file to write the variables into, which will be overwritten if it already exists. If necessary, ".nc" will be added to the file name |
variables |
a |
append |
if TRUE, will append variables if file exists; default: FALSE |
overwrite |
if TRUE, will overwrite variables if file exists; default: FALSE |
time_dim |
the name of the time dimension, if one exists; default: "time" |
coord_dims |
the names of the coordinate dimension, if any; should be a named list of character vectors, they are matched to variables names |
dim_factors |
factors that dimensions have; this corresponds to the
|
value_column |
if any |
guess_time |
whether to guess time dimension; this would be a numerical
column in the data frame given which is not the |
verbose |
if TRUE, will print variables as they are read |
The list of variables must follow the following rules. Each element of the list must itself be one of:
1) a data frame with a value_column
column (see option 'value_column')
and any number of other columns indicating one or more dimensions
2) a numeric vector of length one, with no dimensions
The name of the list elements itself is used to create the corresponding variable in the NetCDF file.
A list of the time and coord dims, and factors in extra dimensions, if any
filename <- tempfile(pattern = "dummy", fileext = ".nc") a <- 3 b <- data.frame( dim_a = rep(1:3, time = 2), dim_b = rep(1:2, each = 3), value = 1:6 ) variables <- list(a = a, b = b) bi_write(filename, variables) bi_file_summary(filename)
filename <- tempfile(pattern = "dummy", fileext = ".nc") a <- 3 b <- data.frame( dim_a = rep(1:3, time = 2), dim_b = rep(1:2, each = 3), value = 1:6 ) variables <- list(a = a, b = b) bi_write(filename, variables) bi_file_summary(filename)
bi_model
Any variable type given will have any 'has_output=0' option removed in the given model.
enable_outputs(x, type = "all")
enable_outputs(x, type = "all")
x |
a |
type |
either "all" (default), or a vector of variable types that are to have outputs enabled |
the updated bi_model
object
model_file_name <- system.file(package = "rbi", "PZ.bi") PZ <- bi_model(filename = model_file_name) PZ[6] <- "param mu (has_output=0)" PZ <- enable_outputs(PZ)
model_file_name <- system.file(package = "rbi", "PZ.bi") PZ <- bi_model(filename = model_file_name) PZ[6] <- "param mu (has_output=0)" PZ <- enable_outputs(PZ)
Ignores differences in the model name.
## S3 method for class 'bi_model' e1 == e2, ...
## S3 method for class 'bi_model' e1 == e2, ...
e1 |
a |
e2 |
a |
... |
ignored |
TRUE or FALSE, depending on whether the models are equal or not
model_file_name <- system.file(package = "rbi", "PZ.bi") PZ <- bi_model(filename = model_file_name) PZ == PZ # TRUE
model_file_name <- system.file(package = "rbi", "PZ.bi") PZ <- bi_model(filename = model_file_name) PZ == PZ # TRUE
Extracts a subset of lines from the model and assigns new character strings.
## S3 replacement method for class 'bi_model' x[i, ...] <- value
## S3 replacement method for class 'bi_model' x[i, ...] <- value
x |
A bi_model |
i |
A vector of line numbers |
... |
ignored |
value |
A vector of the same length as |
the updated bi_model
object
model_file_name <- system.file(package = "rbi", "PZ.bi") PZ <- bi_model(filename = model_file_name) PZ[3:4] <- c("const e = 0.4", "const m_l = 0.05")
model_file_name <- system.file(package = "rbi", "PZ.bi") PZ <- bi_model(filename = model_file_name) PZ[3:4] <- c("const e = 0.4", "const m_l = 0.05")
LibBi
run.This function takes the provided libbi
results and extracts a data frame.
extract_sample(x, np, ...)
extract_sample(x, np, ...)
x |
a |
np |
iteration to extract; if set to "last", the last sample will be extracted. If not given a random sample will be extracted |
... |
parameters to |
a list of data frames or numeric vectors containing parameters and trajectories
Extracts a subset of lines from the model.
## S3 method for class 'bi_model' x[i, ...]
## S3 method for class 'bi_model' x[i, ...]
x |
A bi_model |
i |
A vector of line numbers |
... |
ignored |
a character string of the extracted model lines(s)
model_file_name <- system.file(package = "rbi", "PZ.bi") PZ <- bi_model(filename = model_file_name) PZ[3:4]
model_file_name <- system.file(package = "rbi", "PZ.bi") PZ <- bi_model(filename = model_file_name) PZ[3:4]
The method filter
launches libbi
to filter state trajectories.
See the options to run.libbi
for how to specify the various
components of sampling with LibBi, and the LibBi manual for all options
that can be passed when the client is filter
.
If x
is given as a 'bi_model', a libbi
object will be
created from the model For the help page of the base R filter
function, see filter
.
## S3 method for class 'libbi' filter(x, ...) ## S3 method for class 'bi_model' filter(x, ...)
## S3 method for class 'libbi' filter(x, ...) ## S3 method for class 'bi_model' filter(x, ...)
x |
a |
... |
options to be passed to |
an updated libbi
object
Replaces all variables with fixed values as given ; note that this will not replace differential equations and lead to an error if applied to states that are changed inside an "ode" block
For the help page of the base R fix
function, see
fix
.
## S3 method for class 'bi_model' fix(x, ...)
## S3 method for class 'bi_model' fix(x, ...)
x |
a |
... |
values to be assigned to the (named) variables |
the updated bi_model
object
model_file_name <- system.file(package = "rbi", "PZ.bi") PZ <- bi_model(filename = model_file_name) PZ <- fix(PZ, alpha = 0)
model_file_name <- system.file(package = "rbi", "PZ.bi") PZ <- bi_model(filename = model_file_name) PZ <- fix(PZ, alpha = 0)
bi_read
) and converts it to a flat data frameFlatten list of data frames
This function takes a list of data frames (such as, for example, returned by
bi_read
) and converts it to a flat data frame
flatten(x)
flatten(x)
x |
The list of data frames |
a data frame containing the flattened data
This is a wrapper around libbi sample --target joint
--nsamples 1
, to generate a synthetic dataset from a model. Parameters can
be passed via the 'init' option (see run.libbi
, otherwise
they are generated from the prior specified in the model. The end time
should be specified using the "end_time" option. If this is not given, only
a parameter set is sampled. Use the 'noutputs' or 'output_every' options to
control the number of data points being generated. By default, output_every
is set to 1.
generate_dataset(..., output_every = 1)
generate_dataset(..., output_every = 1)
... |
arguments to be passed to |
output_every |
real; if given, |
a libbi
object, the generated data set
Returns the contents of a block in a LibBi model as a character vector of lines.
## S3 method for class 'bi_model' get_block(x, name, shell = FALSE, ...)
## S3 method for class 'bi_model' get_block(x, name, shell = FALSE, ...)
x |
a |
name |
name of the block |
shell |
if TRUE (default:FALSE), will return the shell (i.e., the
definition of the block) as well as content; this is useful, e.g., to see
options passed to a |
... |
ignored |
a character vector of the lines in the block
Get constants contained in a LibBi model and their values. This will attempt to evaluate any calculation on the right hand side. Failing that, it will be returned verbatim.
get_const(model)
get_const(model)
model |
a |
a list of constants (as names) and their values
Get dimensions contained in a LibBi model and their sizes
get_dims(model, type)
get_dims(model, type)
model |
a |
type |
a character vector of one or more types |
a list of dimensions (as names) and their sizes
Extracts the name of a bi model (first line of the .bi file).
## S3 method for class 'bi_model' get_name(x, ...)
## S3 method for class 'bi_model' get_name(x, ...)
x |
a |
... |
ignored |
a character string, the name of the model
model_file_name <- system.file(package = "rbi", "PZ.bi") PZ <- bi_model(filename = model_file_name) get_name(PZ)
model_file_name <- system.file(package = "rbi", "PZ.bi") PZ <- bi_model(filename = model_file_name) get_name(PZ)
This function takes the provided libbi
object
which has been run and returns a data frame with the parameter
traces.
get_traces(x, model, burnin, all = FALSE, ...)
get_traces(x, model, burnin, all = FALSE, ...)
x |
a |
model |
a model to get the parameter names from; not needed if
'run' is given as a |
burnin |
proportion of iterations to discard as burn-in (if between 0 and 1), or number of samples to discard (if >1) |
all |
whether all variables in the run file should be considered (otherwise, just parameters) |
... |
parameters to |
a ata frame with parameter traces; this can be fed to
coda
routines
Inserts one or more lines into a libbi model. If one of before
or
after
is given, the line(s) will be inserted before or after a given
line number or block name, respectively. If one of at_beginning of
or at_end_of
is given, the lines will be inserted at the
beginning/end of the block, respectively.
## S3 method for class 'bi_model' insert_lines(x, lines, before, after, at_beginning_of, at_end_of, ...)
## S3 method for class 'bi_model' insert_lines(x, lines, before, after, at_beginning_of, at_end_of, ...)
x |
a |
lines |
vector or line(s) |
before |
line number before which to insert line(s) |
after |
line number after which to insert line(s) |
at_beginning_of |
block at the beginning of which to insert lines(s) |
at_end_of |
block at the end of which to insert lines(s) |
... |
ignored |
the updated bi_model
object
model_file_name <- system.file(package = "rbi", "PZ.bi") PZ <- bi_model(filename = model_file_name) PZ <- insert_lines(PZ, lines = "noise beta", after = 8)
model_file_name <- system.file(package = "rbi", "PZ.bi") PZ <- bi_model(filename = model_file_name) PZ <- insert_lines(PZ, lines = "noise beta", after = 8)
libbi
objectsThis function can be used to join multiple libbi
objects into
one (e.g., parallel MCMC runs into one long change)
## S3 method for class 'libbi' join(x, ...)
## S3 method for class 'libbi' join(x, ...)
x |
a |
... |
ignored |
an joined libbi
object
libbi
allows to call LibBi
.
Upon creating a new libbi object, the following arguments can be given.
Once the instance is created, LibBi
can be run through the
sample
, filter
, or
optimise
, or rewrite
methods. Note that
libbi
objects can be plotted using plot
if the
rbi.helpers
package is loaded.
libbi(model, path_to_libbi, dims, use_cache = TRUE, ...)
libbi(model, path_to_libbi, dims, use_cache = TRUE, ...)
model |
either a character vector giving the path to a model file
(typically ending in ".bi"), or a |
path_to_libbi |
path to |
dims |
any named dimensions, as list of character vectors |
use_cache |
logical; whether to use the cache (default: true) |
... |
options passed to |
a new libbi
object
sample
, filter
, optimise
,
rewrite
bi_object <- libbi(model = system.file(package = "rbi", "PZ.bi"))
bi_object <- libbi(model = system.file(package = "rbi", "PZ.bi"))
The method logLik
extracts the log-likelihood of a libbi
object. This can be done, for example, after a call to
sample
to inspect the chain log-likelihoods.
For the help page of the base R logLik
function, see
logLik
.
## S3 method for class 'libbi' logLik(object, ...)
## S3 method for class 'libbi' logLik(object, ...)
object |
a |
... |
options to be passed to |
a vector of log-likelihood
The method optimise
launches libbi
to optimise the parameters
with respect to the likelihood or posterior distribution. See the options
to run.libbi
for how to specify the various components of
sampling with LibBi, and the LibBi manual for all options that can be
passed when the client is optimise
.
If x
is given as a 'bi_model', a libbi
object will be
created from the model For the help page of the base R optimise
function, see optimise
.
## S3 method for class 'libbi' optimise(x, ...) ## S3 method for class 'bi_model' optimise(x, ...)
## S3 method for class 'libbi' optimise(x, ...) ## S3 method for class 'bi_model' optimise(x, ...)
x |
a |
... |
options to be passed to |
an updated libbi
object
The method predict
is an alias for sample(target="prediction")
.
Usually, an init
object or file should be given containing posterior
samples.
For the help page of the base R optimise
function, see
optimise
.
## S3 method for class 'libbi' predict(x, ...)
## S3 method for class 'libbi' predict(x, ...)
x |
a |
... |
any arguments to be passed to |
an updated libbi
object
libbi
objectThis is useful for diagnosis after a libbi
run
print_log(x)
print_log(x)
x |
nothing (invisible NULL)
LibBi
run from an RDS file or from a folder.
This completely reconstructs the saved LibBi
objectThis reads all options, files and outputs of a LibBi
run from a
specified RDS file or folder (if split = TRUE
has been used with
save_libbi
).
read_libbi(name, ...)
read_libbi(name, ...)
name |
name of the RDS file(s) to read |
... |
any extra options to pass to |
a new libbi
object
Removes one or more lines in a libbi model.
## S3 method for class 'bi_model' remove_lines( x, what, only, type = c("all", "assignment", "sample"), preserve_shell = FALSE, ... )
## S3 method for class 'bi_model' remove_lines( x, what, only, type = c("all", "assignment", "sample"), preserve_shell = FALSE, ... )
x |
a |
what |
either a vector of line number(s) to remove, or a vector of blocks to remove (e.g., "parameter") |
only |
only remove lines assigning given names (as a vector of character strings) |
type |
which types of lines to remove, either "all", "sample" (i.e., lines with a "~") or "assignment" (lines with a "<-" or "=") (default: "all") |
preserve_shell |
if TRUE (default: FALSE), preserve the definition of a
block even if all lines are removed; this is useful to preserve options
passed to a |
... |
ignored |
the updated bi_model
object
model_file_name <- system.file(package = "rbi", "PZ.bi") PZ <- bi_model(filename = model_file_name) PZ <- remove_lines(PZ, 2)
model_file_name <- system.file(package = "rbi", "PZ.bi") PZ <- bi_model(filename = model_file_name) PZ <- remove_lines(PZ, 2)
Removes variables from the left-hand side of a model
remove_vars(x, vars)
remove_vars(x, vars)
x |
a |
vars |
vector of variables to remove |
a bi model object of the new model
the updated bi_model
object
Takes every occurrence of one string and replaces it with another
## S3 method for class 'bi_model' replace_all(x, from, to, ...)
## S3 method for class 'bi_model' replace_all(x, from, to, ...)
x |
a |
from |
string to be replaced (a regular expression) |
to |
new string (which can refer to the regular expression given as
|
... |
ignored |
the updated bi_model
object
The method rewrite
launches LibBi
to rewrite a model to inspect
its internal representation in LibBi
If x
is given as a 'bi_model', a libbi
object will be
created from the model
## S3 method for class 'libbi' rewrite(x, ...) ## S3 method for class 'bi_model' rewrite(x, ...)
## S3 method for class 'libbi' rewrite(x, ...) ## S3 method for class 'bi_model' rewrite(x, ...)
x |
a |
... |
options to be passed to |
a re-written bi_model
object
The method run
launches LibBi
with a particular set of command
line arguments. Normally, this function would not be run by the user,
but instead one of the client functions sample
,
filter
, or optimise
, or rewrite
,
which pass any options on to run
. Note that any options specified
here are stored in the libbi
object and do not have to be
specified again if another command is run on the object.
## S3 method for class 'libbi' run( x, client, proposal = c("model", "prior"), model, fix, config, log_file_name = character(0), init, input, obs, time_dim = character(0), coord_dims = list(), thin, output_every, chain = TRUE, seed = TRUE, debug = FALSE, ... )
## S3 method for class 'libbi' run( x, client, proposal = c("model", "prior"), model, fix, config, log_file_name = character(0), init, input, obs, time_dim = character(0), coord_dims = list(), thin, output_every, chain = TRUE, seed = TRUE, debug = FALSE, ... )
x |
a |
client |
client to pass to LibBi |
proposal |
proposal distribution to use; either "model" (default: proposal distribution in the model) or "prior" (propose from the prior distribution) |
model |
either a character vector giving the path to a model file
(typically ending in ".bi"), or a |
fix |
any variable to fix, as a named vector |
config |
path to a configuration file, containing multiple arguments |
log_file_name |
path to a file to text file to report the output of
|
init |
initialisation of the model, either supplied as a list of values
and/or data frames, or a (netcdf) file name, or a |
input |
input of the model, either supplied as a list of values and/or
data frames, or a (netcdf) file name, or a |
obs |
observations of the model, either supplied as a list of values
and/or data frames, or a (netcdf) file name, or a |
time_dim |
The time dimension in any R objects that have been passed
( |
coord_dims |
The coord dimension(s) in any |
thin |
any thinning of MCMC chains (1 means all will be kept, 2 skips
every other sample etc.); note that |
output_every |
real; if given, |
chain |
logical; if set to TRUE and |
seed |
Either a number (the seed to supply to |
debug |
logical; if TRUE, print more verbose messages and write all variables to the output file, irrespective of their setting of 'has_output' |
... |
list of additional arguments to pass to the call to |
an updated libbi
object, except if client
is
'rewrite', in which case invisible NULL will be returned but the rewritten
model code printed
The method sample
launches libbi
to sample from a (prior,
posterior or joint) distribution. See the options to
run.libbi
for how to specify the various components of
sampling with LibBi, and the LibBi manual for all options that can be
passed when the client is sample
.
If x
is given as a 'bi_model', a libbi
object will be
created from the model For the help page of the base R sample
function, see sample
.
## S3 method for class 'libbi' sample(x, ...) ## S3 method for class 'bi_model' sample(x, ...)
## S3 method for class 'libbi' sample(x, ...) ## S3 method for class 'bi_model' sample(x, ...)
x |
a |
... |
options to be passed to |
an updated libbi
object
Sample observations from a LibBi model that has been run
sample_obs(x, ...)
sample_obs(x, ...)
x |
a |
... |
any options to pass to LibBi |
the original libbi
object with added variables in the
output file for sampled observations
Sebastian Funk
LibBi
run to an RDS fileThis saves all options, files and outputs of a LibBi
run to an RDS
file specified
## S3 method for class 'libbi' save_libbi(x, name, supplement, split = FALSE, ...)
## S3 method for class 'libbi' save_libbi(x, name, supplement, split = FALSE, ...)
x |
a |
name |
name of the RDS file(s) to save to. If |
supplement |
any supplementary data to save |
split |
Logical, defaults to |
... |
any options to |
the return value of saveRDS
, i.e. NULL invisibly
Changes the name of a bi model (first line of the .bi file) to the specified name.
## S3 method for class 'bi_model' set_name(x, name, ...)
## S3 method for class 'bi_model' set_name(x, name, ...)
x |
a |
name |
Name of the model |
... |
ignored |
the updated bi_model
object
model_file_name <- system.file(package = "rbi", "PZ.bi") PZ <- bi_model(filename = model_file_name) PZ <- set_name(PZ, "new_PZ")
model_file_name <- system.file(package = "rbi", "PZ.bi") PZ <- bi_model(filename = model_file_name) PZ <- set_name(PZ, "new_PZ")
The method simulate
launches LibBi
to simulate a model by
passing 'target="joint"' to LibBi
If x
is given as a 'bi_model', a libbi
object will be
created from the model
## S3 method for class 'libbi' simulate(x, ...) ## S3 method for class 'bi_model' simulate(x, ...)
## S3 method for class 'libbi' simulate(x, ...) ## S3 method for class 'bi_model' simulate(x, ...)
x |
a |
... |
options to be passed to |
an updated bi_model
object
libbi
objectThis reads in the output file of the libbi
object (which has
been run before) and prints summary information of parameters
## S3 method for class 'libbi' summary( object, type = c("param", "state", "noise", "obs"), quantiles = c(0.25, 0.75), na.rm = FALSE, ... )
## S3 method for class 'libbi' summary( object, type = c("param", "state", "noise", "obs"), quantiles = c(0.25, 0.75), na.rm = FALSE, ... )
object |
a |
type |
one of "param" (default), "state", "noise" or "obs", the variable type to summarise |
quantiles |
quantiles to calculate (default: quartiles); minimum, median, mean and maximum are always calculated |
na.rm |
logical; if true, any |
... |
ignored |
nothing (invisible NULL)
Ignores differences in the model name.
## S3 method for class 'bi_model' e1 != e2, ...
## S3 method for class 'bi_model' e1 != e2, ...
e1 |
a |
e2 |
a |
... |
ignored |
TRUE or FALSE, depending on whether the models are equal or not
model_file_name <- system.file(package = "rbi", "PZ.bi") PZ <- bi_model(filename = model_file_name) PZ != PZ # FALSE
model_file_name <- system.file(package = "rbi", "PZ.bi") PZ <- bi_model(filename = model_file_name) PZ != PZ # FALSE
This updates all the time stamps in a libbi object; it is useful after (input, output, etc.) files have been changed outside the object itself.
## S3 method for class 'libbi' update(x, ...)
## S3 method for class 'libbi' update(x, ...)
x |
a |
... |
ignored |
a libbi
object with updated timestamps
Get variable names of one or more type(s)
This returns all variable names of a certain type ("param", "state", "obs",
"noise", "const") contained in the model of a libbi
object
var_names(x, vars, type, dim = FALSE, opt = FALSE, aux = FALSE)
var_names(x, vars, type, dim = FALSE, opt = FALSE, aux = FALSE)
x |
a |
vars |
a character vector of variable names; if given, only these variables names will be considered |
type |
a character vector of one or more types |
dim |
logical; if set to TRUE, names will contain dimensions in brackets |
opt |
logical; if set to TRUE, names will contain options (e.g., has_output) |
aux |
logical; if set to TRUE, auxiliary names will be returned |
a character vector ofvariable names
Writes a bi model to a file given by filename
. The extension '.bi'
will be added if necessary.
## S3 method for class 'bi_model' write_model(x, filename, update.name = TRUE, ...) ## S3 method for class 'libbi' write_model(x, filename, ...)
## S3 method for class 'bi_model' write_model(x, filename, update.name = TRUE, ...) ## S3 method for class 'libbi' write_model(x, filename, ...)
x |
|
filename |
name of the file to be written |
update.name |
whether to update the model name with the file name |
... |
ignored |
the return value of the writeLines
call.
model_file_name <- system.file(package = "rbi", "PZ.bi") PZ <- bi_model(filename = model_file_name) new_file_name <- tempfile("PZ", fileext = ".bi") write_model(PZ, new_file_name)
model_file_name <- system.file(package = "rbi", "PZ.bi") PZ <- bi_model(filename = model_file_name) new_file_name <- tempfile("PZ", fileext = ".bi") write_model(PZ, new_file_name)