Takes a vector of actual responses and a vector of predictions and constructs a gains table to evaluate the predictions.
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)
a numeric vector of actual response values
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.
an integer containing the number of rows in the gains table. The default value is 10.
method of breaking ties. See the ties.method
argument of the rank
procedure.
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.
the number of bootstrap replications to use for bootstrap confidence intervals. The default value is 1000.
the 1 - alpha level of the confidence interval. The default value is 0.95.
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.
a logical that indicates whether to print the mean responses and predicted responses in percent form.
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:
cumulative percentage of file covered by each row of the gains table (e.g. 10,20,30,...,100).
number of observations in each row.
cumulative number of observations in each row.
mean response in each row.
cumulative mean response in each row.
cumulative percent of total response.
lift index. The lift index is 100 times the mean.resp
for the row divided by the cume.mean.resp
for the last row.
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 predicted response in each row.
minimum predicted response in each row. min.prediction
and max.prediction
can be used to construct decision rules for applying the model.
maximum predicted response in each row.
the argument given for conf
.
the argument given for optimal
.
the number of rows in the gains table. This will equal groups
unless there are fewer distinct predicted values than groups
.
the argument given for percents
.
lower confidence limit for each row. Only included if confidence intervals are requested in the gains table.
upper confidence limit for each row. Only included if confidence intervals are requested in the gains table.
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.
optimal cumulative lift index. The cumulative lift by an optimal ranking. Only included if optimal lift is requested in the gains table.
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.)
# NOT RUN {
data(ciaScores)
with(subset(ciaScores,train==0),
gains(actual=CellPhonesPP, predicted=PredOLS, optimal=TRUE))
# }
Run the code above in your browser using DataLab