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

339

Version

1.0.1

License

GPL-3

Issues

Pull Requests

Stars

Forks

Maintainer

Sebastian Funk

Last Published

February 11th, 2026

Functions in rbi (1.0.1)

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
generate_dataset

Generate Dataset
enable_outputs

Enable outputting variables in a bi_model
extract_sample

Extract a sample from a LibBi run.
get_block

Get the contents of a block in a LibBi model
get_char_levels

Get the factor levels of all character columns in data
insert_lines

Insert lines in a LibBi model
filter

Using the LibBi wrapper to filter
libbi

LibBi Wrapper
bi_open

Bi Open
installed_libbi_version

Get the LibBi version
bi_model

Bi Model
get_const

Get constants in a LibBi model
get_dims

Get dimensions in a LibBi model
fix

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

Find a block in a LibBi model
factorise

Convert character columns to factors in data
create_working_folder

Internal function to create a temporary working folder
locate_libbi

Find the libbi executable
bi_write

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

Check if a model is empty
option_string

Convert Options
option_list

Convert string to option list
join

Join multiple libbi objects
rewrite

Using the LibBi wrapper to rewrite
get_name

Get the name of a bi model
run

Using the LibBi wrapper to launch LibBi
simulate

Using the LibBi wrapper to simulate
print_log

Print the log file a libbi object
summary

Print summary information about a libbi object
update

Update a libbi object
propose_prior

Propose from the prior in a libbi model
read_libbi

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

Remove variables
remove_lines

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

Get the parameter traces
to_input

Convert variables into inputs
logLik

Using the LibBi wrapper to logLik
replace_all

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

Sample observations from a LibBi model that has been run
print.bi_model

Print the lines of a LibBi model
predict

Using the LibBi wrapper to predict
var_names

Get variable names in a LibBi model
set_name

Set the name of a bi model
save_libbi

Write results of a LibBi run to an RDS file
write_model

Writes a bi model to a file.
sample

Using the LibBi wrapper to sample
optimise

Using the LibBi wrapper to optimise
bi_contents

Bi contents
absolute_path

Absolute Path
add_block

Add a block to a LibBi model
Extract.bi_model

Subset model lines
Equals.bi_model

Check if two models are equal
Extract_assign.bi_model

Subset and replace model lines
Unequals.bi_model

Check if two models are unequal
bi_read

Bi Read
bi_generate_dataset

Bi Generate Dataset
attach_data

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

NetCDF File Summary
bi_dim_len

NetCDF dimension length
assert_files

Check that a LibBi wrapper has valid output
create_coord_var

Create a coordinate variable
clean_model

Strip model code to its bare bones
check_sparse_var

Check if a variable is sparse