Skip to content

Commit 0a99840

Browse files
authored
Enhance Dataset example (#100)
* Update plot_create_dataset.py * Enhance datasets example. * Replace "datasets" with "dependent variables".
1 parent f425ff9 commit 0a99840

File tree

2 files changed

+57
-2
lines changed

2 files changed

+57
-2
lines changed

examples/01_basic_io/plot_create_dataset.py

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,24 @@
2222
###############################################################################
2323
# Datasets can be created from arrays
2424
# -----------------------------------
25+
# The simplest way to create a dataset is to pass in arguments as numpy arrays.
26+
#
27+
# ``y`` refers to the study-level estimates, ``v`` to the variances,
28+
# ``X`` to any study-level regressors, and ``n`` to the sample sizes.
29+
#
30+
# Not all Estimators require all of these arguments, so not all need to be
31+
# used in a given Dataset.
32+
y = [2, 4, 6]
2533
v = [100, 100, 100]
2634
X = [[5, 9], [2, 8], [1, 7]]
27-
y = [2, 4, 6]
28-
dataset = core.Dataset(y=y, v=v, X=X)
35+
36+
dataset = core.Dataset(y=y, v=v, X=X, X_names=["X1", "X7"])
37+
38+
pprint(vars(dataset))
39+
40+
###############################################################################
41+
# Datasets have the :meth:`~pymare.core.Dataset.to_df` method.
42+
dataset.to_df()
2943

3044
###############################################################################
3145
# Datasets can also be created from pandas DataFrames
@@ -38,6 +52,32 @@
3852
"X7": [9, 8, 7],
3953
}
4054
)
55+
4156
dataset = core.Dataset(v="v_alt", X=["X1", "X7"], data=df, add_intercept=False)
4257

4358
pprint(vars(dataset))
59+
60+
###############################################################################
61+
# Datasets can also contain multiple dependent variables
62+
# ------------------------------------------------------
63+
# These variables are analyzed in parallel, but as unrelated variables,
64+
# rather than as potentially correlated ones.
65+
#
66+
# This is particularly useful for image-based neuroimaging meta-analyses.
67+
# For more information about this, see `NiMARE <https://nimare.readthedocs.io>`_.
68+
y = [
69+
[2, 4, 6], # Estimates for first study's three outcome variables.
70+
[3, 2, 1], # Estimates for second study's three outcome variables.
71+
]
72+
v = [
73+
[100, 100, 100], # Estimate variances for first study's three outcome variables.
74+
[8, 4, 2], # Estimate variances for second study's three outcome variables.
75+
]
76+
X = [
77+
[5, 9], # Predictors for first study. Same across all three outcome variables.
78+
[2, 8], # Predictors for second study. Same across all three outcome variables.
79+
]
80+
81+
dataset = core.Dataset(y=y, v=v, X=X, X_names=["X1", "X7"])
82+
83+
pprint(vars(dataset))

examples/02_meta-analysis/plot_run_meta-analysis.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,21 @@
3737
# :meth:`~pymare.estimators.estimators.BaseEstimator.fit_dataset` to fit it to
3838
# a :class:`~pymare.core.Dataset`.
3939
#
40+
# .. tip::
41+
# We generally recommend using
42+
# :meth:`~pymare.estimators.estimators.BaseEstimator.fit_dataset` over
43+
# :meth:`~pymare.estimators.estimators.BaseEstimator.fit`.
44+
#
45+
# There are a number of methods, such as
46+
# :meth:`~pymare.results.MetaRegressionResults.get_heterogeneity_stats` and
47+
# :meth:`~pymare.results.MetaRegressionResults.permutation_test`,
48+
# which only work when the Estimator is fitted to a Dataset.
49+
#
50+
# However, :meth:`~pymare.estimators.estimators.BaseEstimator.fit` requires
51+
# less memory than :meth:`~pymare.estimators.estimators.BaseEstimator.fit_dataset`,
52+
# so it can be useful for large-scale meta-analyses,
53+
# such as neuroimaging image-based meta-analyses.
54+
#
4055
# The :meth:`~pymare.estimators.estimators.BaseEstimator.summary` function
4156
# will return a :class:`~pymare.results.MetaRegressionResults` object,
4257
# which contains the results of the analysis.

0 commit comments

Comments
 (0)