pymare.estimators.StanMetaRegression

class StanMetaRegression(**sampling_kwargs)[source]

Bases: BaseEstimator

Bayesian meta-regression estimator using Stan.

Parameters:

**sampling_kwargs – Optional keyword arguments to pass on to the MCMC sampler (e.g., iter for number of iterations).

Notes

For most uses, this class should be ignored in favor of the functional stan() estimator. The object-oriented interface is useful primarily when fitting the meta-regression model repeatedly to different data; the separation of .compile() and .fit() steps allows one to compile the model only once.

Warning

StanMetaRegression uses Pystan 3, which requires Python 3.7. Pystan 3 should not be used with PyMARE and Python 3.6 or earlier.

compile()[source]

Compile the Stan model.

fit(y, v, X, groups=None)[source]

Run the Stan sampler and return results.

Parameters:
  • y (numpy.ndarray of shape (K,)) – 1d array of study-level estimates

  • v (numpy.ndarray of shape (K,)) – 1d array of study-level variances

  • X (numpy.ndarray of shape (K[, P])) – 1d or 2d array containing study-level predictors (including intercept); has dimensions K x P, where K is the number of studies and P is the number of predictor variables.

  • groups (list of int, optional) – 1d array of integers identifying groups/clusters of observations in the y/v/X inputs. If provided, values must consist of integers in the range of 1..k (inclusive), where k is the number of distinct groups. When None (default), it is assumed that each observation in the inputs is a separate group.

Return type:

A StanFit4Model object (see PyStan documentation for details).

Notes

This estimator supports (simple) hierarchical models. When multiple estimates are available for at least one of the studies in y, the groups argument can be used to specify the nesting structure (i.e., which rows in y, v, and X belong to each study).

fit_dataset(dataset, *args, **kwargs)[source]

Apply the current estimator to the passed Dataset container.

A convenience interface that wraps fit() and automatically aligns the variables held in a Dataset with the required arguments.

Parameters:
  • dataset (Dataset) – A PyMARE Dataset instance holding the data.

  • *args – Optional positional arguments to pass onto the fit() method.

  • **kwargs – Optional keyword arguments to pass onto the fit() method.

get_v(dataset)[source]

Get the variances, or an estimate thereof, from the given Dataset.

Parameters:

dataset (Dataset) – The dataset to use to retrieve/estimate v.

Returns:

2-dimensional array of variances/variance estimates.

Return type:

numpy.ndarray

Notes

This is equivalent to directly accessing dataset.v when variances are present, but affords a way of estimating v from sample size (n) for any estimator that implicitly estimates a sigma^2 parameter.

summary(ci=95)[source]

Generate a BayesianMetaRegressionResults object from the fitted estimator.

Examples using pymare.estimators.StanMetaRegression

Run Estimators on a simulated dataset

Run Estimators on a simulated dataset