pymargins.PysmatchClient¶
- class pymargins.PysmatchClient(matcher: Any, treatment_col: str, fit_scores_kwds: dict | None = None, match_kwds: dict | None = None)¶
Wrap a fitted
pysmatch.Matcherfor use withMargins.This adapter satisfies the
MatchingClientprotocol consumed byMargins(..., matching=...). It extracts the matched subset and matched-set labels from a fittedpysmatch.Matcher, and implementsrematch()so that bootstrap inference can re-run matching on each resampled replicate.- Parameters:
matcher (pysmatch.Matcher) – A fitted
pysmatch.Matcherthat has already hadfit_scores(),predict_scores(), andmatch()called.treatment_col (str) – Name of the binary treatment indicator column in the data. Used to reconstruct test/control groups during
rematch().fit_scores_kwds (dict, optional) – Keyword arguments passed to
Matcher.fit_scores()on eachrematch()call. If omitted, sensible defaults are used (balance=True, model_type='linear', nmodels=3, n_jobs=1).match_kwds (dict, optional) – Keyword arguments passed to
Matcher.match()on eachrematch()call. If omitted, sensible defaults are used (method='min', nmatches=1, threshold=0.001, replacement=False).
- matched_data¶
The matched subset (
matcher.matched_data).- Type:
- cluster_ids¶
Matched-set labels extracted from
matched_data["match_id"].- Type:
Examples
>>> from pysmatch.Matcher import Matcher >>> from pymargins.matching import PysmatchClient >>> matcher = Matcher(test, control, yvar="treated", exclude=["y"]) >>> matcher.fit_scores(balance=True, model_type="linear") >>> matcher.predict_scores() >>> matcher.match(method="min", nmatches=1, threshold=0.001) >>> client = PysmatchClient(matcher, treatment_col="treated") >>> m = Margins(fitted_model, matching=client)
- __init__(matcher: Any, treatment_col: str, fit_scores_kwds: dict | None = None, match_kwds: dict | None = None)¶
Methods
__init__(matcher, treatment_col[, ...])rematch(data)Re-run pysmatch matching on a bootstrap resample.