R Interface to LibBi

Provides a complete R interface to LibBi, a library for Bayesian inference (see < http://libbi.org> and 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 from R.

Build Status codecov

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,


RBi requires R (>= 2.12.1) as well as the packages:

  • reshape2
  • ncdf4
  • data.table

The easiest way to install the latest stable version of RBi is via CRAN. The package is called rbi (all lower case):


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


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 or Unix, the easiest way is via the homebrew-science tap: Install Homebrew (on OS X) or Linuxbrew (on linux), then issue the following commands (using a command shell, i.e. Terminal or similar):

brew tap homebrew/science
brew install 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.


rbi 0.8.0

  • supplement option to save_libbi to store supplementary information
  • Temporary directories are now removed when quitting R or collecting garbage
  • Improved chaining of libbi calls
  • New attach_file function, a more general version of the former add_output
  • New file option for bi_read
  • Fixed problems with predict
  • Fixed add_output when passed a list
  • Fixed a bug in writing observation files; extra dimensions are now written in the correct order
  • Improved writing of observation files with ns or other dimensions
  • Improved error handling: libbi calls now finish and yield a warning if the call to the libbi executable fails; this makes it possible to inspect the object to diagnoise the problem

rbi 0.7.0

  • The class is now based on S3 classes. Because of this, it plays much nicer with the magrittr and related packages. There are now str and summary methods defined for libbi objects, and sample, filter and optimise commands for running LibBi
  • Caching is now supported: multiple calls to bi_read are much faster
  • added a testing suite
  • Fixed bug in bi_read when reading variables with one dimension
  • bi_generate_dataset now has a seed option
  • extract_sample function for extracting a single sample from a NetCDF file
  • new add_output option for reconstructing libbi objects
  • cleaned up code and removed obsolete functions
  • Many smaller bug fixes

rbi 0.6.0

  • bi_contents to quickly get the variables in an NetCDF file
  • generate_seed to generate a seed for a libbi run
  • new sample_obs option to libbi$run, to sample posterior observations
  • improved option handling; there is now only one 'options' option
  • overloaded subset operators in bi_model
  • no more result field in the libbi object
  • new vignette: Introduction to rbi
  • Fixed bug in bi_model$get_vars that didn't remove all spaces
  • Fixed bug in reading in the coord dimension(s) in bi_read
  • Fixed bug in bi_model$fix that ignored input variables

rbi 0.5.0

  • client is now an option to libbi$run
  • Fix bug in parsing options in libbi$initialize
  • Fix bug in get_traces if there is only one sample
  • bi_model$insert_lines can now work with blocks
  • Improve cloning, where all initialising parameters can now be passed

rbi 0.4.1

  • Change package name to lower case
  • Tidy up for CRAN submission
  • Fix finding libbi path
  • Fix handling of config options (#2, @tyler-abbot)
  • Fix options in bi_generate_dataset (#3, #5, @tyler-abbot)
  • Fix demos (#1, #6, @tyler-abbot)
  • Remove stringr dependency

rbi 0.4

  • Guess time dimension in netCDF files
  • Bug fixes to better deal with multiple coordinate variables
  • burnin option to get_traces
  • Reduce memory use when thinning

rbi 0.3

  • Bug fixes in bi_write
  • Improve dealing with different types of dimensions, including introduction of the coord_dim option in bi_write
  • bi_generate_dataset now returns observations
  • Remove Rcpp dependency

rbi 0.2

  • Remove C code and use ncdf4 package for interaction with netCDF files
  • Introduce the bi_model class to manipulate models
  • Allow giving init, obs and input as R objects
  • Rename bi_wrapper to libbi
  • Improved bi_read function to directly read from libbi objects

rbi 0.1

  • initial version

Reference manual

It appears you don't have a PDF plugin for this browser. You can click here to download the reference manual.


0.9.0 by Sebastian Funk, 2 months ago


Report a bug at https://github.com/libbi/RBi/issues

Browse source code at https://github.com/cran/rbi

Authors: Pierre E. Jacob [aut], Anthony Lee [ctb], Lawrence M. Murray [ctb], Sebastian Funk [aut, cre]

Documentation:   PDF Manual  

GPL-3 license

Imports ncdf4, data.table, reshape2

Suggests coda, R.rsp, testthat, stringi

System requirements: LibBi (>= 1.2.0)

See at CRAN