gains: Gains Table for a Vector of Predictions

Description Usage Arguments Value See Also Examples

View source: R/gains.R

Description

Takes a vector of actual responses and a vector of predictions and constructs a gains table to evaluate the predictions.

Usage

1
2
3
4
gains(actual, predicted, groups=10, 
      ties.method=c("max","min","first","average","random"),
      conf=c("none","normal","t","boot"), boot.reps=1000, conf.level=0.95, 
      optimal=FALSE,percents=FALSE)

Arguments

actual

a numeric vector of actual response values

predicted

a numeric vector of predicted response values. This vector must have the same length as actual, and the ith value of this vector needs to be the model score for the subject with the ith value of the actual vector as its actual response.

groups

an integer containing the number of rows in the gains table. The default value is 10.

ties.method

method of breaking ties. See the ties.method argument of the rank procedure.

conf

method to construct confidence intervals for the mean response in each row of the table. If "none", then no confidence intervals are constructed. If "normal", then critical values from the normal distribution are used. If "t", then critical values from the t distribution are used. If "boot", then 1000 bootstrap samples are drawn from each row, and the upper and lower conf.level/2 values of the distribution are used as the confidence interval endpoints.

boot.reps

the number of bootstrap replications to use for bootstrap confidence intervals. The default value is 1000.

conf.level

the 1 - alpha level of the confidence interval. The default value is 0.95.

optimal

a logical indicated whether the user wants optimal lift indices to be computed. Optimal lift indices represent the results that would be achieved from an optimal ranking of subjects.

percents

a logical that indicates whether to print the mean responses and predicted responses in percent form.

Value

gains returns an S3 object of class gains. The function print.gains can be used to print the results. The function plot.gains can be used to plot the mean response and cumulative mean response for each group. An object of class gains is a list containing the following components:

depth

cumulative percentage of file covered by each row of the gains table (e.g. 10,20,30,...,100).

obs

number of observations in each row.

cume.obs

cumulative number of observations in each row.

mean.resp

mean response in each row.

cume.mean.resp

cumulative mean response in each row.

cume.pct.of.total

cumulative percent of total response.

lift

lift index. The lift index is 100 times the mean.resp for the row divided by the cume.mean.resp for the last row.

cume.lift

cumulative lift index. It is 100 times the cume.mean.resp for the row divided by the cume.mean.resp for the last row.

mean.prediction

mean predicted response in each row.

min.prediction

minimum predicted response in each row. min.prediction and max.prediction can be used to construct decision rules for applying the model.

max.prediction

maximum predicted response in each row.

conf

the argument given for conf.

optimal

the argument given for optimal.

num.groups

the number of rows in the gains table. This will equal groups unless there are fewer distinct predicted values than groups.

percents

the argument given for percents.

conf.lower

lower confidence limit for each row. Only included if confidence intervals are requested in the gains table.

conf.upper

upper confidence limit for each row. Only included if confidence intervals are requested in the gains table.

opt.lift

optimal lift index. The lift index achieved by an optimal ranking of subjects in the file. Only included if optimal lift is requested in the gains table.

opt.cume.lift

optimal cumulative lift index. The cumulative lift by an optimal ranking. Only included if optimal lift is requested in the gains table.

See Also

print.gains for printing the table in a nice way. plot.gains for drawing a graph representing the output. (This graph is sometimes called a lift chart.)

Examples

1
2
3
data(ciaScores)
with(subset(ciaScores,train==0), 
      gains(actual=CellPhonesPP, predicted=PredOLS, optimal=TRUE))

Example output

Depth                            Cume   Cume Pct                 Optimal Optimal     Mean
 of           Cume     Mean      Mean   of Total    Lift   Cume    Lift    Cume     Model
File     N      N      Resp      Resp      Resp    Index   Lift   Index    Lift     Score
-----------------------------------------------------------------------------------------
  10     9      9      1.25      1.25      16.4%     168    168     209     209      1.47
  20     9     18      1.25      1.25      32.7%     167    167     167     188      1.30
  29     9     27      1.13      1.21      47.5%     151    162     148     175      1.17
  39     9     36      0.99      1.15      60.4%     132    154     129     163      1.04
  50    10     46      0.79      1.07      71.8%     105    144     109     151      0.85
  60     9     55      0.56      0.99      79.2%      76    133      92     142      0.75
  70     9     64      0.65      0.94      87.7%      87    126      71     132      0.65
  79     9     73      0.44      0.88      93.4%      58    118      47     121      0.54
  89     9     82      0.20      0.81      96.0%      27    108      29     111      0.40
 100    10     92      0.27      0.75     100.0%      37    100       8     100     -0.02

gains documentation built on May 2, 2019, 3:25 a.m.

Related to gains in gains...