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 to install Homebrew (on OS X) or Linuxbrew (on linux), followed by (using a command shell, i.e. Terminal or similar):

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.9.1

License

GPL-3

Issues

Pull Requests

Stars

Forks

Maintainer

Sebastian Funk

Last Published

May 14th, 2018

Functions in rbi (0.9.1)

optimise

Using the LibBi wrapper to optimise
libbi

LibBi Wrapper
Extract.bi_model

Subset and replace model lines
option_list

Convert string to option list
find_block

Find a block in a LibBi model
fix

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

Absolute Path
remove_lines

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

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

Extract a sample from a LibBi run.
replace_all

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

Check that a LibBi wrapper has valid output
bi_write

Create (init or observation) files for LibBi
bi_read

Bi Read
get_block

Get the contents of a block in a LibBi model
summary

bi_model

Bi Model
attach_file

add_block

Add a block to a LibBi model
bi_generate_dataset

Bi Generate Dataset
rewrite

Using the LibBi wrapper to rewrite
insert_lines

Insert lines in a LibBi model
bi_open

Bi open
netcdf_create_from_list

Create NetCDF File from R list
bi_contents

Bi contents
set_name

Set the name of a bi model
get_traces

Get the parameter traces
predict

Using the LibBi wrapper to predict
bi_dim_len

NetCDF dimension length
sample

Using the LibBi wrapper to sample
obs_to_noise

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

propose_prior

Propose from the prior in a libbi model
get_name

Get the name of a bi model
option_string

Convert Options
bi_file_summary

NetCDF File Summary
rbi-package

RBi - R interface for libbi
run

Using the LibBi wrapper to launch LibBi
filter

Using the LibBi wrapper to filter
clean_model

Strip model code to its bare bones
save_libbi

Write results of a LibBi run to an RDS file
logLik

Using the LibBi wrapper to logLik
is_empty

Check if a model is empty
print.bi_model

Print the lines of a LibBi model
var_names

Get variables
write_model

Writes a bi model to a file.