Learn R Programming

⚠️There's a newer version (1.0.1) of this package.Take me there.

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

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):

install.packages('rbi')

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

# install.packages("devtools")
library('devtools')
install_github("libbi/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 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.

Copy Link

Version

Install

install.packages('rbi')

Monthly Downloads

458

Version

0.7.0

License

GPL-3

Issues

Pull Requests

Stars

Forks

Maintainer

Sebastian Funk

Last Published

February 6th, 2017

Functions in rbi (0.7.0)

add_output

bi_open

Bi open
Extract.bi_model

Subset and replace model lines
fix

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

Get the name of a bi model
get_block

Get the contents of a block in a LibBi model
extract_sample

Extract a sample from a LibBi run.
find_block

Find a block in a LibBi model
filter

Using the LibBi wrapper to filter
clean_model

Strip model code to its bare bones
bi_write

Create (init or observation) files for LibBi
bi_read

Bi Read
predict

Using the LibBi wrapper to predict
optimise

Using the LibBi wrapper to optimise
get_traces

Get the parameter traces
insert_lines

Insert lines in a LibBi model
option_string

Convert Options
option_list

Convert string to option list
libbi

LibBi Wrapper
is_empty

Check if a model is empty
netcdf_create_from_list

Create NetCDF File from R list
obs_to_noise

Copy obs variables to state variables (with '__sample_' prepended)
read_libbi

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

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

Using the LibBi wrapper to launch LibBi
sample

Using the LibBi wrapper to sample
read_var_input

Read variable from NetCDF file.
print.bi_model

Print the lines of a LibBi model
rbi-package

RBi - R interface for libbi
replace_all

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

Using the LibBi wrapper to rewrite
propose_prior

Propose from the prior in a libbi model
save_libbi

Write results of a LibBi run to an RDS file
set_name

Set the name of a bi model
write_file

Writes a bi model to a file.
summary

var_names

Get variables
bi_generate_dataset

Bi Generate Dataset
assert_output

Check that a LibBi wrapper has valid output
bi_contents

Bi contents
bi_model

Bi Model
absolute_path

Absolute Path
bi_file_summary

NetCDF File Summary
add_block

Add a block to a LibBi model
bi_dim_len

NetCDF dimension length