pyabc.external.r

R interface via rpy2

class pyabc.external.r.R(source_file: str)[source]

Bases: object

Interface to R via rpy2.

Note

The rpy2 package needs to be installed to interface with the R language. Installation of rpy2 is optional if R support is not required. See also installation of optional dependencies.

Note

Support of R via rpy2 is considered experimental for various reasons (see #116). Should this not work on your system, consider accessing R script-based.

Parameters:

source_file – Path to the file which contains the definitions for the model, the summary statistics and the distance function as well as the observed data.

__init__(source_file: str)[source]
display_source_ipython()[source]

Display source code as syntax highlighted HTML within IPython.

distance(function_name: str)[source]

The R-distance function.

Parameters:

function_name (str) – Name of the function in the R script which defines the distance function.

Returns:

distance – The distance function.

Return type:

callable

model(function_name: str)[source]

The R-model.

Parameters:

function_name (str) – Name of the function in the R script which defines the model.

Returns:

model – The model.

Return type:

callable

observation(name: str)[source]

The summary statistics of the observed data as defined in R.

Parameters:

name (str) – Name of the named list defined in the R script which holds the observed data.

Returns:

observation – A dictionary like object which holds the summary statistics of the observed data.

Return type:

r named list

summary_statistics(function_name: str, is_py_model: bool = False)[source]

The R-summary statistics.

Parameters:
  • function_name (str) – Name of the function in the R script which defines the summary statistics function.

  • is_py_model (bool) – Whether or not the model result is a python object. If True, then it is expected to be a dictionary that will be converted to a ListVector.

Returns:

summary_statistics – The summary statistics function.

Return type:

callable