# `causalis.dgp.causaldata.preperiod`

## Module Contents

### Classes

`PreCorrSpec` |

### Functions

`corr_on_scale` |
`calibrate_sigma_for_target_corr` | Find sigma such that Corr(T(y_pre_base + sigma*eps), T(y_post)) ~ target_corr. Returns (sigma, achieved_corr).
`add_preperiod_covariate` | Standardized utility to add a calibrated pre-period covariate to a DataFrame.

### Data

`CorrMethod` |
`Transform` |

### API

causalis.dgp.causaldata.preperiod.CorrMethod

  None

causalis.dgp.causaldata.preperiod.Transform

  None

causalis.dgp.causaldata.preperiod.corr_on_scale(y_pre: numpy.ndarray, y_post: numpy.ndarray, *, transform: causalis.dgp.causaldata.preperiod.Transform = 'log1p', winsor_q: Optional[float] = 0.999, method: causalis.dgp.causaldata.preperiod.CorrMethod = 'pearson') → float

class causalis.dgp.causaldata.preperiod.PreCorrSpec
  target_corr: float

    0.7

  transform: causalis.dgp.causaldata.preperiod.Transform

    ‘log1p’

  winsor_q: Optional[float]

    0.999

  method: causalis.dgp.causaldata.preperiod.CorrMethod

    ‘pearson’

  sigma_lo: float

    0.0

  sigma_hi: float

    50.0

  sigma_tol: float

    0.001

  max_iter: int

    40

causalis.dgp.causaldata.preperiod.calibrate_sigma_for_target_corr(y_pre_base: numpy.ndarray, y_post: numpy.ndarray, rng: numpy.random.Generator, spec: causalis.dgp.causaldata.preperiod.PreCorrSpec, *, noise: Optional[numpy.ndarray] = None) → Tuple[float, float]

  Find sigma such that Corr(T(y_pre_base + sigma*eps), T(y_post)) ~ target_corr. Returns (sigma, achieved_corr).

causalis.dgp.causaldata.preperiod.add_preperiod_covariate(df: pandas.DataFrame, y_col: str, d_col: str, pre_name: str, base_builder: Callable[[pandas.DataFrame], numpy.ndarray], spec: causalis.dgp.causaldata.preperiod.PreCorrSpec, rng: numpy.random.Generator, mask: Optional[numpy.ndarray] = None) → pandas.DataFrame

  Standardized utility to add a calibrated pre-period covariate to a DataFrame.

  Parameters

  df : pd.DataFrame The dataset. y_col : str Name of the outcome column. d_col : str Name of the treatment column. pre_name : str Name of the new pre-period covariate column. base_builder : callable Function df -> y_pre_base (np.ndarray) providing the shared signal. spec : PreCorrSpec Specification for target correlation and scale. rng : np.random.Generator Random number generator. mask : np.ndarray, optional Boolean mask of rows to use for calibration (e.g. control group). If None, use control group (d == 0).