SUPERLEARNER Procedure
Example 33.2 Causal Effect Estimation
(View the complete code for this example.)
This example illustrates how you can use the SUPERLEARNER procedure for causal effect estimation.
This example uses the SmokingWeight data set available in the examples for the CAUSALTRT procedure in SAS/STAT User's Guide. These data are a subset of data from the NHANES I Epidemiologic Follow-Up Study (NHEFS) in Hernán and Robins (2020). For the study, medical and behavioral information was collected during an initial physical examination and again at follow-up interviews about 10 years later. As in the PROC CAUSALTRT examples, the question of interest here is what effect does quitting smoking, as recorded in the variable Quit, have on an individual’s change in weight (measured in kilograms), as recorded in the variable Change.
To create the data table SmokingWeight in your CAS session, you can modify the DATA step that is used to create the data set in PROC CAUSALTRT to create the data table in your CAS engine library . For this example, it is assumed that your CAS engine libref is named mylib, but you can substitute any appropriately defined CAS engine libref.
In addition to the treatment variable Quit and outcome variable Change, the data include the following variables:
Activity: level of daily activity, with values 0, 1, and 2Age: age in 1971BaseWeight: weight in kilograms in 1971Education: level of education, with values 0, 1, 2, 3, and 4Exercise: amount of regular recreational exercise, with values 0, 1, and 2PerDay: number of cigarettes smoked per day in 1971Race: 0 for white; 1 otherwiseSex: 0 for male; 1 for femaleWeight: weight in kilograms at the follow-up interviewYearsSmoke: number of years an individual has smoked
For this example, it is assumed that the variables Activity, Age, BaseWeight, Education, Exercise, PerDay, Race, Sex, and YearsSmoke make up a valid adjustment set that you can use to obtain unbiased estimates of the potential outcome means.
Targeted maximum likelihood estimation (TMLE) is a doubly robust method that combines modeling of both the treatment and outcome variable to estimate the potential outcome means and causal effects. This example uses the super learner to model the treatment and outcome variables, because it has been proven effective when combined with TMLE for causal effect estimation.
The following statements use PROC SUPERLEARNER to fit a super learner model for the treatment variable Quit and create an output data table that contains the predictions from the fitted model:
proc superlearner data=mylib.SmokingWeight seed=2324;
target Quit / level=nominal;
input Sex Race Education Exercise Activity / level=nominal;
input Age YearsSmoke PerDay / level=interval;
baselearner 'logistic' logselect;
baselearner 'logistic_2way' logselect
class=(Sex Race Education Exercise Activity)
effect=(Age|YearsSmoke|PerDay|Sex|Race|Education|Exercise|Activity @ 2);
baselearner 'logistic_ridge' logselect(selection=ELASTICNET(lambda=5 mixing=0))
class=(Sex Race Education Exercise Activity)
effect=(Age|YearsSmoke|PerDay|Sex|Race|Education|Exercise|Activity @ 2);
baselearner 'gam' gammod;
baselearner 'bart' bart(nTree=10 nMC=100);
output out=mylib.swTrtEstData copyvars=(_ALL_);
run;
When you use PROC SUPERLEARNER, you must specify the TARGET statement, at least one INPUT statement, and at least two BASELEARNER statements. You specify the input data table to use for training the super learner model in the DATA= option. The TARGET statement specifies information about the target variable. Each INPUT statement specifies predictor variables of the same type. Each BASELEARNER statement specifies a base learner model to be included in the super learner model.
In the TARGET statement, you use the LEVEL= option to indicate that you want to treat the treatment variable Quit as a categorical variable. You specify the categorical predictor variables in one INPUT statement and the continuous predictor variables in another.
In this example, five base learners are specified. For the first base learner, 'logistic', you specify a logistic regression model by using the LOGSELECT model type. The second base learner, 'logistic_2way', also specifies a logistic regression model but includes different model effects. You use the CLASS= option to specify the classification variables for this base learner. You use the EFFECT= option to construct main and two-way interaction effects that are based on the eight input variables and to include them in this base learner. The third base learner, 'logistic_ridge', adds a ridge penalty to the second base learner specification. You do this by using the SELECTION= option to apply the elastic net model selection method to this base learner. You set the lambda parameter to 5 by using the LAMDBA= option, and you set the mixing parameter to 0 by using the MIXING= option. For the fourth base learner, 'gam', you use the GAMMOD model type to specify a nonparametric logistic regression. You specify a Bayesian additive regression trees model by using the BART model type. You set the number of trees to 10 and the number of MCMC iterations to 100 by using the NTREES= and NMC= options, respectively.
In the OUTPUT statement, you use the COPYVARS= option to copy all variables from the input data table to the output data table.
The "Model Information" table in Output 33.2.1 summarizes important information, including the input data source, response (target) variable and its type, number of folds that are used in cross-validation, number of base learners, loss function, meta-learning method, and random number seed.
Output 33.2.1: Model Information
| Model Information | |
|---|---|
| Data Source | SMOKINGWEIGHT |
| Target Variable | Quit |
| Target Variable Type | NOMINAL |
| Number of Folds | 10 |
| Number of Base Learners | 5 |
| Loss Function | Log Loss |
| Meta-learning Method | Convex-constrained Binomial Likelihood Maximization |
| Random Number Seed | 2324 |
By default, based on the sample size used for training, the input data are divided into 10 folds for cross-validation. Because the response variable is categorical, the CCLOGLIK meta-learning method is used by default to compute the super learner coefficients, and the log loss function is used to compute the cross-validated risks of base learners.
Output 33.2.2 displays the "Number of Observations" table. In this analysis, a number of observations are not used for training, because there are missing values in the predictor variables and the response variable. A number of observations are not used for scoring, because there are missing predicted treatment assignment probabilities from the base learners. These probabilities are missing because there are missing values in the predictor variables.
Output 33.2.2: Number of Observations
| Number of Observations Read | 1746 |
|---|---|
| Number of Observations Used for Training | 1629 |
| Number of Observations Used for Scoring | 1629 |
Output 33.2.3 displays the super learner coefficient estimates and the cross-validated risks of the base learners. The base learner 'logistic' has the smallest cross-validated risk and the largest coefficient in the ensemble.
Output 33.2.3: Super Learner Coefficients
| Super Learner Model Coefficients | |||
|---|---|---|---|
| Name | Model Type | Coefficient | Cross-Validated Risk |
| logistic | Logistic Regression | 0.54565 | 0.55602 |
| logistic_2way | Logistic Regression | 0.01448 | 0.59092 |
| logistic_ridge | Logistic Regression | 0.05880 | 0.56960 |
| gam | Generalized Additive Model | 0 | 0.56010 |
| bart | Bayesian Additive Regression Trees | 0.38106 | 0.55771 |
By default, PROC SUPERLEARNER models the probability that the variable Quit takes the value 0. The name of the variable in the output data table that contains the predicted probability is P_Quit0. The following DATA step creates the variable P_Quit1, which contains the predicted probability of being assigned to the treatment condition, Quit=1:
data mylib.swTrtEstData;
set mylib.swTrtEstData;
P_Quit1 = 1 - P_Quit0;
run;
The following statements use PROC SUPERLEARNER to fit a super learner model for the outcome variable Change and create an output data table that contains the predictions from the fitted model:
proc superlearner data=mylib.swTrtEstData seed=2324;
baselearner 'linear' regselect;
baselearner 'linear_2way' regselect
class=(Sex Race Education Exercise Activity Quit)
effect=(Age|YearsSmoke|PerDay|Sex|Race|Education|Exercise|Activity|Quit @ 2);
baselearner 'linear_ridge' regselect(selection=ELASTICNET(lambda=5 mixing=0))
class=(Sex Race Education Exercise Activity Quit)
effect=(Age|YearsSmoke|PerDay|Sex|Race|Education|Exercise|Activity|Quit @ 2);
baselearner 'gam' gammod;
baselearner 'bart' bart(nTree=10 nMC=100);
margin 'quitsmoking' Quit=1;
margin 'noquitsmoking' Quit=0;
target Change / level=interval;
input Sex Race Education Exercise Activity Quit / level=nominal;
input Age YearsSmoke PerDay / level=interval;
output out=mylib.swDREstData marginpred copyvars=(Quit Change P_Quit1 P_Quit0);
run;
The syntax is almost identical to the syntax that is used to model the treatment probability. The first three base learners are specified using the REGSELECT model instead of the LOGSELECT model for modeling a continuous response variable. Also, the treatment variable Quit is added as a predictor variable. You use two MARGIN statements to intervene and set the Quit variable to two different values. You use the MARGINPRED option in the OUTPUT statement to include predictions that are based on the intervened values of the Quit variable in the output data table.
The "Model Information" table in Output 33.2.4 again summarizes important information about the fitted outcome mean model.
Output 33.2.4: Model Information
| Model Information | |
|---|---|
| Data Source | SWTRTESTDATA |
| Target Variable | Change |
| Target Variable Type | INTERVAL |
| Number of Folds | 10 |
| Number of Base Learners | 5 |
| Loss Function | Quadratic Loss |
| Meta-learning Method | Convex-constrained Least Squares |
| Random Number Seed | 2324 |
By default, based on the sample size used for training, the input data are divided into 10 folds for cross-validation. Because the response variable is continuous, CCLS is used as the default meta-learning method to compute the super learner coefficients.
Output 33.2.5 displays the "Number of Observations" table. In this analysis, a number of observations are not used for training, because there are missing values in the predictor variables and the response variable. A number of observations are not used for scoring and computing the predictive margins, because there are missing predicted responses from the base learners. These predicted responses are missing because there are missing values in the predictor variables.
Output 33.2.5: Number of Observations
| Number of Observations Read | 1746 |
|---|---|
| Number of Observations Used for Training | 1566 |
| Number of Observations Used for Computing Predictive Margins | 1629 |
| Number of Observations Used for Scoring | 1629 |
Output 33.2.6 displays the super learner coefficient estimates and the cross-validated risks of the base learners. The base learner 'gam' has the smallest cross-validated risk and the largest coefficient in the ensemble.
Output 33.2.6: Super Learner Coefficients
| Super Learner Model Coefficients | |||
|---|---|---|---|
| Name | Model Type | Coefficient | Cross-Validated Risk |
| linear | Ordinary Linear Least Squares | 0 | 57.31210 |
| linear_2way | Ordinary Linear Least Squares | 0.18160 | 59.30354 |
| linear_ridge | Ordinary Linear Least Squares | 0.15837 | 57.85823 |
| gam | Generalized Additive Model | 0.40464 | 56.70110 |
| bart | Bayesian Additive Regression Trees | 0.25539 | 56.93869 |
The following statements use the CAEFFECT procedure to estimate potential outcome means and their difference by using the doubly robust TMLE method:
proc caeffect data=mylib.swDREstData inference method=TMLE;
treatvar Quit;
outcomevar Change;
pom treatLev=1 treatProb=P_Quit1 predout=quitsmoking;
pom treatLev=0 treatProb=P_Quit0 predout=noquitsmoking;
difference evtLev=1;
run;
For this example, you use the TREATVAR and OUTCOMEVAR statements to specify the treatment and outcome variables, respectively. You use two POM statements to specify the potential outcomes of interest under the two treatment levels. In each POM statement, you supply the variables in the input data table that contains the predicted treatment assignment probabilities and outcome means that the TMLE analysis requires. You do this by specifying the TREATPROB= and PREDOUT= options, respectively. The variable names of the predicted outcome means correspond to the names that you specify in the MARGIN statements earlier. You use the DIFFERENCE statement to request a difference between the potential outcome mean estimates.
Output 33.2.7 displays the potential outcome mean estimates and their difference. The "POM Estimates" table indicates the level of treatment that defines the potential outcome and the estimate of its mean.
Output 33.2.7: Potential Outcome Mean and Difference Estimates
| POM Estimates | ||||||
|---|---|---|---|---|---|---|
| Treatment Level | Estimate | Standard Error | 95% Confidence Limits | Z | Pr > |Z| | |
| 1 | 5.06841 | 0.43041 | 4.22482 | 5.91201 | 11.78 | <.0001 |
| 0 | 1.81793 | 0.21516 | 1.39622 | 2.23964 | 8.45 | <.0001 |
| POM Differences | |||||||
|---|---|---|---|---|---|---|---|
| Treatment Levels | Difference | Standard Error | Z | Pr > |Z| | |||
| Event | Reference | 95% Confidence Limits | |||||
| 1 | 0 | 3.2505 | 0.47196 | 2.32545 | 4.17552 | 6.89 | <.0001 |
The "POM Differences" table shows the requested difference in potential outcome mean estimates. With the proper causal assumptions, the difference in potential outcome mean estimates corresponds to an estimate of the average treatment effect (ATE) of a weight change that is approximately 3.2 kilograms greater because the subjects quit smoking.