:py:mod:`causal_testing.estimation.ipcw_estimator` ================================================== .. py:module:: causal_testing.estimation.ipcw_estimator .. autoapi-nested-parse:: This module contains the IPCWEstimator class, for estimating the time to a particular event Module Contents --------------- Classes ~~~~~~~ .. autoapisummary:: causal_testing.estimation.ipcw_estimator.IPCWEstimator Attributes ~~~~~~~~~~ .. autoapisummary:: causal_testing.estimation.ipcw_estimator.logger .. py:data:: logger .. py:class:: 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: :py:obj:`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`. .. py:method:: 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. .. py:method:: 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). :param individual: DataFrame representing the individual. :param strategy_assigned: The assigned treatment strategy. .. py:method:: 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. .. py:method:: setup_fault_time(individual: pandas.DataFrame, perturbation: float = -0.001) Return the time at which the event of interest (i.e. a fault) occurred. .. py:method:: preprocess_data() Set up the treatment-specific columns in the data that are needed to estimate the hazard ratio. .. py:method:: estimate_hazard_ratio() -> causal_testing.estimation.effect_estimate.EffectEstimate Estimate the hazard ratio.