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'
. SeeFormula
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)
, whereL
is the number of levels present in the categorical variable andC
is the length of the desired encoding.
Returns: A wrapper around the model description and the design matrices.
Return type: Example:
df = pd.DataFrame({'y': [1., 2.], 'x': [.5, 0.]}) model = brm('y ~ 1 + x', df)
- formula_str (str) – An lme4 formula. e.g.
-
class
brmp.
ModelAndData
(model, df, data)[source]¶ -
-
fit
(algo='nuts', **kwargs)[source]¶ Fits the wrapped model.
Parameters: Returns: A model fit.
Return type: 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: 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: 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: Example:
fit = brm('y ~ x', df).prior()
-