smmargins.MarginsResult¶
- class smmargins.MarginsResult(estimate: ndarray, vcov: ndarray, labels: Sequence[str] | None = None, level: float = 0.95, df: int | None = None, stat_name: str = 'margin')¶
Container for margin estimates with delta-method standard errors.
Holds the point estimate, standard error, confidence interval, p-value, and the full delta-method covariance matrix of a vector of margin statistics (e.g. adjusted predictions or marginal effects).
For a fitted model with parameter vector \(\hat\beta\), estimated covariance \(\widehat V(\hat\beta)\), and a (possibly vector-valued) statistic \(g(\beta)\), the delta method gives
\[\widehat{\mathrm{Var}}[g(\hat\beta)] \approx G \, \widehat V \, G^\top,\]where \(G = \partial g / \partial \beta|_{\hat\beta}\).
- Parameters:
estimate (ndarray) – Point estimates.
vcov (ndarray) – Full delta-method covariance of the estimates (useful for joint tests).
labels (sequence of str, optional) – Row labels. Defaults to
["m1", "m2", ...].level (float) – Confidence level for intervals (default 0.95).
df (int or None) – Residual degrees of freedom; if set, uses t-distribution for p-values and CIs. Otherwise uses N(0,1).
stat_name (str) – Column name for the statistic in
summary().
- estimate¶
- Type:
ndarray
- se¶
- Type:
ndarray
- labels¶
- Type:
list[str]
- vcov¶
Full delta-method covariance of the estimates (useful for joint tests).
- Type:
ndarray
- level¶
- Type:
float
- df¶
- Type:
int or None
- ci_lower¶
- Type:
ndarray
- ci_upper¶
- Type:
ndarray
- pvalue¶
- Type:
ndarray
- zstat¶
- Type:
ndarray
- _test_name¶
"z"or"t"depending on whether the normal or t-distribution is used.- Type:
str
Examples
Most users obtain a
MarginsResultby callingMargins.predictorMargins.dydxrather than constructing one directly. Once you have a result, the typical workflow is to inspect.summary()or pull fields off it:res = M.dydx(["x1", "x2"]) res.summary() # tidy table of estimates / SE / CI res.estimate # ndarray of point estimates res.vcov # joint delta-method covariance
Forming linear contrasts of the estimates uses the joint covariance that is already on the result, so no additional differentiation is required. For example, the difference between the AMEs of
x1andx2:res.contrast([1.0, -1.0], labels=["x1 - x2"])
Constructing one directly (mostly useful in tests):
>>> import numpy as np >>> from smmargins import MarginsResult >>> est = np.array([1.0, 2.0]) >>> vcov = np.array([[0.25, 0.10], ... [0.10, 0.16]]) >>> res = MarginsResult(est, vcov, labels=["m1", "m2"]) >>> res.se.round(2).tolist() [0.5, 0.4] >>> res.contrast([1.0, -1.0], labels=["m1 - m2"]).estimate.tolist() [-1.0]
See also
Margins.predict,Margins.dydx,Margins.did- __init__(estimate: ndarray, vcov: ndarray, labels: Sequence[str] | None = None, level: float = 0.95, df: int | None = None, stat_name: str = 'margin')¶
Methods
__init__(estimate, vcov[, labels, level, ...])contrast(c[, labels, name])Form linear contrasts of the estimates, with delta-method SEs.
summary()Return a summary DataFrame with estimates, SEs, and confidence intervals.