Skip to content

statspai.quasi

quasi

Lightweight pre/post quasi-experimental designs.

These wrap StatsPAI's OLS machinery into named, assumption-surfacing designs so non-experts reach for the right estimator:

  • :func:ancova — covariate-adjusted comparison of group means.
  • :func:negd — pre/post non-equivalent group design (ANCOVA or change-score).

Both return the unified :class:~statspai.core.results.CausalResult.

negd

negd(data: DataFrame, group: str, *, pre: str, post: str, covariates: Optional[Sequence[str]] = None, method: str = 'ancova', robust: str = 'hc1', cluster: Optional[str] = None, alpha: float = 0.05, group_value: Any = None) -> CausalResult

Pre/post non-equivalent group design (NEGD).

A treated and a non-randomised comparison group are each measured before and after the intervention. Two estimators are offered:

  • method='ancova' (default): regress post on treatment and pre (plus any covariates). Conditions on baseline; robust to baseline imbalance and generally preferred (Lord's paradox).
  • method='change_score': regress the change post - pre on treatment (plus covariates). Identifies under parallel pre/post trends and is more vulnerable to regression to the mean when baseline differs across groups.

Parameters:

Name Type Description Default
data DataFrame

One row per unit (wide format: a pre and a post column).

required
group str

Treatment-group column (see :func:ancova for encoding).

required
pre str

Baseline and follow-up outcome columns.

required
post str

Baseline and follow-up outcome columns.

required
covariates sequence of str

Additional adjustment covariates.

None
method ('ancova', 'change_score')

Estimator (see above).

'ancova'
robust str

As in :func:ancova.

'hc1'
cluster str

As in :func:ancova.

'hc1'
alpha str

As in :func:ancova.

'hc1'
group_value str

As in :func:ancova.

'hc1'

Returns:

Type Description
CausalResult

estimand='ATE'. model_info records the method and, for change-score, a regression-to-the-mean caveat.

Examples:

>>> import statspai as sp
>>> res = sp.negd(
...     df, group='treated', pre='score0', post='score1',
... )