mcf_main.ModifiedCausalForest.predict#

ModifiedCausalForest.predict(data_df, new_keywords=None, exit_after_commonsupport=False)#

Compute all effects.

meth:~ModifiedCausalForest.train method must be run beforehand.

Parameters:
  • data_df (DataFrame) – Data used to compute the predictions. It must contain information about features (and treatment if effects for treatment specific subpopulations are desired as well).

  • new_keywords (Dictionary (or None). Default is None.) –

    Parameters of mcf instance to be changed. The keys in the dictionary are the parameters to be changed when running this method (and all methods that are run subsequently, like analyse or sensitivity), and the values corresponding to the keys are the new value (None is allowed only for ignored variable-name entries; see below). However, not all parameters can differ from those used during training. The following parameters can be changed, and thus specified as keys in this dictionary (some of these will however not influence the results of this method, but of other other used with the same instance): ‘cs_type’ (can only be changed to 0, use only if prediction data are already on common

    support);

    ’gen_output_type’; ‘var_x_name_balance_test_ord’, ‘var_x_name_balance_test_unord’, ‘var_x_name_balance_bgate’, ‘var_x_name_ba’, ‘var_z_name_ord’, ‘var_z_name_unord’, ‘p_ba’, ‘p_ba_adj_method’, ‘p_ba_pos_weights_only’, ‘p_ba_use_x’, ‘p_ba_use_prop_score’, ‘p_ba_use_prog_score’, ‘p_ba_ridge’, ‘p_ate_no_se_only’, ‘p_atet’, ‘p_gatet’, ‘p_bgate’, ‘p_cbgate’, ‘p_iate’, ‘p_iate_se’, ‘p_iate_m_ate’, ‘p_bgate_sample_share’, ‘p_gates_minus_previous’, ‘p_gates_smooth_bandwidth’, ‘p_gates_smooth’, ‘p_gates_smooth_no_evalu_points’, ‘p_gates_no_evalu_points’, ‘p_qiate’, ‘p_qiate_se’, ‘p_qiate_m_mqiate’, ‘p_qiate_m_opp’, ‘p_qiate_no_of_quantiles’, ‘p_qiate_smooth’, ‘p_qiate_smooth_bandwidth’, ‘p_qiate_bias_adjust’, ‘p_bt_yes’, ‘p_choice_based_sampling’, ‘p_choice_based_probs’, ‘p_cond_var’, ‘p_knn’, ‘p_knn_const’, ‘p_knn_min_k’, ‘p_nw_bandw’, ‘p_nw_kern’, ‘p_ci_level’, ‘p_se_boot_ate’, ‘p_se_boot_gate’, ‘p_se_boot_iate’, ‘p_se_boot_qiate’; ‘post_bin_corr_threshold’, ‘post_bin_corr_yes’, ‘post_est_stats’, ‘post_kmeans_yes’, ‘post_kmeans_no_of_groups’, ‘post_kmeans_max_tries’, ‘post_kmeans_min_size_share’, ‘post_kmeans_replications’, ‘post_kmeans_single’, ‘post_random_forest_vi’, ‘post_relative_to_first_group_only’, ‘post_plots’, ‘post_tree’. For ‘p_ba’, ‘p_ba_use_prop_score’, ‘p_ba_use_prog_score’, ‘p_qiate’, ‘p_qiate_se’ and ‘p_bt_yes’, new_keywords accepts only False. Passing True raises ValueError, even if the flag is already enabled on the instance. The additional key ‘no_treatment_versions’ disables prediction for treatment versions, even if versions were used during training. Its value is currently ignored: any value other than None, including False, triggers this change. None raises ValueError. Omit the key to retain prediction for treatment versions. A dictionary, including {}, is accepted only before the first prediction on an instance already used for training. Otherwise, ValueError is raised. For repeated predictions with different settings, create copies of the trained instance with copy.deepcopy() before its first prediction. None skips this check. Updates to variable names require a list or tuple of strings, even for one variable. Names are casefolded and must match the feature lists stored in the trained instance. ‘var_x_name_balance_test_ord’ and ‘var_z_name_ord’ require ordered features; ‘var_x_name_balance_test_unord’ and ‘var_z_name_unord’ require unordered features. ‘var_x_name_balance_bgate’ and ‘var_x_name_ba’ accept either feature type. Variable-name entries are checked only when their use is enabled after all updates. ‘var_x_name_ba’ requires both ‘p_ba’ and ‘p_ba_use_x’; an active selection must equal the trained set. Changing that set requires retraining. The balancing-test lists require ‘p_bt_yes’. ‘var_x_name_balance_bgate’ requires ‘p_bgate’ and enabled GATEs; CBGATEs do not use this balancing list. ‘p_ate_no_se_only’ disables checks of grouping and balancing-variable updates. Inactive entries, including None, are ignored and the stored lists are retained. Dictionary order does not affect which variable-name entries are checked. For unordered features, supply original names; the internal ‘_prime’ suffix is added.

  • exit_after_commonsupport (Boolean, optional) – If True, stop after common-support processing without estimating effects. Return the processed prediction data in ‘inputdata_on_support’. The default is False.

