Documentation
¶
Overview ¶
Package prediction provides causal prediction methods including DoubleML, naive adjustment regression, and instrumental variable regression.
Index ¶
- type DoubleMLRegressor
- func (d *DoubleMLRegressor) ATE() float64
- func (d *DoubleMLRegressor) ConfidenceInterval(alpha float64) (float64, float64)
- func (d *DoubleMLRegressor) EstimateCate() ([]float64, error)
- func (d *DoubleMLRegressor) Fit(data *tabgo.DataFrame) error
- func (d *DoubleMLRegressor) PValue() float64
- func (d *DoubleMLRegressor) Predict(data *tabgo.DataFrame) ([]float64, error)
- func (d *DoubleMLRegressor) SE() float64
- func (d *DoubleMLRegressor) SetNSplits(n int)
- func (d *DoubleMLRegressor) Summary() string
- type NaiveAdjustmentRegressor
- func (r *NaiveAdjustmentRegressor) ATE() float64
- func (r *NaiveAdjustmentRegressor) ConfidenceInterval(alpha float64) (float64, float64)
- func (r *NaiveAdjustmentRegressor) Fit(data *tabgo.DataFrame) error
- func (r *NaiveAdjustmentRegressor) PValue() float64
- func (r *NaiveAdjustmentRegressor) Predict(data *tabgo.DataFrame) ([]float64, error)
- func (r *NaiveAdjustmentRegressor) SE() float64
- func (r *NaiveAdjustmentRegressor) Summary() string
- type NaiveIVRegressor
- func (r *NaiveIVRegressor) ATE() float64
- func (r *NaiveIVRegressor) ConfidenceInterval(alpha float64) (float64, float64)
- func (r *NaiveIVRegressor) FirstStageFStat() float64
- func (r *NaiveIVRegressor) Fit(data *tabgo.DataFrame) error
- func (r *NaiveIVRegressor) PValue() float64
- func (r *NaiveIVRegressor) Predict(data *tabgo.DataFrame) ([]float64, error)
- func (r *NaiveIVRegressor) SE() float64
- func (r *NaiveIVRegressor) Summary() string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DoubleMLRegressor ¶
type DoubleMLRegressor struct {
// contains filtered or unexported fields
}
DoubleMLRegressor implements Double Machine Learning for causal effect estimation. It uses cross-fitting with configurable number of folds to estimate the Average Treatment Effect (ATE).
func NewDoubleMLRegressor ¶
func NewDoubleMLRegressor(treatment, outcome string, confounders []string) *DoubleMLRegressor
NewDoubleMLRegressor creates a new DoubleMLRegressor. It defaults to 2-fold cross-fitting. Use SetNSplits to change.
func (*DoubleMLRegressor) ATE ¶
func (d *DoubleMLRegressor) ATE() float64
ATE returns the estimated Average Treatment Effect.
func (*DoubleMLRegressor) ConfidenceInterval ¶
func (d *DoubleMLRegressor) ConfidenceInterval(alpha float64) (float64, float64)
ConfidenceInterval returns the (lower, upper) bounds of a confidence interval for the ATE at the given significance level alpha (e.g., 0.05 for 95% CI). Uses a normal approximation.
func (*DoubleMLRegressor) EstimateCate ¶
func (d *DoubleMLRegressor) EstimateCate() ([]float64, error)
EstimateCate estimates conditional average treatment effects (CATE) for each observation. It computes observation-level treatment effects as: cate_i = yResid_i / tResid_i, smoothed by local weighting. For a linear DML model, the CATE is constant and equals the ATE; this method returns per-observation influence-weighted effects.
func (*DoubleMLRegressor) Fit ¶
func (d *DoubleMLRegressor) Fit(data *tabgo.DataFrame) error
Fit performs DML estimation with cross-fitting on the given data.
Algorithm (K-fold cross-fitting):
- Split data into K folds.
- For each fold k: train outcome and treatment models on all other folds, compute residuals on fold k.
- Pool all residuals and estimate ATE as the OLS coefficient of treatment residuals on outcome residuals (no intercept).
- Compute standard error from residuals.
func (*DoubleMLRegressor) PValue ¶
func (d *DoubleMLRegressor) PValue() float64
PValue returns the two-sided p-value for testing H0: ATE = 0.
func (*DoubleMLRegressor) Predict ¶
func (d *DoubleMLRegressor) Predict(data *tabgo.DataFrame) ([]float64, error)
Predict returns counterfactual outcome predictions for each row: predicted_outcome = ATE * treatment_value. This is a simplified prediction that applies the estimated treatment effect.
func (*DoubleMLRegressor) SE ¶
func (d *DoubleMLRegressor) SE() float64
SE returns the standard error of the ATE estimate.
func (*DoubleMLRegressor) SetNSplits ¶
func (d *DoubleMLRegressor) SetNSplits(n int)
SetNSplits sets the number of cross-fitting folds. Must be >= 2.
func (*DoubleMLRegressor) Summary ¶
func (d *DoubleMLRegressor) Summary() string
Summary returns a formatted summary string with ATE, SE, CI, and p-value.
type NaiveAdjustmentRegressor ¶
type NaiveAdjustmentRegressor struct {
// contains filtered or unexported fields
}
NaiveAdjustmentRegressor implements naive back-door adjustment for causal effect estimation via OLS regression: outcome ~ treatment + adjustmentSet.
func NewNaiveAdjustmentRegressor ¶
func NewNaiveAdjustmentRegressor(treatment, outcome string, adjustmentSet []string) *NaiveAdjustmentRegressor
NewNaiveAdjustmentRegressor creates a new NaiveAdjustmentRegressor.
func (*NaiveAdjustmentRegressor) ATE ¶
func (r *NaiveAdjustmentRegressor) ATE() float64
ATE returns the estimated Average Treatment Effect, which is the OLS coefficient on the treatment variable.
func (*NaiveAdjustmentRegressor) ConfidenceInterval ¶
func (r *NaiveAdjustmentRegressor) ConfidenceInterval(alpha float64) (float64, float64)
ConfidenceInterval returns (lower, upper) bounds for the ATE at significance level alpha.
func (*NaiveAdjustmentRegressor) Fit ¶
func (r *NaiveAdjustmentRegressor) Fit(data *tabgo.DataFrame) error
Fit performs OLS regression: outcome ~ intercept + treatment + adjustmentSet.
func (*NaiveAdjustmentRegressor) PValue ¶
func (r *NaiveAdjustmentRegressor) PValue() float64
PValue returns the two-sided p-value for testing H0: ATE = 0.
func (*NaiveAdjustmentRegressor) Predict ¶
func (r *NaiveAdjustmentRegressor) Predict(data *tabgo.DataFrame) ([]float64, error)
Predict returns predicted outcome values for each row.
func (*NaiveAdjustmentRegressor) SE ¶
func (r *NaiveAdjustmentRegressor) SE() float64
SE returns the standard error of the ATE estimate.
func (*NaiveAdjustmentRegressor) Summary ¶
func (r *NaiveAdjustmentRegressor) Summary() string
Summary returns a formatted summary string.
type NaiveIVRegressor ¶
type NaiveIVRegressor struct {
// contains filtered or unexported fields
}
NaiveIVRegressor implements instrumental variable regression using two-stage least squares (2SLS) for causal effect estimation.
func NewNaiveIVRegressor ¶
func NewNaiveIVRegressor(treatment, outcome string, instruments []string) *NaiveIVRegressor
NewNaiveIVRegressor creates a new NaiveIVRegressor.
func (*NaiveIVRegressor) ATE ¶
func (r *NaiveIVRegressor) ATE() float64
ATE returns the estimated Average Treatment Effect from 2SLS.
func (*NaiveIVRegressor) ConfidenceInterval ¶
func (r *NaiveIVRegressor) ConfidenceInterval(alpha float64) (float64, float64)
ConfidenceInterval returns (lower, upper) bounds for the ATE at significance level alpha.
func (*NaiveIVRegressor) FirstStageFStat ¶
func (r *NaiveIVRegressor) FirstStageFStat() float64
FirstStageFStat returns the F-statistic from the first stage regression, testing whether the instruments are jointly significant predictors of treatment. A value > 10 is typically considered evidence of strong instruments.
func (*NaiveIVRegressor) Fit ¶
func (r *NaiveIVRegressor) Fit(data *tabgo.DataFrame) error
Fit performs two-stage least squares:
Stage 1: treatment ~ intercept + instruments (OLS) -> predicted treatment Stage 2: outcome ~ intercept + predicted_treatment (OLS) -> ATE
func (*NaiveIVRegressor) PValue ¶
func (r *NaiveIVRegressor) PValue() float64
PValue returns the two-sided p-value for testing H0: ATE = 0.
func (*NaiveIVRegressor) Predict ¶
func (r *NaiveIVRegressor) Predict(data *tabgo.DataFrame) ([]float64, error)
Predict returns predicted outcome values: intercept + ATE * treatment.
func (*NaiveIVRegressor) SE ¶
func (r *NaiveIVRegressor) SE() float64
SE returns the standard error of the ATE estimate.
func (*NaiveIVRegressor) Summary ¶
func (r *NaiveIVRegressor) Summary() string
Summary returns a formatted summary string.