Meta-Analysis¶
Fixed-effects and random-effects meta-analysis matching R’s metafor::rma().
Meta-analysis: fixed-effects and random-effects pooling of study results.
Computes inverse-variance weighted pooled estimates, between-study heterogeneity (tau2), and heterogeneity diagnostics (Q, I2, H2).
Supports four estimation methods: - FE: Fixed-effects (common-effect) - DL: DerSimonian-Laird (random-effects, method-of-moments) - REML: Restricted maximum likelihood (random-effects) - PM: Paule-Mandel (random-effects, generalized Q)
Validates against: R metafor::rma()
- class pystatsbio.meta.MetaSolution(result)[source]¶
Bases:
SolutionReprMixinPublic result of a meta-analysis — a Solution wrapping
Result[MetaParams].Exposes every fit output as a read-only property plus the uniform
.backend_name/.timing/.warnings/.infometadata and a Jupyter_repr_html_(viaSolutionReprMixin).- Parameters:
result (Result[MetaParams])
- class pystatsbio.meta.MetaParams(estimate, se, ci_lower, ci_upper, z_value, p_value, tau2, tau2_se, tau, I2, H2, Q, Q_df, Q_p, k, method, conf_level, weights, yi, vi)[source]¶
Bases:
objectComputed payload of a meta-analysis.
- Parameters:
- weights¶
Study weights used in the final pooling.
- Type:
NDArray
- yi¶
Input effect sizes.
- Type:
NDArray
- vi¶
Input sampling variances.
- Type:
NDArray
- pystatsbio.meta.rma(yi, vi, *, method='REML', conf_level=0.95)[source]¶
Random-effects (or fixed-effects) meta-analysis.
Matches R’s metafor::rma(yi, vi, method=…) for the common case of pre-computed effect sizes and sampling variances.
- Parameters:
yi (ArrayLike) – Effect sizes (e.g., log odds ratios, standardized mean differences).
vi (ArrayLike) – Corresponding sampling variances (NOT standard errors).
method (str) – Estimation method. One of: -
'FE': fixed-effects (inverse-variance weighted) -'DL': DerSimonian-Laird (default in many older packages) -'REML': restricted maximum likelihood (default, recommended) -'PM': Paule-Mandelconf_level (float) – Confidence level for confidence intervals. Default 0.95.
- Returns:
Solution wrapping the pooled estimate, heterogeneity statistics, and study weights, with a summary method and the uniform .backend_name/.timing/.warnings/.info accessors.
- Return type:
- Raises:
ValidationError – If
methodis not one of the valid methods, or if inputs fail validation (wrong shape, negative variances, etc.).ConvergenceError – If iterative optimization (REML, PM) fails to converge.
Examples
>>> import numpy as np >>> from pystatsbio.meta import rma >>> yi = np.array([-0.89, -1.59, -1.35]) >>> vi = np.array([0.035, 0.019, 0.014]) >>> result = rma(yi, vi, method='DL') >>> print(f"Pooled: {result.estimate:.3f}, tau2: {result.tau2:.4f}")
- pystatsbio.meta.cochran_q(yi, vi)[source]¶
Cochran’s Q statistic for heterogeneity.
Q = sum(w_i * (y_i - mu_FE)^2) where w_i = 1/v_i and mu_FE is the fixed-effects pooled estimate. The p-value is from a chi-squared distribution with df = k - 1.
- pystatsbio.meta.i_squared(Q, k)[source]¶
I-squared heterogeneity statistic.
I^2 = max(0, (Q - (k-1)) / Q) * 100
Measures the percentage of total variability due to between-study heterogeneity rather than sampling error.