?>
The bartScoreMargin action computes predictive margins by using a fitted Bayesian additive regression trees (BART) model. Predictive margins are predictions from a model at fixed values of some predictors, averaged over the distribution of the other predictors. This technique is useful for understanding the effect of a specific predictor on the outcome, while accounting for the influence of other variables in the model.
| Parameter | Description |
|---|---|
| alpha | Specifies the significance level for constructing equal-tail credible limits. The default is 0.05. |
| casOut | Specifies the output data table to store the computed predictive margins. |
| differences | Specifies a list of differences between predictive margins to compute. Each difference is defined by a reference margin (refMargin) and an event margin (evtMargin). |
| display | Specifies which result tables to display. By default, all tables are displayed. |
| marginInfo | When set to TRUE, requests a summary table of the variables and their values that define each predictive margin. |
| margins | Specifies one or more predictive margins to compute. Each margin is defined by a name and a set of variable values ('at' subparameter). |
| model | Specifies the CAS table that contains the fitted BART model information, saved from a previous call to the bartGauss or bartProbit action. |
| outputTables | Specifies which result tables to save as CAS tables. |
| seed | Specifies the seed for the pseudorandom number generator to ensure reproducibility. |
| table | Specifies the input data table used for computing the predictive margins. This is typically the same data used to train the model. |
This example first creates a sample dataset 'getStarted' with a binary outcome 'y' and several predictor variables. Then, it fits a Bayesian additive regression trees model for a binary outcome using the `bartProbit` action and saves the model to a CAS table named 'my_bart_model'. This saved model is required for the `bartScoreMargin` action.
data mycas.getStarted;
call streaminit(123);
do i = 1 to 100;
x1 = rand('UNIFORM');
x2 = rand('UNIFORM');
x3 = rand('UNIFORM');
if (i <= 50) then x4 = 'A'; else x4 = 'B';
p = 1 / (1 + exp(-(x1 - 0.5*x2 + 0.2*x3)));
y = rand('BERNOULLI', p);
output;
end;
run;
proc cas;
bart.bartProbit table={name='getStarted'},
model={depVars={{name='y', levelType='BINARY'}},
effects={{vars={'x1', 'x2', 'x3', 'x4'}}}},
store={name='my_bart_model', replace=true};
quit;This example computes a single predictive margin named 'margin_x1_high'. It evaluates the model's prediction when the predictor 'x1' is fixed at a high value (0.9), while averaging over the observed values of all other predictors in the 'getStarted' table.
| 1 | PROC CAS; |
| 2 | bart.bartScoreMargin |
| 3 | TABLE='getStarted', |
| 4 | model='my_bart_model', |
| 5 | margins={{ |
| 6 | name='margin_x1_high', |
| 7 | at={{var='x1', value=0.9}} |
| 8 | }}; |
| 9 | QUIT; |
This example calculates and compares predictive margins for the two levels of the categorical variable 'x4'. It defines two margins, 'margin_x4_A' and 'margin_x4_B', and then computes the difference between them, named 'diff_A_vs_B'. This allows for quantifying the effect of changing 'x4' from 'A' to 'B' on the predicted outcome.
| 1 | PROC CAS; |
| 2 | bart.bartScoreMargin |
| 3 | TABLE='getStarted', |
| 4 | model='my_bart_model', |
| 5 | seed=1234, |
| 6 | alpha=0.1, |
| 7 | margins={{ |
| 8 | name='margin_x4_A', |
| 9 | label='Margin for x4=A', |
| 10 | at={{var='x4', value='A'}} |
| 11 | }, |
| 12 | { |
| 13 | name='margin_x4_B', |
| 14 | label='Margin for x4=B', |
| 15 | at={{var='x4', value='B'}} |
| 16 | }}, |
| 17 | differences={{ |
| 18 | name='diff_A_vs_B', |
| 19 | label='Difference (A vs B)', |
| 20 | refMargin='margin_x4_B', |
| 21 | evtMargin='margin_x4_A' |
| 22 | }}, |
| 23 | marginInfo=true, |
| 24 | casOut={name='scored_margins', replace=true}; |
| 25 | QUIT; |