![]() | ![]() | ![]() | ![]() | ![]() |
| Contents: | Purpose / History / Requirements / Usage / Details / Limitations / Missing Values |
For a continuous response, a table and plots of gains, lift, and cumulative lift are provided.
All statistic plots can be displayed in a single panel of line or bar charts or can be individually presented.
%gainlift(v)
The GainLift macro always attempts to check for a later version of itself. If it is unable to do this (such as if there is no active internet connection available), the macro issues the following message:
NOTE: Unable to check for newer version of the GAINLIFT macro.
The computations performed by the macro are not affected by the appearance of this message. However, this check can be avoided by specifying nochk as the first macro argument. This can be useful if your machine has no connection to the internet.
| Version
|
Update Notes
|
| 2.0 | Added ability to evaluate continuous response models. Added level= option. Added 5 as an optional number of bins for smaller data sets. Added predicted value cutpoints for bins to table. More complete checking of inputs. |
| 1.1 | Corrected gain formula to use absolute value. Removed cumulative gain. Added Best Possible values for each statistic. Added default table of statistics. Added graphopts= option that subsumes previous graph, grid=, and panel= options and adds capability for displaying baseline and best possible lines. Added tableopts= option that controls statistics in the optional table. Replaced oneplot= option with plots= option to specify statistics to display as individual plots. Now displays notes in the log for time used and output data set creation. |
| 1.0 | Initial version |
%inc "<location of your file containing the GainLift macro>";
After this statement, you can call the GainLift macro using the following syntax. Macro arguments can be listed in any order. See the Results tab for examples.
The following macro arguments are required:
The following macro arguments are optional:
table - Display a table of statistics for each bin,
notable - Suppress the table of statistics,
base - Show values of the baseline (uninformative) model,
nobase - Omit the baseline values,
best - Show values of the best possible model,
nobest - Omit the best possible values
nograph - Suppresses all plots,
line - Produces line plots for the fitted model,
bar - Produces bar charts for the fitted model,
panel - All statistic plots appear in a panel,
nopanel - Display all statistics in separate plots,
grid - Add grid lines in plots,
nogrid - Omits grid lines,
base - Display a line for the baseline (uninformative) model,
nobase - Omit line line for the baseline model,
best - Display a line for the best possible model,
nobest - Omit the line for the best possible model
gain - Gain,
lift - Lift,
clift - Cumulative Lift,
These plots are only available when level=binary:
ccapt - Cumulative Percent Captured,
pcapt - Percent Captured,
cresp - Cumulative percent response,
presp - Percent Response
The plots produced by the GainLift macro are most commonly used to assess the predictive ability of a binary response model, such as a logistic or probit model or of a decision tree. Gains and lift plots are popular in direct marketing and credit scoring fields. Another plot, the ROC plot, also summarizes predictive ability. The ROC plot can be produced directly by the LOGISTIC procedure. However, analogous lift and gain plots can be created for a continuous response model as described below.
For both binary and continuous response data, the data set that contains the predicted values from the fitted model are sorted and divided into bins as described in bins= above.
For a binary response model (specify level=binary), Gain is the percent change in the event proportion from overall in all bins up to the current bin. Lift for each bin, is the ratio of the proportion of observations in the bin that are events to the overall proportion of events. Cumulative Lift is the event rate up to the current bin over the overall event rate. Percent Captured, for each bin, is the percentage of total events in the bin. Cumulative Percent Captured is the percentage of total events up to the current bin. This is often considered gain rather than the change percent statistic described above. Percent Response for each bin is the percentage of observations in the bin that are events. Cumulative Percent Response is the percentage of observations up to the current bin that are events.
The statistics are computed as follows for a binary response:
E = total number of events N = number of observations G = number of bins (20 (ventiles or demi-deciles); 10 (deciles); 5 (quintiles)) P = overall proportion of observations that are events (P = E/N) ei = number of events in bin i, i=1,2,...,G ni = number of observations in bin i, i=1,2,...,G bi = best event count achievable in bin i, i=1,2,...,G = E-Σjej if E-Σjej≤ni, j=1,2,...,i-1 = ni otherwise, pi = proportion of observations in bin i that are events (pi = ei/ni) For Bin i, i=1,2,...,G: %Response = 100*pi Cumulative %Response = 100*(Σjej/Σjnj), j=1,2,...,i %Captured = 100*(ei/E) Cumulative %Captured = 100*(Σjej/E), j=1,2,...,i Lift = pi/P Cumulative Lift = (Σjej/Σjnj)/P, j=1,2,...,i Gain = 100*abs(Σjej/Σjnj-P)/P = 100*abs(CumLift-1)
The statistic values for the best possible model are computed as above using the best event count achievable, bi, rather than ei. This puts all observed events in the top bins, filling the top bins as needed to absorb all observed events.
Assuming an uninformative model that randomly puts observations into bins, baseline values for each statistic are as follows:
%Response = 100*P Cumulative %Response = 100*P %Captured = 100*ni/N Cumulative %Captured = 100*Σini/N, j=1,2,...,i Lift = 1 Cumulative Lift = 1 Gain = 0
For a continuous response model (specify level=interval), lift, cumulative lift, and gains can be computed by using sums and means of the target response within bins of the ordered predicted response values instead of counts and proportions of events as for a binary model. Note that proportions are means when the binary response is coded 1 for the event and 0 for the nonevent.
Lift in each bin can be considered as the ratio of the target (observed response) mean in the bin to the overall target mean. This is analogous to lift in the binary case where lift is the ratio of the event proportion in the bin to the overall event proportion. Cumulative Lift is computed similarly as the cumulative target mean in bins up to the current bin divided by the overall mean. For a base, or noninformative model, both lift and cumulative lift equal 1. Gain is the cumulated sum of target values up to the current bin divided by the overall target sum. This is analogous to the Cumulative Percent Captured in the binary case that is often regarded as the measure of gain. For a base model, gain is the proportion of the sample in each bin which is a diagonal line from 0 to 1.
The statistics are computed as follows for a continuous response:
S = overall sum of responses M = S/N = overall mean response si = sum of responses in bin i, i=1,2,...,G mi = si/ni = mean response in bin i, i=1,2,...,G For Bin i: Lift = mi/M, i=1,2,...,G Cumulative Lift = (Σjsj/Σjnj)/M, j=1,2,...,i Gain = Σjsj/S, j=1,2,...,i
The statistic values for the best possible model are computed as above by creating bins from the ordered actual response values rather than from the predicted responses.
Included in the default table of bin statistics are values of the "Bin Predicted Cutpoint." These are the minimum predicted value in each bin. They are useful when scoring new observations using the model that is evaluated by the macro and determining which bin a new observation would belong to based on its score. For example, if an observation's predicted score falls between the cutpoints for bins 2 and 3, then it can be classified as falling in bin 2.
The GainLift macro always creates an output data set that contains the values of all statistics for each bin. Most of the variables in this data set are displayed by default by the macro unless tableopts=notable is specified. By default, the data set is named _GainLift. You can change its name by specifying it in out=.
For binary response data, if the data were collected by sampling from the response levels, such as when oversampling the event or in case-control settings, then see SAS Note 22601 on adjusting the predicted probabilities for the sampling before using the macro.
These sample files and code examples are provided by SAS Institute Inc. "as is" without warranty of any kind, either express or implied, including but not limited to the implied warranties of merchantability and fitness for a particular purpose. Recipients acknowledge and agree that SAS Institute shall not be liable for any damages whatsoever arising out of their use of this material. In addition, SAS Institute will provide no support for the materials contained herein.
These sample files and code examples are provided by SAS Institute Inc. "as is" without warranty of any kind, either express or implied, including but not limited to the implied warranties of merchantability and fitness for a particular purpose. Recipients acknowledge and agree that SAS Institute shall not be liable for any damages whatsoever arising out of their use of this material. In addition, SAS Institute will provide no support for the materials contained herein.
The following statements use the home equity data in the SAMPSIO.HMEQ data set. The binary response, BAD, indicates delinquency of the loan (1=delinquent; 0=not). PROC LOGISTIC is used to fit a logistic model to the response. The OUTPUT statement saves a data set that contains the predicted probabilities of the event (delinquency) and nonevent.
proc logistic data=sampsio.hmeq plots(only)=roc; model bad(event='1') = loan yoj clno; output out=out pred=p; run;
The performance of the model is assessed by the ROC curve provided by PROC LOGISTIC and by the plots from the GainLift macro. The area under the ROC curve is 0.5725, which indicates only a slight improvement in the predictive ability of this model over an uninformative model that contains only an intercept (with area 0.5).
The GainLift macro is called next to provide additional assessment of the model. The default table of statistics is suppressed by the TABLEOPTS=NOTABLE option.
%gainlift(data=out, response=bad, p=p, level=binary,
event=1, tableopts=notable)
The cumulative plots from the GainLift macro show curves for the model that do not deviate much from baseline and are far from the best possible model, which again indicates a poorly performing model.
The final model found by stepwise selection is assessed next. These statements fit the model and produce the ROC plot.
proc logistic data=sampsio.hmeq plots(only)=roc;
model bad(event='1') = loan value mortdue yoj derog delinq
clage ninq clno / selection=stepwise;
output out=out pred=p;
run;
The area under the ROC curve for this model is 0.7992, which indicates much better performance.
The GainLift macro is called to evaluate this new model.
%gainlift(data=out, response=bad, p=p, level=binary, event=1)
The plots from the GainLift macro are now much closer to the best possible case than to the baseline case. The Lift plots show the proportion of observations in the bin or up to that bin that are events divided by the overall proportion of events. These plots below show that bins with 20% highest predicted probabilities have two or more times the overall event probability. The best possible model would have almost five times the overall probability. The noninformative, base model would be expected to have the same proportion of events as overall, so baseline lift is 1.
The %Captured plots show the percentage of total events captured in the bin or up to that bin. Note that many consider this to be the gain rather than the difference-based gain statistic discussed below. The cumulative plot shows that the top 25% from the model contain over 60% of the events. These are loans with predicted event probability that exceeds the 0.2157 cutpoint. The best possible model would contain almost all of the events. The first bin in the noncumulative plot with the 5% highest predicted probabilities (those exceeding the bin's 0.7217 cutpoint) contains over 20% of the events. The proportion of events expected by the base model would contain its proportion of the sample, that is 10% in each decile bin or 5% in each demi-decile bin. So, the base model is represented by a diagonal line from 0 to 1.
The Gain plot shows the percent change in the event proportion from overall up to that bin. This is effectively the cumulative lift plot normalized by subtracting the base-expected value of 1. As a result, the expected baseline gain is zero. The plot and table show a 202% gain at Depth=15, which indicates a 202% increase in event rate relative to the overall event rate. Alternatively, using cumulative %Captured as a measure of gain shows 45% of total events captured at Depth=15.
The %Response plots show the event proportion in the bin or up to that bin. This is effectively lift rescaled by multiplying the lift by the overall event probability. The best possible and baseline values are similarly rescaled. The cumulative percent response indicates that the top 20% of predicted probabilities contain 58.5% of the delinquencies. This is a factor of 2.77 (cumulative lift) times the base (overall) remission rate of 1002/4748 = 21.1%, or a 177% gain.
The following macro call produces a bar chart version of the cumulative percent captured plot for the final model. The baseline case is omitted by the NOBASE option.
%gainlift(data=out, response=bad, p=p, event=1, plots=ccapt,
graphopts=bar nobase, tableopts=notable)
The following example uses the insurance claim loss data set, TOTLOSS, created as described in SAS KB0058455. The response variable, TOTLOSS, contains the total amount lost by the insurance company to each policyholder over one year. TOTLOSS ranges from zero to large positive values. PROC GENMOD fits a Tweedie model to this response using several predictors. As for the binary example above, the OUTPUT statement saves the predicted and observed response values in a data set for use by the GainLift macro.
proc genmod data=totloss;
model totloss = age gender carType annualMiles education
carSafety income / dist=tweedie;
output out=pred pred=pred;
run;
In the GainLift macro call, bin numbers are specified as the horizonal axis variable for the paneled plots and values for the best possible model are added to the table of bin statistics.
%gainlift(data=pred, response=totloss, p=pred,
level=interval, xaxis=binnum, tableopts=best)
The plots show that the Tweedie model performs close to the best possible model. The noncumulative lift plot shows that the top four bins (top 20% of predicted values) have Lift > 1, which indicates that the response mean in these bins exceeds the overall response mean. This suggests that any action to reduce loss is best focused on the policyholders in the top 20% of predicted response. The minimum predicted loss for the top 20% is the cutpoint for bin 4, 1253.15. So, new policyholders scored by the above model having predicted loss exceeding this value would be eligible for action. In terms of total loss, the gain plot suggests that the top five bins (top 25% of predicted values) account for about 80% of the total loss.
For small data sets, it is advisable to create fewer bins. This example uses the cancer remission data presented in the stepwise logistic regression example in the LOGISTIC documentation. The data set has only 27 observations that contain 9 events (REMISS=1) for an overall event rate of 33%. These statements fit a logistic model to the data and save the predicted event probabilities in a data set for use in the GainLift macro.
proc logistic data=remission; model remiss(event='1') = li temp cell; output out=OutRemiss pred=p; run;
Since the OUT= data set, OutRemiss, is the last created data set, the GainLift macro can be called without specifying data= as below. Because the data set is small, bins=5 is specified so that there are about 4 or 5 observations in each bin. The default panel of plots of all statistics is produced but graphopts=bar requests the use of bar charts for the fitted model rather than line plots.
%gainlift(response=remiss, p=p, event=1, level=binary, bins=5,
graphopts=bar)
In the table and plot, the cumulative percent of remissions captured is nearly 90% using only the top two bins that contain 40% of predicted remission probabilities (those exceeding the 0.3216 cutpoint). These two bins have at least twice event rate as overall as indicated by the noncumulative lift in each bin equaling or exceeding 2. The cumulative percent response indicates that the top bin with 20% of the predicted remission probabilities contain 80% of the remission events. This is a factor of 2.4 (cumulative lift) times the base (overall) remission rate of 33%. Expressed as a percent difference, this is 100(80-33.33)/33.33 = 140% gain.
Right-click the link below and select Save to save the GainLift macro definition to a file. It is recommended that you name the file GainLift.sas.
| Type: | Sample |
| Topic: | Analytics ==> Categorical Data Analysis Analytics ==> Regression |
| Date Modified: | 2026-10-19 11:25:17 |
| Date Created: | 2010-11-24 14:49:04 |
| Product Family | Product | Host | SAS Release | |
| Starting | Ending | |||
| SAS System | SAS/STAT | z/OS | ||
| OpenVMS VAX | ||||
| Microsoft® Windows® for 64-Bit Itanium-based Systems | ||||
| Microsoft Windows Server 2003 Datacenter 64-bit Edition | ||||
| Microsoft Windows Server 2003 Enterprise 64-bit Edition | ||||
| Microsoft Windows XP 64-bit Edition | ||||
| Microsoft® Windows® for x64 | ||||
| OS/2 | ||||
| Microsoft Windows 95/98 | ||||
| Microsoft Windows 2000 Advanced Server | ||||
| Microsoft Windows 2000 Datacenter Server | ||||
| Microsoft Windows 2000 Server | ||||
| Microsoft Windows 2000 Professional | ||||
| Microsoft Windows NT Workstation | ||||
| Microsoft Windows Server 2003 Datacenter Edition | ||||
| Microsoft Windows Server 2003 Enterprise Edition | ||||
| Microsoft Windows Server 2003 Standard Edition | ||||
| Microsoft Windows Server 2003 for x64 | ||||
| Microsoft Windows Server 2008 | ||||
| Microsoft Windows Server 2008 for x64 | ||||
| Microsoft Windows XP Professional | ||||
| Windows 7 Enterprise 32 bit | ||||
| Windows 7 Enterprise x64 | ||||
| Windows 7 Home Premium 32 bit | ||||
| Windows 7 Home Premium x64 | ||||
| Windows 7 Professional 32 bit | ||||
| Windows 7 Professional x64 | ||||
| Windows 7 Ultimate 32 bit | ||||
| Windows 7 Ultimate x64 | ||||
| Windows Millennium Edition (Me) | ||||
| Windows Vista | ||||
| Windows Vista for x64 | ||||
| 64-bit Enabled AIX | ||||
| 64-bit Enabled HP-UX | ||||
| 64-bit Enabled Solaris | ||||
| ABI+ for Intel Architecture | ||||
| AIX | ||||
| HP-UX | ||||
| HP-UX IPF | ||||
| IRIX | ||||
| Linux | ||||
| Linux for x64 | ||||
| Linux on Itanium | ||||
| OpenVMS Alpha | ||||
| OpenVMS on HP Integrity | ||||
| Solaris | ||||
| Solaris for x64 | ||||
| Tru64 UNIX | ||||




