cleverly.validation.NuisanceDiagnostics#
- class cleverly.validation.NuisanceDiagnostics(models: tuple[NuisanceModelReport, ...], evaluation: EvaluationBasis, n_repeats: int = 1, backend: str | None = None, selection: CTMLESelection | CTMLEOutcomeAdaptiveFit | CTMLEDerivativeFit | None = None, treatment_role: TreatmentModelRole | None = None, repeat_spread: tuple[RepeatSpreadRow, ...] = (), selection_omission: str | None = None, repeat_spread_omission: str | None = None, reported_repeat: int = 1, inference: InferenceStatus = 'influence_curve')[source]#
Fit quality for every nuisance model in a TMLE fit.
The metrics are out-of-fold when the fit cross-fitted its nuisances, and in-sample when it used one fold.
evaluationrecords which.- Parameters:
- models
tupleofNuisanceModelReport One report per fitted nuisance model.
- evaluation{“out_of_fold”, “in_sample”}
Whether the predictions the reports read were made out of fold. The calibration-slope rule tests out-of-fold predictions only, because an unpenalized logistic model with an intercept has an in-sample slope of exactly 1.
- n_repeats
int Cross-fitting draws the fit combined. The reports describe the first.
- backend
strorNone Dataframe backend
to_frame()returns whendatais omitted.- selection
CTMLESelectionorCTMLEOutcomeAdaptiveFitorCTMLEDerivativeFitorNone The fitted
CTMLESelection,CTMLEOutcomeAdaptiveFitorCTMLEDerivativeFit.Nonemeans the method is not collaborative, or the stored artifact is unavailable.- treatment_role
strorNone One of
"estimated_treatment_law","declared_treatment_law"and"collaborative_working_model", orNone: the statistical role of the propensity predictions inmodels. A collaborative working mechanism is not the complete treatment law. A declared treatment law is the known mechanism the data declares, and its rows compare that declaration with the observed treatment rather than describe a fitted model.- repeat_spread
tupleofRepeatSpreadRow One descriptive split-sensitivity row per reported parameter. A one-draw fit retains an empty tuple rather than a false zero spread.
- selection_omission
strorNone Machine-readable reason an expected C-TMLE artifact is absent.
- repeat_spread_omission
strorNone Machine-readable reason no split-spread row is available.
- reported_repeat
int One-based draw described by the nuisance models and selection artifact.
- inference
str The inference status the fit’s estimates declare. One of
InferenceStatus, which the inference reference lists. Read here rather than offtreatment_role, which reads"collaborative_working_model"for the outcome-adaptive path as well, and that path has a status of its own.
- models
Methods#
- NuisanceDiagnostics.calibration_frame(name: str, data: Any = None) Any[source]#
Binned observed-vs-predicted table for one model.
- Parameters:
- name
str Which nuisance model to tabulate.
- data
Any A dataframe or fitted container whose backend to match.
Noneuses the backend recorded on this object.
- name
- Returns:
dataframeOne row per bin, with the mean prediction and the observed rate in it.
- NuisanceDiagnostics.repeat_spread_frame(data: Any = None) Any[source]#
Return one split-sensitivity row per reported parameter.
- Parameters:
- data
Any A dataframe or fitted container whose backend to match.
Noneuses the backend recorded on this object.
- data
- Returns:
dataframeParameter aliases, draw counts, split standard deviations, reported standard errors, and their descriptive ratios. A fit that supplies no inference names the last two columns
plugin_standard_errorandratio_to_plugin_standard_error, because the number is its plug-in diagnostic and not a standard error.
- NuisanceDiagnostics.summary() str[source]#
Return a printable summary.
- Returns:
strA printable table, one line per nuisance model.
- NuisanceDiagnostics.to_frame(data: Any = None) Any[source]#
Return tabular output in the input dataframe backend.
- Parameters:
- data
Any A dataframe or fitted container whose backend to match.
Noneuses the backend recorded on this object.
- data
- Returns:
dataframeOne row per nuisance model, with its fit metrics.
Attributes#
- NuisanceDiagnostics.backend: str | None = None#
Name of the dataframe backend the fit’s data arrived in, so that
to_frame()honours “results come back in the backend you passed in” without a caller having to thread the container back in by hand.
- NuisanceDiagnostics.findings#
Return findings that meet an existing diagnostic warning rule.
- NuisanceDiagnostics.inference: InferenceStatus = 'influence_curve'#
Keyed on what the estimates declare rather than on
treatment_role, which cannot tell a selector path from the outcome-adaptive one.
- NuisanceDiagnostics.inference_note#
The fact a report adds when the fit’s estimates carry a labelled status.
The assessment note the status table records for a fit whose estimates declare a labelled status, shown or withheld, and
Noneotherwise. Keyed oninferenceand not ontreatment_role, which the outcome-adaptive path shares, and that path has a status of its own.summary()and the assessment’s nuisance-model row both read it here.
- NuisanceDiagnostics.n_repeats: int = 1#
How many cross-fitting draws the fit combined. The reports above describe the first draw, for the reason
n_repeatsgives: a model’s out-of-fold calibration is a property of that model, and one fitted under a different split is a different model rather than another measurement of the same one. Averaging their AUCs would report a number no model achieved.
- NuisanceDiagnostics.repeat_spread: tuple[RepeatSpreadRow, ...] = ()#
Unlike the nuisance models and selection, these rows read every retained draw.
- NuisanceDiagnostics.reported_repeat: int = 1#
Nuisance models and the selection artifact describe this draw. One is the only draw the fitted result retains method-specific extras for.
- NuisanceDiagnostics.selection: CTMLESelection | CTMLEOutcomeAdaptiveFit | CTMLEDerivativeFit | None = None#
The exact method object already retained by the fitted result. Selector paths keep every candidate and risk rather than flattening the selected index into prose.
- NuisanceDiagnostics.treatment_role: TreatmentModelRole | None = None#
The propensity report’s role. The role changes its interpretation, not its values.
- NuisanceDiagnostics.models: tuple[NuisanceModelReport, ...]#
- NuisanceDiagnostics.evaluation: EvaluationBasis#