TransferFunctionOLS#
- class causalpy.skl_models.TransferFunctionOLS[source]#
OLS model with transfer functions for graded interventions.
This model supports: - HAC (Newey-West) standard errors for robust inference (default) - ARIMAX error models for explicit autocorrelation modeling - Saturation and adstock transforms for treatment effects
This model is designed to work with the GradedInterventionTimeSeries experiment class following the standard CausalPy pattern where the experiment handles data preparation and calls model.fit().
- Parameters:
saturation_type (str, default="hill") – Type of saturation function: “hill”, “logistic”, or “michaelis_menten”.
saturation_grid (dict, optional) – For grid search: dict mapping parameter names to lists of values. E.g., {“slope”: [1.0, 2.0], “kappa”: [3, 5]}.
saturation_bounds (dict, optional) – For optimization: dict mapping parameter names to (min, max) tuples. E.g., {“slope”: (0.5, 5.0), “kappa”: (2, 10)}.
adstock_grid (dict, optional) – For grid search: dict mapping parameter names to lists of values. E.g., {“half_life”: [2, 3, 4]}.
adstock_bounds (dict, optional) – For optimization: dict mapping parameter names to (min, max) tuples. E.g., {“half_life”: (1, 10)}.
estimation_method (str, default="grid") – Method for parameter estimation: “grid” or “optimize”.
error_model (str, default="hac") – Error model specification: “hac” or “arimax”.
arima_order (tuple of (int, int, int), optional) – ARIMA order (p, d, q) when error_model=”arimax”.
hac_maxlags (int, optional) – Maximum lags for HAC standard errors.
coef_constraint (str, default="nonnegative") – Constraint on treatment coefficients.
- ols_result#
Fitted OLS or ARIMAX model result.
- Type:
statsmodels regression result
- treatments#
Treatment specifications with transform objects.
- Type:
List[Treatment]
- coef_#
Model coefficients (for sklearn compatibility).
- Type:
np.ndarray
Examples
# Create unfitted model with configuration model = cp.skl_models.TransferFunctionOLS( saturation_type="hill", saturation_grid={"slope": [1.0, 2.0], "kappa": [3, 5]}, adstock_grid={"half_life": [2, 3, 4]}, estimation_method="grid", error_model="hac", ) # Use with experiment class (experiment calls fit()) result = cp.GradedInterventionTimeSeries( data=df, y_column="outcome", treatment_names=["exposure"], base_formula="1 + t", model=model, )
Methods
TransferFunctionOLS.__init__([...])Initialize model with configuration parameters.
Calculate the cumulative impact intervention.
TransferFunctionOLS.calculate_impact(y_true, ...)Calculate the causal impact of the intervention.
TransferFunctionOLS.fit(X, y)Fit OLS model with HAC/ARIMAX errors.
Get the coefficients of the model as a numpy array.
Get metadata routing of this object.
TransferFunctionOLS.get_params([deep])Get parameters for this estimator.
Predict using the fitted model.
Print the coefficients of the model with the corresponding labels.
TransferFunctionOLS.score(X, y[, sample_weight])Return coefficient of determination on test data.
TransferFunctionOLS.set_params(**params)Set the parameters of this estimator.
TransferFunctionOLS.set_score_request(*[, ...])Configure whether metadata should be requested to be passed to the
scoremethod.- __init__(saturation_type='hill', saturation_grid=None, saturation_bounds=None, adstock_grid=None, adstock_bounds=None, estimation_method='grid', error_model='hac', arima_order=None, hac_maxlags=None, coef_constraint='nonnegative')[source]#
Initialize model with configuration parameters.
- classmethod __new__(*args, **kwargs)#