Returns:

results – Contains the results. The descriptions of ‘gate_diff’, ‘bgate_diff’ and ‘cbgate_diff’ below assume ‘p_gates_minus_previous’ is False. If True, these entries compare each evaluation point with its predecessor; the first point has no preceding comparison. Their ‘_diff_se’ entries contain the corresponding standard errors. Entries for GATEs, BGATEs, CBGATEs, QIATEs and balancing tests are None when that estimation is disabled, including their standard errors and effect differences. ‘gate_names_values’ is None when all three GATE variants are disabled. The dictionary has the following structure: ‘ate’: ATE, ‘ate_se’: Standard error of ATE. None if exit_after_commonsupport is True. ‘ate_effect_list’: List of names of estimated effects. None if exit_after_commonsupport

is True.

’gate’: GATE, ‘gate_se’: SE of GATE. None if exit_after_commonsupport is True. ‘gate_diff’: GATE minus ATE. None if exit_after_commonsupport is True. ‘gate_diff_se’: Standard error of GATE minus ATE. None if exit_after_commonsupport is

True.

’cbgate’: cbGATE (all covariates balanced). None if exit_after_commonsupport is True. ‘cbgate_se’: Standard error of CBGATE. None if exit_after_commonsupport is True. ‘cbgate_diff’: CBGATE minus ATE. None if exit_after_commonsupport is True. ‘cbgate_diff_se’: Standard error of CBGATE minus ATE. None if exit_after_commonsupport

is True.

’bgate’: BGATE (only prespecified covariates balanced). None if exit_after_commonsupport

is True.

’bgate_se’: Standard error of BGATE. None if exit_after_commonsupport is True. ‘bgate_diff’: BGATE minus ATE. None if exit_after_commonsupport is True. ‘bgate_diff_se’: Standard errror of BGATE minus ATE. None if exit_after_commonsupport

is True.

’gate_names_values’: Dictionary: Order of gates parameters and name and values of GATE

effects.

None if exit_after_commonsupport is True. ‘qiate’: QIATE, ‘qiate_se’: Standard error of QIATEs. None if exit_after_commonsupport

is True.

’qiate_mmed’: QIATE(q) - QIATE(0.5).

None if not computed or exit_after_commonsupport is True.

’qiate_mmed_se’: Standard errors of qiate_mmed.

None if not computed or exit_after_commonsupport is True.

’qiate_mopp’: QIATE(q) - QIATE(1 - q).

None if not computed or exit_after_commonsupport is True.

’qiate_mopp_se’: Standard errors of qiate_mopp.

None if not computed or exit_after_commonsupport is True.

’iate’: NumPy array or None

Individual effects with shape (N, Y, C, 2): retained prediction observations, outcomes, treatment comparisons, and effect type. The last axis contains IATEs at index 0 and IATE-minus-ATE deviations at index 1. Index 1 contains NaN when ‘p_iate_m_ate’ is False. Available even when ‘iate_data_df’ is not returned. None if IATE estimation is disabled or exit_after_commonsupport is True.

’iate_se’: NumPy array or None

Standard errors with the same shape and ordering as ‘iate’. None when ‘p_iate_se’ is False, IATE estimation is disabled, or exit_after_commonsupport is True.

’iate_eff’: Boolean or None

Resolved ‘gen_iate_eff’ flag; indicates whether reported IATEs use both rounds. Returned even when IATE estimation is disabled. None if exit_after_commonsupport is True.

’iate_data_df’: DataFrame or None

Processed prediction data with potential outcomes and IATEs, plus requested standard errors and IATE-minus-ATE results. Contains only observations retained after data preparation and common-support trimming. None if exit_after_commonsupport is True, IATE estimation is disabled, or IATE DataFrame return is disabled. See _int_with_output and _int_return_iate_sp.

’iate_names_dic’: Tuple of two dictionaries or None

Column-name metadata for potential outcomes, IATEs and requested standard errors and IATE-minus-ATE results. Index 0 includes names for all computed effect comparisons. Index 1 restricts effect names to comparisons against the first treatment value; potential-outcome names are unchanged. Entries for unrequested standard errors or IATE-minus-ATE results are None. Returned even when IATE DataFrame return is disabled. None if IATE estimation is disabled or exit_after_commonsupport is True.

’bala’: Effects of balancing tests. None if exit_after_commonsupport is True. ‘bala_se’: Standard error of effects of balancing tests. None if

exit_after_commonsupport is True.

’bala_effect_list’: Names of effects of balancing tests. None if

exit_after_commonsupport is True.

’common_support_probabilities’: DataFrame containing treatment probabilities,

the observation identifier, and an indicator for being on common support. None if _int_with_output is False or cs_type is 0.

’path_output’Path or None

Directory in which output is saved. None if _int_with_output is False.

’inputdata_on_support’: Processed prediction data retained after common-support

processing when exit_after_commonsupport is True; otherwise None.

Return type:

Dictionary.