fitted(what='expectation', data=None, seed=None)[source]

Produces predictions from the fitted model.

Predicted values are computed for each sample collected during inference, and for each row in the data set.

  • what (str) –

    The value to predict. Valid arguments and their effect are described below:

    'expectation' Computes the expected value of the response distribution.
    'sample' Draws a sample from the response distribution.
    'response' Computes the output of the model followed by any inverse link function. i.e. The value of the location parameter of the response distribution.
    'linear' Computes the output of the model prior to the application of any inverse link function.
  • data (pandas.DataFrame) – The data from which to compute the predictions. When omitted, the data on which the model was fit is used.
  • seed (int) – Random seed. Used only when 'sample' is given as the 'what' argument.

An array with shape (S, N). Where S is the number of samples taken during inference and N is the number of rows in the data set used for prediction.

Return type:


marginals(qs=[0.025, 0.25, 0.5, 0.75, 0.975])[source]

Produces a table containing statistics of the marginal distibutions of the parameters of the fitted model.

Parameters:qs (list) – A list of quantiles to include in the output.
Returns:A table of marginal statistics.


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

#        mean    sd  2.5%   25%   50%   75% 97.5% n_eff r_hat
# b_x    0.42  0.33 -0.11  0.14  0.48  0.65  0.88  5.18  1.00
# sigma  0.78  0.28  0.48  0.61  0.68  0.87  1.32  5.28  1.10
get_scalar_param(name, preserve_chains=False)[source]

Extracts the values sampled for a single parameter from a model fit.

  • name (str) – The name of a parameter of the model. Valid names are those shown in the output of marginals().
  • preserve_chains (bool) – Whether to group samples by the MCMC chain on which they were collected.

An array with shape (S,) when preserve_chains=False, (C, S) otherwise. Where S is the number of samples taken during inference, and C is the number of MCMC chains run.

Return type: