## Demo: Fitting a Multiple Logistic Regression Model (Self-Paced)

In this demonstration, you fit a multiple logistic regression model using the Logistic Regression.sas program in a flow. The program uses Response as the target variable and GiftCnt36, DemMedHomeValue, GiftTimeLast, and StatusCatStarAll as the predictor variables. The goal is to predict whether a customer is likely to donate to the donation campaign.

Reminder: If you restarted your SAS session, or it has timed out due to inactivity, you must re-create the course libraries, LOCALLIB and VST. To do this, run the AssignLibrary flow.

1. In SAS Viya, launch SAS Studio by clicking the Applications menu button (the three-by-three grid in the upper left corner), expand ANALYTICS LIFE CYCLE, and click Develop Code and Flows.
2. In the navigation panel on the far left, click the Explorer button (second from top). Expand Files >Home > workshop > VST. Double-click AssignLibrary.flw to open it.
3. Click the Run button on the flow toolbar.

## Demo Steps

1. Open the previously created flow Categorical Data Analysis.flw from the VST folder. We will add a program to this flow.
2. Still in the VST folder, double click on Logistic Regression.sas. View the code.
3. The SAS Program step contains the following code. Note the oddsratio statement to calculate odds ratios comparing groups with a one-unit difference. Two other statements start with an asterisk, which prevents the code from being executed:

     proc logselect data=VST.PVA_DONORS association;
      partition fraction(validate=0.5 seed=12345);
      class StatusCatStarAll;
      model Response(event='Yes')=StatusCatStarAll GiftCnt36 GiftTimeLast
      DemMedHomeValue / link=logit;
      code file="/home/student/workshop/VST/logistic_score.sas";
      oddsratio;
      *ods select oddsratios;
      *oddsratio StatusCatStarAll GiftCnt36 GiftTimeLast DemMedHomeValue/
        unit (DemMedHomeValue=1000);
    run;

4. Click the + Code to Flow button and add the program to the previously saved Categorical Data Analysis flow. Navigate to the flow tab of Categorical Data Anlysis.flw.
5. Right-click on the Logistic Regression node and select Run node. Save the Categorical Data Analysis flow.
6. Examine the results from the Logistic Regression node. If you want to view the results on a separate browser tab, click the More options (three dots) menu and select Open in a browser tab > Results.

On the Results tab, the Model Information table displays information about the model, including the data source, distribution, link function, and optimization technique.

The Number of Observations table contains the number of observations that were read from the source data and used in the analysis. Because the data were partitioned, the table displays the number of observations in each partition.

The Response Profile table shows the distribution of the target variable values for each partition. A Class Level Information table lists the levels of categorical predictors.

The Global Null Hypothesis Test table provides a likelihood ratio test for the hypothesis of whether the final model provides a better fit than a model without effects (an intercept-only model). The p-value (<0.0001) column in the global null hypothesis test table indicates that this model is statistically significant at the 5% level of significance, and at least one of the predictors in the model is useful in predicting Response..

The Fit Statistics table displays a variety of likelihood-based measures of fit. These statistics are useful for assessing the fit of the model to your data. The statistics are computed for each data role when you partition the data.

The Parameter Estimates table shows the parameter estimates, their standard errors, and the p-values for assessing statistical significance. All parameter estimates are on the logit scale. You can use these parameter estimates to define your logistic regression equation.

Because reference cell coding was used for the classification variable, the effect is measured against the reference level. For the StatusCatStarAll variable, level 1 is used as the reference level. So, the estimate for StatusCatStarAll | 0 shows the difference in logits between individuals with 0 and 1 for StatusCatStarAll. The table shows that the parameter estimates for all the effects are statistically significant at the 5% level of significance.

The Association of Predicted Probabilities and Observed Responses table shows that the concordance index (c) equals 0.5938 for the training data and 0.6104 for the validation data. The c statistic value for this model indicates that approximately 60% of the positive and negative response pairs are correctly sorted using StatusCatStarAll, GiftCnt36, GiftTimeLast, and DemMedHomeValue.

The Odds Ratio Estimates table can be used to establish the relationship between predictors and the odds of the event. It is often easier to report odds ratios by first transforming the decimal value to a percent difference value. In this example, the odds ratio estimate for StatusCatStarAll when transformed to percent difference is (0.820-1)*100= -17.96%. In other words, the odds ratio estimate for StatusCatStarAll shows that, when adjusting for other predictor variables, individuals with zero for StatusCatStarAll had ~18% lower odds of donation than the individuals with 1 for StatusCatStarAll. For GiftCnt36, the odds ratio estimate equals 1.084. This means that for each additional donation in the past 36 months, the odds of donation during the campaign changed by a factor of 1.084, an 8.4% increase.

Note: The unusual value of 1.000 for the DemMedHomeValue odds ratio has a simple explanation. Unit (that is, single dollar) changes in the home value do not change the odds of response by an amount captured in three significant digits. To obtain a more meaningful value for this input's effect on response odds, you can calculate an odds ratio comparing median home values that differ by $1000. We’ll alter the code to do this in the next step.

7. Go back to Categorical Data Analysis flow and click on the Logistic Regression node. You will edit the code to change how the oddsratio for DemMedHomeValue is calculated. Add an asterisk to the first oddsratio statement and remove the 2 asterisks from the ods select statement and from second oddsratio statement (which is followed by 4 variable names). Now the oddsratio statement will calculate an odds ratio for DemMedHomeValue, comparing groups with a $1000 difference. The code should appear as follows:

    proc logselect data=VST.PVA_DONORS association;
      partition fraction(validate=0.5 seed=12345);
      class StatusCatStarAll;
      model Response(event='Yes')=StatusCatStarAll GiftCnt36 GiftTimeLast
      DemMedHomeValue / link=logit;
      code file="/home/student/workshop/VST/logistic_score.sas";
      *oddsratio;
      ods select oddsratios;
      oddsratio StatusCatStarAll GiftCnt36 GiftTimeLast DemMedHomeValue/
        unit (DemMedHomeValue=1000);
       run;

8. Run the Logistic Regression node again and view the results.

Now the odds ratio for DemMedHomeValue shows a value of 1.001 with a 95% confidence interval of (1.001, 1.002). This indicates that for every $1000 increase in DemMedHomeValue, the odds of donating increase by 0.12%.