cleverly.longitudinal.snmm#

cleverly.longitudinal.snmm(data: Any, *, outcome: str, treatment: Sequence[str], baseline: Sequence[str], regimens: Any = None, time_varying: Sequence[Sequence[str]] | None = None, censoring: Sequence[str] | None = None, id: str | None = None, weights: str | None = None, weights_type: str = 'probability', weights_estimated: bool = False, family: str = 'auto', continuous_treatment: Sequence[str] = (), **kwargs: Any) → StructuralNestedMeanResult[source]#

One-call structural nested mean model, mirroring cleverly.longitudinal.ltmle().

Parameters:
dataDataFrame or LongitudinalData

One wide frame, or a container that has already read the columns.

outcomestr

The end-of-study outcome column.

treatmentsequence of str

The treatment column of each node, in time order.

baselinesequence of str

The covariates measured before any treatment.

regimensmapping, sequence, or None

Static regimens, as for StructuralNestedMean.

time_varyingsequence of sequence of str or None

The covariates measured before the treatment of each node.

censoringsequence of str or None

Refused when it names a column.

idstr or None

A cluster column.

weightsstr or None

A column of known observation weights.

weights_typestr

How to read weights.

weights_estimatedbool

Declare that the weights came out of a fitted model.

family{“auto”, “binomial”, “gaussian”}

The outcome family.

continuous_treatmentsequence of str

The treatment columns that hold a dose.

**kwargsAny

The remaining StructuralNestedMean settings.

Returns:
StructuralNestedMeanResult

The blips, the reference mean, and the declared regimen means and contrasts.

See also

StructuralNestedMean

The estimator class and its settings.

Examples

>>> from cleverly.datasets import make_longitudinal
>>> from cleverly.learners import GLM
>>> from cleverly.longitudinal import snmm
>>> frame, _ = make_longitudinal(n=300, seed=0, censoring=False)
>>> result = snmm(
...     frame,
...     outcome="Y",
...     treatment=["A1", "A2"],
...     baseline=["W1", "W2"],
...     time_varying=[[], ["L2"]],
...     outcome_learner=GLM(family="binomial"),
...     treatment_learner=GLM(family="binomial"),
...     n_folds=2,
...     random_state=0,
... )
>>> "ey_reference" in result
True