brmp

brmp.brm(formula_str, df, family=None, priors=None, contrasts=None)[source]

Defines a model and encodes data in design matrices.

By default categorical columns are coded using dummy coding.

Parameters:
  • formula_str (str) – An lme4 formula. e.g. 'y ~ 1 + x'. See Formula for a description of the supported syntax.
  • df (pandas.DataFrame) – A data frame containing columns for each of the variables in formula_str.
  • family (brmp.family.Family) – The model’s response family.
  • priors (list) – A list of Prior instances describing the model’s priors.
  • contrasts (dict) – A dictionary that optionally maps variable names to contrast matrices describing custom encodings of categorical variables. Each contrast matrix should be a ndarray of shape (L, C), where L is the number of levels present in the categorical variable and C is the length of the desired encoding.
Returns:

A wrapper around the model description and the design matrices.

Return type:

brmp.ModelAndData

Example:

df = pd.DataFrame({'y': [1., 2.], 'x': [.5, 0.]})
model = brm('y ~ 1 + x', df)
class brmp.ModelAndData(model, df, data)[source]
data = None

A dictionary with the encoded data as its values. Each value is a ndarray.

fit(algo='nuts', **kwargs)[source]

Fits the wrapped model.

Parameters:
  • algo (str) – The algorithm used for inference, either 'nuts', 'svi' or 'prior'.
  • kwargs – Inference algorithm-specific keyword arguments. See nuts(), svi() and prior() for details.
Returns:

A model fit.

Return type:

brmp.fit.Fit

Example:

fit = brm('y ~ x', df).fit()
nuts(iter=10, warmup=None, num_chains=1, seed=None, backend=<Backend name="NumPyro">)[source]

Fit the model using NUTS.

Parameters:
  • iter (int) – The number of (post warm up) samples to take.
  • warmup (int) – The number of warm up samples to take. Warm up samples are not included in the final model fit. Defaults to iter / 2.
  • num_chains (int) – The number of chains to run.
  • seed (int) – Random seed.
  • backend (brmp.backend.Backend) – The backend used to perform inference.
Returns:

A model fit.

Return type:

brmp.fit.Fit

Example:

fit = brm('y ~ x', df).nuts()
svi(iter=10, num_samples=10, seed=None, backend=<Backend name="Pyro">, **kwargs)[source]

Fit the model using stochastic variational inference.

Parameters:
  • iter (int) – The number of optimisation steps to take.
  • num_samples (int) – The number of samples to take from the variational posterior.
  • seed (int) – Random seed.
  • backend (brmp.backend.Backend) – The backend used to perform inference.
Returns:

A model fit.

Return type:

brmp.fit.Fit

Example:

fit = brm('y ~ x', df).svi()
prior(num_samples=10, seed=None, backend=<Backend name="Pyro">)[source]

Sample from the prior.

Parameters:
  • num_samples (int) – The number of samples to take.
  • seed (int) – Random seed.
  • backend (brmp.backend.Backend) – The backend used to perform inference.
Returns:

A model fit.

Return type:

brmp.fit.Fit

Example:

fit = brm('y ~ x', df).prior()