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("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

458

Version

0.10.4

License

GPL-3

Issues

Pull Requests

Stars

Forks

Maintainer

Sebastian Funk

Last Published

November 8th, 2021

Functions in rbi (0.10.4)

Extract_assign.bi_model

Subset and replace model lines
Extract.bi_model

Subset model lines
bi_contents

Bi contents
Equals.bi_model

Check if two models are equal
attach_file

Deprecated (use 'attach' instead). Attach a new file or data set to a libbi object
Unequals.bi_model

Check if two models are unequal
bi_write

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

Absolute Path
create_working_folder

Internal function to create a temporary working folder
assert_files

Check that a LibBi wrapper has valid output
add_block

Add a block to a LibBi model
bi_dim_len

NetCDF dimension length
attach_data

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

NetCDF File Summary
get_block

Get the contents of a block in a LibBi model
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
bi_open

Bi open
extract_sample

Extract a sample from a LibBi run.
filter

Using the LibBi wrapper to filter
enable_outputs

Enable outputting variables in a bi_model
get_const

Get constants in a LibBi model
get_dims

Get dimensions in a LibBi model
libbi

LibBi Wrapper
insert_lines

Insert lines in a LibBi model
installed_libbi_version

Get the LibBi version
predict

Using the LibBi wrapper to predict
clean_model

Strip model code to its bare bones
print.bi_model

Print the lines of a LibBi model
var_names

Get variable names in a LibBi model
update

Update a libbi object
option_string

Convert Options
get_name

Get the name of a bi model
get_traces

Get the parameter traces
bi_read

Bi Read
option_list

Convert string to option list
remove_lines

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

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

Using the LibBi wrapper to rewrite
locate_libbi

Find the libbi executable
run

Using the LibBi wrapper to launch LibBi
print_log

Print the log file a libbi object
propose_prior

Propose from the prior in a libbi model
optimise

Using the LibBi wrapper to optimise
logLik

Using the LibBi wrapper to logLik
sample

Using the LibBi wrapper to sample
simulate

Using the LibBi wrapper to simulate
set_name

Set the name of a bi model
save_libbi

Write results of a LibBi run to an RDS file
remove_vars

Remove variables
write_model

Writes a bi model to a file.
sample_obs

Sample observations from a LibBi model that has been run
bi_model

Bi Model
fix

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

Bi Generate Dataset
find_block

Find a block in a LibBi model
join

Join multiple libbi objects
is_empty

Check if a model is empty
rbi-package

RBi - R interface for libbi
summary

Print summary information about a libbi object
to_input

Convert variables into inputs
read_libbi

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