causal_testing.estimation.ipcw_estimator

This module contains the IPCWEstimator class, for estimating the time to a particular event

Module Contents

Classes

IPCWEstimator

Class to perform Inverse Probability of Censoring Weighting (IPCW) estimation

Attributes

logger

causal_testing.estimation.ipcw_estimator.logger
class causal_testing.estimation.ipcw_estimator.IPCWEstimator(df: pandas.DataFrame, timesteps_per_observation: int, control_strategy: list[tuple[int, str, Any]], treatment_strategy: list[tuple[int, str, Any]], outcome: causal_testing.specification.variable.Variable, status_column: str, fit_bl_switch_formula: str, fit_bltd_switch_formula: str, eligibility=None, alpha: float = 0.05, total_time: float = None)

Bases: causal_testing.estimation.abstract_estimator.Estimator

Class to perform Inverse Probability of Censoring Weighting (IPCW) estimation for sequences of treatments over time-varying data.

Param:

df: Input DataFrame containing time-varying data.

Param:

timesteps_per_observation: Number of timesteps per observation.

Param:

control_strategy: The control strategy, with entries of the form (timestep, variable, value).

Param:

treatment_strategy: The treatment strategy, with entries of the form (timestep, variable, value).

Param:

outcome: Name of the outcome column in the DataFrame.

Param:

status_column: Name of the status column in the DataFrame, which should be True for operating normally, False for a fault.

Param:

fit_bl_switch_formula: Formula for fitting the baseline switch model.

Param:

fit_bltd_switch_formula: Formula for fitting the baseline time-dependent switch model.

Param:

eligibility: Function to determine eligibility for treatment. Defaults to None for “always eligible”.

Param:

alpha: Significance level for hypothesis testing. Defaults to 0.05.

Param:

total_time: Total time for the analysis. Defaults to one plus the length of of the strategy (control or treatment) with the most elements multiplied by timesteps_per_observation.

add_modelling_assumptions()

Add modelling assumptions to the estimator. This is a list of strings which list the modelling assumptions that must hold if the resulting causal inference is to be considered valid.

setup_xo_t_do(individual: pandas.DataFrame, strategy_assigned: list)

Return a binary sequence with each bit representing whether the current index is the time point at which the individual diverted from the assigned treatment strategy (and thus should be censored).

Parameters:
  • individual – DataFrame representing the individual.

  • strategy_assigned – The assigned treatment strategy.

setup_fault_t_do(individual: pandas.DataFrame)

Return a binary sequence with each bit representing whether the current index is the time point at which the event of interest (i.e. a fault) occurred.

N.B. This is rounded _up_ to the nearest multiple of self.timesteps_per_observation. That is, if the fault occurs at time 22, and self.timesteps_per_observation == 5, then fault_t_do will be 25.

setup_fault_time(individual: pandas.DataFrame, perturbation: float = -0.001)

Return the time at which the event of interest (i.e. a fault) occurred.

preprocess_data()

Set up the treatment-specific columns in the data that are needed to estimate the hazard ratio.

estimate_hazard_ratio() causal_testing.estimation.effect_estimate.EffectEstimate

Estimate the hazard ratio.