riantr/moonbit_dowhy/estimators does not have a README file

    CausalEstimator

    pub struct CausalEstimator {
    target_estimand :
    IdentifiedEstimand

    kind : EstimatorKind
    weighting_scheme : WeightingScheme
    min_ps_score : Double
    max_ps_score : Double
    num_strata : NumStrata
    clipping_threshold : Int
    instrument_name : String
    rd_variable_name : String
    rd_threshold_value : Double
    rd_bandwidth : Double
    rd_local_data :
    DataFrame
    ?
    model :
    OlsFit

    first_stage : TwoStageModel?
    second_stage : TwoStageModel?
    glm_model :
    GlmFit

    glm_family :
    GlmFamily

    encoders :
    Encoders

    features : Array[String]
    propensities : Array[Double]
    propensity_beta : Array[Double]
    adjustment_names : Array[String]
    effect_modifier_names : Array[String]
    treatment_name : String
    outcome_name : String
    treatment_value : Double
    control_value : Double
    confidence_level : Double
    num_simulations : Int
    sample_size_fraction : Double
    compute_confidence_intervals : Bool
    test_significance : Bool
    num_matches_per_unit : Int
    distance_metric : DistanceMetric
    }

    A causal estimator.

    The estimator owns the identified estimand and the state that fit produced; estimate_effect turns a data frame into a CausalEstimate.

    CausalEstimator::adjustment_set

    fn CausalEstimator::adjustment_set(self : CausalEstimator) -> Array[String]

    The adjustment variables the estimator uses.

    CausalEstimator::base

    The base estimator of the upstream.

    This is the port of the base class CausalEstimator of the upstream, whose placeholder methods raise a NotImplementedError. The port reports the placeholders with the predicates supports_do_operator and supports_symbolic_estimator and with a None return, because MoonBit cannot catch the abort of a method.

    The upstream builds its base estimator without an estimand. The port needs one for every estimator, so the base takes the estimand it reports with.

    CausalEstimator::control_value

    fn CausalEstimator::control_value(self : CausalEstimator) -> Double

    The treatment value of the control arm.

    The E-value analysis of the refuters package needs it, because the contrast of the treatment scales the estimate of the upstream.

    CausalEstimator::design_features

    fn CausalEstimator::design_features(self : CausalEstimator) -> Array[String]

    The columns of the design matrix of a regression based estimator, in order.

    The first column is the column of ones of the intercept, the next one is the treatment and the last ones are the adjustment variables and the effect modifiers, the way build_design_matrix builds them.

    CausalEstimator::distance_matching

    fn CausalEstimator::distance_matching(estimand :
    IdentifiedEstimand
    , num_matches_per_unit? : Int, distance_metric? : DistanceMetric) -> CausalEstimator

    A distance matching estimator for the given estimand.

    The estimator matches every unit of the treated arm with the units of the control arm whose common causes are the closest ones, and the effect is the difference of the outcomes of the matched units.

    The number of the matches per unit and the distance metric are the two parameters of the upstream: the upstream takes the number of the matches from its num_matches_per_unit and the metric from its distance_metric.

    CausalEstimator::distance_matching_error

    fn CausalEstimator::distance_matching_error(self : CausalEstimator, data :
    DataFrame
    ) -> String?

    The message of the error the upstream raises when the distance matching estimator does not fit the data.

    The upstream raises an exception when the treatment is not binary and when the estimand has no common cause. MoonBit cannot catch the abort of a function, so the port reports the two cases with this function, which returns None when the estimator fits the data.

    CausalEstimator::do_operator

    fn CausalEstimator::do_operator(self : CausalEstimator, x : Double, data :
    DataFrame
    ) -> Double?

    The mean of the outcome when the treatment is set to the given value.

    This is the port of dowhy.causal_estimator.CausalEstimator.do, which returns the mean of the interventional outcomes of the data: the value of the outcome under the intervention, and not the difference between the two arms.

    The upstream keeps the data it was fitted on and reads it when the caller gives none. The port keeps no data in the estimator, so the data is an argument.

    The name of the upstream is do, and do is a reserved word of the toolchain, so the port calls the method do_operator.

    The base estimator of the upstream does not implement the do operator and raises a NotImplementedError when it is called, so the port gives None for it.

    CausalEstimator::doubly_robust

    fn CausalEstimator::doubly_robust(estimand :
    IdentifiedEstimand
    , min_ps_score : Double, max_ps_score : Double) -> CausalEstimator

    A doubly robust estimator.

    CausalEstimator::effect_modifiers

    fn CausalEstimator::effect_modifiers(self : CausalEstimator) -> Array[String]

    The effect modifiers the estimator uses.

    The bootstrap refuter perturbs them, the way the upstream does.

    CausalEstimator::estimand

    The estimand the estimator was built for.

    CausalEstimator::estimate_conditional_effects

    fn CausalEstimator::estimate_conditional_effects(self : CausalEstimator, data :
    DataFrame
    , treatment_value : Double, control_value : Double) -> Array[(String, Double)]

    The conditional estimates of the effect, one per group of the effect modifier.

    The key of a group is the value of the discretised effect modifier, or the values of the discretised effect modifiers when there is more than one. The list is empty when the estimator has no effect modifier, which is what the upstream reports as a None.

    CausalEstimator::estimate_effect

    fn CausalEstimator::estimate_effect(self : CausalEstimator, data :
    DataFrame
    , treatment_value : Double, control_value : Double, target_units : String) ->
    CausalEstimate

    Estimate the treatment effect.

    target_units is one of "ate", "att" or "atc".

    CausalEstimator::estimator_kind

    fn CausalEstimator::estimator_kind(self : CausalEstimator) -> EstimatorKind

    The algorithm of the estimator.

    CausalEstimator::fit

    fn CausalEstimator::fit(self : CausalEstimator, data :
    DataFrame
    , effect_modifier_names : Array[String]) -> Unit

    Fit the estimator on the given data.

    The estimator remembers the adjustment variables of its estimand, fits the model it needs and stores the propensity scores when it uses them.

    CausalEstimator::generalized_linear_model

    A generalised linear model estimator for the given estimand.

    The family decides the link of the model: a binomial family fits a logistic regression, a poisson family fits a count model and the gaussian family fits an ordinary least squares model.

    CausalEstimator::glm_family

    The family of the generalised linear model estimator.

    The E-value analysis of the refuters package needs it, because the conversion of the estimate to the risk ratio scale depends on the family.

    CausalEstimator::glm_model

    The fitted model of the generalised linear model estimator.

    The E-value analysis of the refuters package needs it, because the estimate of a generalised linear model is on the scale of the link of its family.

    CausalEstimator::instrument_name

    fn CausalEstimator::instrument_name(self : CausalEstimator) -> String

    The name of the instrument of an instrumental variable estimator.

    It is empty for every other estimator.

    CausalEstimator::instrumental_variable

    fn CausalEstimator::instrumental_variable(estimand :
    IdentifiedEstimand
    , instrument_name : String) -> CausalEstimator

    An instrumental variable estimator.

    CausalEstimator::intervene

    fn CausalEstimator::intervene(self : CausalEstimator, value : Double, data :
    DataFrame
    ) -> Double

    The mean outcome of the intervention do(treatment = value).

    This is the port of the do operator of the upstream estimators: the treatment is set to the given value in every row of the data and the model predicts the outcome of the modified data.

    CausalEstimator::linear_regression

    An ordinary least squares estimator for the given estimand.

    CausalEstimator::outcome

    fn CausalEstimator::outcome(self : CausalEstimator) -> String

    The outcome column the estimator uses.

    CausalEstimator::propensity_score_matching

    A propensity score matching estimator.

    CausalEstimator::propensity_score_stratification

    fn CausalEstimator::propensity_score_stratification(estimand :
    IdentifiedEstimand
    , num_strata : NumStrata, clipping_threshold : Int) -> CausalEstimator

    A propensity score stratification estimator.

    CausalEstimator::propensity_score_weighting

    fn CausalEstimator::propensity_score_weighting(estimand :
    IdentifiedEstimand
    , min_ps_score : Double, max_ps_score : Double, scheme : WeightingScheme) -> CausalEstimator

    An inverse propensity score weighting estimator.

    CausalEstimator::propensity_scores

    fn CausalEstimator::propensity_scores(self : CausalEstimator) -> Array[Double]

    The propensity scores the estimator computed.

    CausalEstimator::regression_discontinuity

    fn CausalEstimator::regression_discontinuity(estimand :
    IdentifiedEstimand
    , rd_variable_name : String, rd_threshold_value : Double, rd_bandwidth : Double) -> CausalEstimator

    A regression discontinuity estimator.

    CausalEstimator::regression_model

    The fitted model of a regression based estimator.

    The sensitivity analysis of the refuters package needs the coefficients, the standard errors, the t statistics and the degrees of freedom of the fit, which are the numbers the upstream reads from the model of its LinearRegressionEstimator.

    CausalEstimator::set_compute_confidence_intervals

    fn CausalEstimator::set_compute_confidence_intervals(self : CausalEstimator, compute : Bool) -> Unit

    Ask the estimator to compute the confidence intervals.

    CausalEstimator::set_confidence_level

    fn CausalEstimator::set_confidence_level(self : CausalEstimator, level : Double) -> Unit

    Set the confidence level of the intervals.

    CausalEstimator::set_estimand

    Replace the estimand the estimator was built for.

    The refuters use this to estimate a different effect with the same estimator.

    CausalEstimator::set_num_simulations

    fn CausalEstimator::set_num_simulations(self : CausalEstimator, num_simulations : Int) -> Unit

    Set the number of bootstrap simulations.

    CausalEstimator::set_sample_size_fraction

    fn CausalEstimator::set_sample_size_fraction(self : CausalEstimator, fraction : Double) -> Unit

    Set the fraction of the sample a bootstrap resample takes.

    CausalEstimator::set_test_significance

    fn CausalEstimator::set_test_significance(self : CausalEstimator, do_test : Bool) -> Unit

    Ask the estimator to test the significance of the estimate.

    CausalEstimator::strata_labels

    The stratum of every row of the data.

    This is the port of the strata column that the propensity score stratification estimator of the upstream adds to the data. The upstream searches for the number of the strata when its estimator holds the automatic number, and the port searches for it the same way.

    CausalEstimator::supports_do_operator

    fn CausalEstimator::supports_do_operator(self : CausalEstimator) -> Bool

    Whether the estimator has a do operator.

    This is the port of the _do of the upstream. The base estimator of the upstream does not implement it and raises a NotImplementedError when it is called, and so do the estimators of the upstream that do not derive from the regression estimator or from the doubly robust estimator, which are the two classes that implement it.

    The port computes the do operator for every estimator that has a model, so this predicate tells what the upstream does and not what the port does.

    CausalEstimator::supports_symbolic_estimator

    fn CausalEstimator::supports_symbolic_estimator(self : CausalEstimator) -> Bool

    Whether the estimator has a symbolic estimator.

    This is the port of the construct_symbolic_estimator of the upstream. The base estimator of the upstream does not implement it and raises a NotImplementedError when it is called, and every estimator of the upstream that the port covers implements it.

    The port does not build the symbolic estimators, because they are the symbolic expressions of the sympy of the upstream, so this predicate tells what the upstream does and not what the port does.

    CausalEstimator::symbolic_estimator

    fn CausalEstimator::symbolic_estimator(self : CausalEstimator) -> String?

    The symbolic estimator of the estimator.

    The base estimator of the upstream does not build one and raises a NotImplementedError when it is asked for, so the port gives None for it, and so does the port for the instrumental variable estimator, whose symbolic estimator of the upstream holds the expressions of the sympy.

    The regression discontinuity estimator of the upstream builds the empty string, so the port builds the empty string too.

    The upstream builds the symbolic estimator when the estimator is fitted, and the port computes it when it is asked for, so the effect modifiers of the estimator are the ones of its last fit.

    CausalEstimator::treatment

    fn CausalEstimator::treatment(self : CausalEstimator) -> String

    The treatment column the estimator uses.

    CausalEstimator::treatment_value

    fn CausalEstimator::treatment_value(self : CausalEstimator) -> Double

    The treatment value of the treated arm.

    The E-value analysis of the refuters package needs it, because the contrast of the treatment scales the estimate of the upstream.

    CausalEstimator::two_stage_error

    fn CausalEstimator::two_stage_error(self : CausalEstimator) -> String

    The error the two stage regression estimator reports for the estimand of the estimator, or an empty string when it can estimate the effect.

    The upstream raises a ValueError when the estimand holds no mediator variable or more than one, and it raises an Exception when the estimand holds more than one treatment variable or more than one outcome variable. MoonBit cannot catch an error, so the port aborts with the message of the upstream; this function reports the message of the error the upstream raises, so that a caller can check for it before it fits the estimator.

    CausalEstimator::two_stage_features

    fn CausalEstimator::two_stage_features(self : CausalEstimator) -> (Array[String], Array[String])

    The columns of the design matrix of the two stages of the two stage regression estimator.

    The first element holds the columns of the first stage, the one that regresses the mediator on the treatment, and the second one the columns of the second stage, the one that regresses the outcome on the mediator.

    CausalEstimator::two_stage_regression

    A two stage regression estimator.

    CausalEstimator::with_estimand

    A copy of the estimator that estimates a different estimand.

    The refuters use this to re-estimate the effect with the same algorithm on modified data. The copy starts without any fitted state, so the estimator that was handed in keeps the model and the adjustment set it was fitted with.

    CausalEstimator::with_instrument_name

    fn CausalEstimator::with_instrument_name(self : CausalEstimator, name : String) -> CausalEstimator

    A copy of the estimator that uses a different instrument.

    The placebo treatment refuter uses this for the instrumental variable method, whose instrument the placebo replaces.

    DistanceMetric

    pub enum DistanceMetric {
    Minkowski(Double)
    Euclidean
    Manhattan
    Chebyshev
    }

    The distance metric of the distance matching estimator.

    The upstream hands the name of the metric to the NearestNeighbors of scikit-learn, which uses the Minkowski metric with an exponent of two by default. The port supports the Minkowski family, which is the family the upstream uses with its default settings.

    DistanceMetric::chebyshev

    fn DistanceMetric::chebyshev() -> DistanceMetric

    The Chebyshev distance.

    DistanceMetric::euclidean

    fn DistanceMetric::euclidean() -> DistanceMetric

    The Euclidean distance.

    DistanceMetric::manhattan

    fn DistanceMetric::manhattan() -> DistanceMetric

    The Manhattan distance.

    DistanceMetric::minkowski

    fn DistanceMetric::minkowski(exponent : Double) -> DistanceMetric

    The Minkowski metric with the given exponent.

    EstimatorKind

    pub enum EstimatorKind {
    Base
    LinearRegression
    PropensityScoreWeighting
    PropensityScoreMatching
    PropensityScoreStratification
    DoublyRobust
    InstrumentalVariable
    TwoStageRegression
    RegressionDiscontinuity
    GeneralizedLinearModel
    DistanceMatching
    }

    The estimator family that DoWhy offers.

    The kind decides which algorithm fit and estimate_effect run; the estimator itself keeps the fitted state, exactly like the Python classes inherit from CausalEstimator.

    NumStrata

    pub enum NumStrata {
    Fixed(Int)
    Auto
    }

    The number of strata of the propensity score stratification estimator.

    The upstream takes the string "auto", which searches for the number of strata, and an integer, which is the number of strata.

    NumStrata::auto

    fn NumStrata::auto() -> NumStrata

    The number of strata is searched for, the way the upstream searches for it.

    NumStrata::fixed

    fn NumStrata::fixed(count : Int) -> NumStrata

    The given number of strata.

    TwoStageModel

    type TwoStageModel

    One stage of the two stage regression estimator.

    Every stage has its own encoders, because the treatment of the first stage is the column the second stage regresses on.

    WeightingScheme

    pub enum WeightingScheme {
    IpsWeight
    IpsStabilizedWeight
    IpsNormalizedWeight
    }

    The weighting scheme of the propensity score weighting estimator.

    WeightingScheme::ips_normalized_weight

    fn WeightingScheme::ips_normalized_weight() -> WeightingScheme

    The normalised inverse propensity score weighting scheme.

    WeightingScheme::ips_stabilized_weight

    fn WeightingScheme::ips_stabilized_weight() -> WeightingScheme

    The stabilised inverse propensity score weighting scheme.

    WeightingScheme::ips_weight

    fn WeightingScheme::ips_weight() -> WeightingScheme

    The inverse propensity score weighting scheme.

    WeightingScheme::name

    fn WeightingScheme::name(self : WeightingScheme) -> String

    The name of the weighting scheme.

    DEFAULT_CONFIDENCE_LEVEL

    let DEFAULT_CONFIDENCE_LEVEL : Double

    The default confidence level.

    DEFAULT_NUMBER_OF_SIMULATIONS_CI

    let DEFAULT_NUMBER_OF_SIMULATIONS_CI : Int

    The default number of simulations used for the confidence intervals.

    DEFAULT_NUMBER_OF_SIMULATIONS_STAT_TEST

    let DEFAULT_NUMBER_OF_SIMULATIONS_STAT_TEST : Int

    The default number of simulations used for the significance test.

    NUM_QUANTILES_TO_DISCRETIZE_CONT_COLS

    let NUM_QUANTILES_TO_DISCRETIZE_CONT_COLS : Int

    The default number of quantiles a continuous effect modifier is split into.

    default_not_implemented_error_message

    fn default_not_implemented_error_message() -> String

    The message of the error the upstream raises for a method it does not implement.

    This is the port of DEFAULT_NOTIMPLEMENTEDERROR_MSG of the upstream. The upstream puts the class of the estimator in the message.