cleverly.variable_importance_plan#

cleverly.variable_importance_plan(data: Any, *, outcome: str, candidates: Sequence[str], covariates: Sequence[str], estimand: str = 'ate', estimator: TMLE | None = None, adjust_for_other_candidates: bool = True, delta: str | None = None, weights: str | None = None, weights_type: str = 'probability', weights_estimated: bool = False, id: str | None = None) → PlannedFits[source]#

Count the model fits variable_importance() would make, without fitting any.

Takes the arguments of variable_importance() except keep_fits, which does not change the fits. It runs the same refusals in the same order, prepares each candidate’s data as the run does, and counts the fits of each candidate’s own TMLE fit.

Parameters:
dataDataFrame

The original pandas or polars dataframe.

outcomestr

Outcome column.

candidatessequence of str

Candidate exposures, each fitted in turn as the treatment.

covariatessequence of str

Baseline covariates.

estimandstr

Target parameter stem fitted for each candidate.

estimatorTMLE or None

Template estimator; None uses TMLE(estimands=estimand).

adjust_for_other_candidatesbool

Whether the other candidates join each candidate’s adjustment set.

deltastr or None

Outcome-observation indicator column.

weightsstr or None

Probability-weight column.

weights_type{“probability”}

Interpretation of weights.

weights_estimatedbool

Whether the supplied weights were estimated from these data.

idstr or None

Independent-cluster identifier used for variance estimation.

Returns:
PlannedFits

One row per model, scope and candidate. Each scope ends with the candidate it belongs to, and the multiplier "candidate exposures" gives their number. A multiplier whose value differs between candidates, such as the number of arms, is left out and named in a note.

See also

variable_importance

The fits this counts.

cleverly.PlannedFits

The record returned.

cleverly.IdentifiedEffect.planned_fits

The same preview for one estimate.

Examples

>>> import numpy as np
>>> import pandas as pd
>>> from sklearn.linear_model import LinearRegression, LogisticRegression
>>> from cleverly import variable_importance_plan
>>> from cleverly.estimators import TMLE
>>> rng = np.random.default_rng(0)
>>> frame = pd.DataFrame(
...     {
...         "W": rng.normal(size=200),
...         "X1": rng.integers(0, 2, 200),
...         "X2": rng.integers(0, 2, 200),
...     }
... )
>>> frame["Y"] = frame["X1"] + frame["W"] + rng.normal(size=200)
>>> plan = variable_importance_plan(
...     frame,
...     outcome="Y",
...     candidates=["X1", "X2"],
...     covariates=["W"],
...     estimator=TMLE(
...         outcome_learner=LinearRegression(),
...         treatment_learner=LogisticRegression(),
...         cross_fit=False,
...         random_state=0,
...     ),
... )
>>> plan.total_fits, plan.exact
(4, True)