gainstable.default: Gains Table for Binary Classifier

View source: R/gainstable.R

gainstable.defaultR Documentation

Gains Table for Binary Classifier

Description

Default S3 method to create gains table from a vector of diagnostic score and the class of observations.

Usage

## Default S3 method:
gainstable(score, class, negref = NULL, ngroup = 10, breaks = NULL, ... = NULL)

Arguments

score

An numeric array of diagnostic score. Same as in rocit.

class

An array of equal length of score, containing the class of the observations. Same as in rocit.

negref

The reference value, same as the reference in convertclass. Depending on the class of x, it can be numeric or character type. If specified, this value is converted to 0 and other is converted to 1. If NULL, reference is set alphabetically. Same as in rocit.

ngroup

Number of desired groups in gains table. Ignored if breaks is specified. See "Details".

breaks

Percentiles (in percentage) at which observations should be separated to form groups. If specified, ngroup is ignored. See "Details".

...

NULL. Used for S3 generic/method consistency.

Details

gainstable function creates gains table containing ngroup number of groups or buckets. The algorithm first orders the score variable with respect to score variable. In case of tie, it class becomes the ordering variable, keeping the positive responses first. The algorithm calculates the ending index in each bucket as round((length(score) / ngroup) * (1:ngroup)). Each bucket should have at least 5 observations.

If buckets' end index are to be ended at desired level of population, then breaks should be specified. If specified, it overrides ngroup and ngroup is ignored. breaks by default always includes 100. If whole number does not exist at specified population, nearest integers are considered.

Value

A list of class "gainstable". It has the following components:

Bucket

The serial number of buckets or groups.

Obs

Number of observation in the group.

CObs

Cumulative number of observations up to the group.

Depth

Cumulative population depth up to the group.

Resp

Number of (positive) responses in the group.

CResp

Cumulative number of (positive) responses up to the group.

RespRate

(Positive) response rate in the group.

CRespRate

Cumulative (positive) response rate up to the group

CCapRate

Cumulative overall capture rate of (positive) responses up to the group.

Lift

Lift index in the group. Calculated as GroupResponseRate / OverallResponseRate.

CLift

Cumulative lift index up to the group.

Note

The algorithm is designed for complete cases. If NA(s) found in either score or class, then removed.

See Also

gainstable.rocit, plot.gainstable, rocit

Examples

data("Loan")
class <- Loan$Status
score <- Loan$Score
# ----------------------------------------------------------------
gtable15 <- gainstable(score = score, class = class,
                       negref = "FP", ngroup = 15)
gtable_custom <- gainstable(score = score, class = class,
                            negref = "FP", breaks = seq(1,100,15))
# ----------------------------------------------------------------
print(gtable15)
print(gtable_custom)
# ----------------------------------------------------------------
plot(gtable15)
plot(gtable_custom)
plot(gtable_custom, type = 2)
plot(gtable_custom, type = 3)


ROCit documentation built on May 29, 2024, 2:15 a.m.