-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into documentation
- Loading branch information
Showing
17 changed files
with
462 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,68 @@ | ||
# emacs: -*- mode: python-mode; py-indent-offset: 4; tab-width: 4; indent-tabs-mode: nil -*- | ||
# ex: set sts=4 ts=4 sw=4 et: | ||
""" | ||
.. _meta2: | ||
.. _meta_basics: | ||
======================== | ||
Running a meta-analysis | ||
======================== | ||
===================================== | ||
The Basics of Running a Meta-Analysis | ||
===================================== | ||
PyMARE implements a range of meta-analytic estimators. | ||
Here we walk through the basic steps of running a meta-analysis with PyMARE. | ||
""" | ||
############################################################################### | ||
# Start with the necessary imports | ||
# -------------------------------- | ||
import numpy as np | ||
# ----------------------------------------------------------------------------- | ||
from pprint import pprint | ||
|
||
from pymare import core, estimators | ||
from pymare import core, datasets, estimators | ||
|
||
############################################################################### | ||
# Here we simulate a dataset | ||
# ----------------------------------- | ||
n_studies = 100 | ||
v = np.random.random((n_studies)) | ||
y = np.random.random((n_studies)) | ||
X = np.random.random((n_studies, 5)) | ||
n = np.random.randint(5, 50, size=n_studies) | ||
# Load the data | ||
# ----------------------------------------------------------------------------- | ||
# We will use the :footcite:t:`michael2013non` dataset, which comes from the | ||
# metadat library :footcite:p:`white2022metadat`. | ||
# | ||
# We only want to do a mean analysis, so we won't have any covariates except for | ||
# an intercept. | ||
data, meta = datasets.michael2013() | ||
dset = core.Dataset(data=data, y="yi", v="vi", X=None, add_intercept=True) | ||
dset.to_df() | ||
|
||
############################################################################### | ||
# Datasets can also be created from pandas DataFrames | ||
# --------------------------------------------------- | ||
dataset = core.Dataset(v=v, X=X, y=y, n=n) | ||
est = estimators.WeightedLeastSquares().fit_dataset(dataset) | ||
# Now we fit a model | ||
# ----------------------------------------------------------------------------- | ||
# You must first initialize the estimator, after which you can use | ||
# :meth:`~pymare.estimators.estimators.BaseEstimator.fit` to fit the model to | ||
# numpy arrays, or | ||
# :meth:`~pymare.estimators.estimators.BaseEstimator.fit_dataset` to fit it to | ||
# a :class:`~pymare.core.Dataset`. | ||
# | ||
# The :meth:`~pymare.estimators.estimators.BaseEstimator.summary` function | ||
# will return a :class:`~pymare.results.MetaRegressionResults` object, | ||
# which contains the results of the analysis. | ||
est = estimators.WeightedLeastSquares().fit_dataset(dset) | ||
results = est.summary() | ||
print(results.to_df()) | ||
results.to_df() | ||
|
||
############################################################################### | ||
# We can also extract some useful information from the results object | ||
# ----------------------------------------------------------------------------- | ||
# The :meth:`~pymare.results.MetaRegressionResults.get_heterogeneity_stats` | ||
# method will calculate heterogeneity statistics. | ||
pprint(results.get_heterogeneity_stats()) | ||
|
||
############################################################################### | ||
# The :meth:`~pymare.results.MetaRegressionResults.get_re_stats` method will | ||
# estimate the confidence interval for :math:`\tau^2`. | ||
pprint(results.get_re_stats()) | ||
|
||
############################################################################### | ||
# The :meth:`~pymare.results.MetaRegressionResults.permutation_test` method | ||
# will run a permutation test to estimate more accurate p-values. | ||
perm_results = results.permutation_test(n_perm=1000) | ||
perm_results.to_df() | ||
|
||
############################################################################### | ||
# References | ||
# ----------------------------------------------------------------------------- | ||
# .. footbibliography:: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
"""Open meta-analytic datasets.""" | ||
from .metadat import michael2013 | ||
|
||
__all__ = [ | ||
"michael2013", | ||
] |
Oops, something went wrong.