Learn R Programming

Bayesian inference for state-space models with R

rbi is an R interface to libbi, a library for Bayesian inference.

It mainly contains:

  • various functions to retrieve and process the results from libbi (which are in NetCDF format)
  • a bi_model class, to manipulate libbi models
  • a libbi wrapper class, to perform Bayesian using libbi inference from within R,

Installation

The easiest way to install the latest stable version of rbi is via CRAN:

install.packages("rbi")

Alternatively, the current development version can be installed using the remotes package

# install.packages("remotes")
library("remotes")
install_github("sbfnk/rbi")

The rbi package has only been tested on GNU/Linux and OS X, but it should mostly work everywhere R works.

If you want to use rbi as a wrapper to LibBi then you need a working version of LibBi. To install LibBi on a Mac, the easiest way is to install Homebrew, followed by (using a command shell, i.e. Terminal or similar):

brew install libbi

On linux, follow the instructions provided with LibBi.

The path to libbi script can be passed as an argument to rbi, otherwise the package tries to find it automatically using the which linux/unix command.

If you just want to process the output from LibBi, then you do not need to have LibBi installed.

Getting started

A good starting point is to look at the included demos:

demo(PZ_generate_dataset) ## generating a data set from a model
demo(PZ_PMMH) ## particle Markov-chain Metropolis-Hastings
demo(PZ_SMC2) ## SMC^2
demo(PZ_filtering) ## filtering

For further information, have a look at the introductory vignette from the link from the rbi CRAN package.

Using coda

LibBi contains the get_traces method which provides an interface to coda.

Other packages

For higher-level methods to interact with LibBi, have a look at rbi.helpers.

Copy Link

Version

Install

install.packages('rbi')

Monthly Downloads

425

Version

1.0.0

License

GPL-3

Issues

Pull Requests

Stars

Forks

Maintainer

Last Published

August 15th, 2023

Functions in rbi (1.0.0)

Unequals.bi_model

Check if two models are unequal
add_block

Add a block to a LibBi model
Equals.bi_model

Check if two models are equal
bi_model

Bi Model
Extract.bi_model

Subset model lines
create_coord_var

Create a coordinate variable
bi_open

Bi Open
create_working_folder

Internal function to create a temporary working folder
bi_contents

Bi contents
get_const

Get constants in a LibBi model
enable_outputs

Enable outputting variables in a bi_model
bi_dim_len

NetCDF dimension length
extract_sample

Extract a sample from a LibBi run.
fix

Fix noise term, state or parameter of a libbi model
remove_vars

Remove variables
replace_all

Replace all instances of a string with another in a model
bi_read

Bi Read
get_dims

Get dimensions in a LibBi model
assert_files

Check that a LibBi wrapper has valid output
flatten

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

Check if a model is empty
bi_write

Create (e.g., init or observation) files for LibBi
join

Join multiple libbi objects
get_name

Get the name of a bi model
get_traces

Get the parameter traces
var_names

Get variable names in a LibBi model
write_model

Writes a bi model to a file.
attach_data

Attach a new file or data set to a libbi object
option_list

Convert string to option list
check_sparse_var

Check if a variable is sparse
predict

Using the LibBi wrapper to predict
clean_model

Strip model code to its bare bones
generate_dataset

Generate Dataset
filter

Using the LibBi wrapper to filter
option_string

Convert Options
get_block

Get the contents of a block in a LibBi model
logLik

Using the LibBi wrapper to logLik
print.bi_model

Print the lines of a LibBi model
find_block

Find a block in a LibBi model
rewrite

Using the LibBi wrapper to rewrite
insert_lines

Insert lines in a LibBi model
bi_file_summary

NetCDF File Summary
installed_libbi_version

Get the LibBi version
run

Using the LibBi wrapper to launch LibBi
read_libbi

Read results of a LibBi run from an RDS file or from a folder. This completely reconstructs the saved LibBi object
optimise

Using the LibBi wrapper to optimise
save_libbi

Write results of a LibBi run to an RDS file
remove_lines

Remove line(s) and/or block(s) in a libbi model
simulate

Using the LibBi wrapper to simulate
set_name

Set the name of a bi model
summary

Print summary information about a libbi object
bi_generate_dataset

Bi Generate Dataset
to_input

Convert variables into inputs
update

Update a libbi object
libbi

LibBi Wrapper
locate_libbi

Find the libbi executable
print_log

Print the log file a libbi object
propose_prior

Propose from the prior in a libbi model
sample

Using the LibBi wrapper to sample
sample_obs

Sample observations from a LibBi model that has been run
absolute_path

Absolute Path
Extract_assign.bi_model

Subset and replace model lines