smbinning.scaling: Scaling

Description Usage Arguments Value Examples

View source: R/smbinning.R

Description

It transforms the coefficients of a logistic regression into scaled points based on the following three parameters pre-selected by the analyst: PDO, Score, and Odds.

Usage

1
smbinning.scaling(logitraw, pdo = 20, score = 720, odds = 99)

Arguments

logitraw

Logistic regression (glm) that must have specified family=binomial and whose variables have been generated with smbinning.gen or smbinning.factor.gen.

pdo

Points to double the oods.

score

Score at which the desire odds occur.

odds

Desired odds at the selected score.

Value

A scaled model from a logistic regression built with binned variables, the parameters used in the scaling process, the expected minimum and maximum score, and the original logistic model.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# Load library and its dataset
library(smbinning)

# Sampling
pop=smbsimdf1 # Population
train=subset(pop,rnd<=0.7) # Training sample

# Generate binning object to generate variables
smbcbs1=smbinning(train,x="cbs1",y="fgood")
smbcbinq=smbinning.factor(train,x="cbinq",y="fgood")
smbcblineut=smbinning.custom(train,x="cblineut",y="fgood",cuts=c(30,40,50))
smbpmt=smbinning.factor(train,x="pmt",y="fgood")
smbtob=smbinning.custom(train,x="tob",y="fgood",cuts=c(1,2,3))
smbdpd=smbinning.factor(train,x="dpd",y="fgood")
smbdep=smbinning.custom(train,x="dep",y="fgood",cuts=c(10000,12000,15000))
smbod=smbinning.factor(train,x="od",y="fgood")
smbhome=smbinning.factor(train,x="home",y="fgood")
smbinc=smbinning.factor.custom(
  train,x="inc",y="fgood",
  c("'W01','W02'","'W03','W04','W05'","'W06','W07'","'W08','W09','W10'"))

pop=smbinning.gen(pop,smbcbs1,"g1cbs1")
pop=smbinning.factor.gen(pop,smbcbinq,"g1cbinq")
pop=smbinning.gen(pop,smbcblineut,"g1cblineut")
pop=smbinning.factor.gen(pop,smbpmt,"g1pmt")
pop=smbinning.gen(pop,smbtob,"g1tob")
pop=smbinning.factor.gen(pop,smbdpd,"g1dpd")
pop=smbinning.gen(pop,smbdep,"g1dep")
pop=smbinning.factor.gen(pop,smbod,"g1od")
pop=smbinning.factor.gen(pop,smbhome,"g1home")
pop=smbinning.factor.gen(pop,smbinc,"g1inc")

# Resample
train=subset(pop,rnd<=0.7) # Training sample
test=subset(pop,rnd>0.7) # Testing sample

# Run logistic regression
f=fgood~g1cbs1+g1cbinq+g1cblineut+g1pmt+g1tob+g1dpd+g1dep+g1od+g1home+g1inc
modlogisticsmb=glm(f,data = train,family = binomial())
summary(modlogisticsmb)

# Example: Scaling from logistic parameters to points
smbscaled=smbinning.scaling(modlogisticsmb,pdo=20,score=720,odds=99)
smbscaled$logitscaled # Scaled model
smbscaled$minmaxscore # Expected minimum and maximum Score
smbscaled$parameters # Parameters used for scaling
summary(smbscaled$logitraw) # Extract of original logistic regression

# Example: Generate score from scaled model
pop1=smbinning.scoring.gen(smbscaled=smbscaled, dataset=pop)

# Example Generate SQL code from scaled model
smbinning.scoring.sql(smbscaled)

Example output

Loading required package: sqldf
Loading required package: gsubfn
Loading required package: proto
Loading required package: RSQLite
Loading required package: partykit
Loading required package: grid
Loading required package: libcoin
Loading required package: mvtnorm
Loading required package: Formula
Warning message:
no DISPLAY variable so Tk is not available 

Call:
glm(formula = f, family = binomial(), data = train)

Deviance Residuals: 
    Min       1Q   Median       3Q      Max  
-3.4327   0.1139   0.2992   0.5367   1.9285  

Coefficients:
                               Estimate Std. Error z value   Pr(>|z|)    
(Intercept)                     1.64857    0.46933   3.513   0.000444 ***
g1cbs101 <= 38.81              -0.28377    0.28880  -0.983   0.325813    
g1cbs102 <= 51.7701            -0.08315    0.25530  -0.326   0.744656    
g1cbs103 <= 65.36               0.23280    0.26466   0.880   0.379068    
g1cbs104 > 65.36                1.41459    0.42884   3.299   0.000972 ***
g1cbinq02 = '01'               -0.50290    0.24139  -2.083   0.037215 *  
g1cbinq03 = '02'               -0.52214    0.26268  -1.988   0.046837 *  
g1cblineut02 <= 40              0.30958    0.26469   1.170   0.242172    
g1cblineut03 <= 50             -0.03859    0.24704  -0.156   0.875880    
g1cblineut04 > 50              -0.15797    0.24977  -0.632   0.527088    
g1pmt02 = 'M'                  -0.35568    0.17135  -2.076   0.037918 *  
g1pmt03 = 'P'                   0.81906    0.35739   2.292   0.021917 *  
g1tob02 <= 2                    0.04055    0.18687   0.217   0.828225    
g1tob03 <= 3                    0.77891    0.23268   3.348   0.000815 ***
g1tob04 > 3                     0.97801    0.27799   3.518   0.000435 ***
g1dpd02 = '01Lo'               -0.44961    0.19375  -2.321   0.020310 *  
g1dpd03 = '02Hi'               -0.90528    0.20462  -4.424 0.00000968 ***
g1dep02 <= 12000                0.13422    0.18412   0.729   0.466026    
g1dep03 <= 15000                0.64105    0.20970   3.057   0.002235 ** 
g1dep04 > 15000                 0.69876    0.32640   2.141   0.032291 *  
g1od02 = '01'                  -0.29232    0.19239  -1.519   0.128658    
g1od03 = '02'                  -0.60999    0.18296  -3.334   0.000856 ***
g1home02 = 'Yes'                0.25855    0.23341   1.108   0.267991    
g1inc01 in ('W01','W02')       -0.50407    0.30014  -1.679   0.093066 .  
g1inc02 in ('W03','W04','W05') -0.42082    0.27068  -1.555   0.120024    
g1inc03 in ('W06','W07')        0.03864    0.28624   0.135   0.892607    
g1inc04 in ('W08','W09','W10')  0.63195    0.28940   2.184   0.028985 *  
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

(Dispersion parameter for binomial family taken to be 1)

    Null deviance: 1807.1  on 1758  degrees of freedom
Residual deviance: 1249.5  on 1732  degrees of freedom
AIC: 1303.5

Number of Fisher Scoring iterations: 6

[[1]]
   Characteristic                 Attribute Coefficient     Weight WeightScaled
1     (Intercept)                            1.64856917  47.567651      0.00000
2          g1cbs1                   00 Miss  0.00000000   0.000000     63.49805
3          g1cbs1               01 <= 38.81 -0.28376561  -8.187745     55.31031
4          g1cbs1             02 <= 51.7701 -0.08315125  -2.399238     61.09881
5          g1cbs1               03 <= 65.36  0.23279610   6.717076     70.21513
6          g1cbs1                04 > 65.36  1.41459065  40.816458    104.31451
7         g1cbinq                 01 = '00'  0.00000000   0.000000     63.49805
8         g1cbinq                 02 = '01' -0.50290341 -14.510725     48.98733
9         g1cbinq                 03 = '02' -0.52214326 -15.065870     48.43218
10     g1cblineut                  01 <= 30  0.00000000   0.000000     63.49805
11     g1cblineut                  02 <= 40  0.30957673   8.932496     72.43055
12     g1cblineut                  03 <= 50 -0.03858686  -1.113381     62.38467
13     g1cblineut                   04 > 50 -0.15796860  -4.558010     58.94004
14          g1pmt                  01 = 'A'  0.00000000   0.000000     63.49805
15          g1pmt                  02 = 'M' -0.35567877 -10.262720     53.23533
16          g1pmt                  03 = 'P'  0.81905784  23.633014     87.13107
17          g1tob                   01 <= 1  0.00000000   0.000000     63.49805
18          g1tob                   02 <= 2  0.04054600   1.169910     64.66796
19          g1tob                   03 <= 3  0.77891039  22.474603     85.97266
20          g1tob                    04 > 3  0.97800870  28.219366     91.71742
21          g1dpd               01 = '00No'  0.00000000   0.000000     63.49805
22          g1dpd               02 = '01Lo' -0.44960718 -12.972921     50.52513
23          g1dpd               03 = '02Hi' -0.90528183 -26.120912     37.37714
24          g1dep               01 <= 10000  0.00000000   0.000000     63.49805
25          g1dep               02 <= 12000  0.13421578   3.872649     67.37070
26          g1dep               03 <= 15000  0.64104694  18.496705     81.99476
27          g1dep                04 > 15000  0.69875582  20.161831     83.65988
28           g1od                 01 = '00'  0.00000000   0.000000     63.49805
29           g1od                 02 = '01' -0.29231846  -8.434528     55.06352
30           g1od                 03 = '02' -0.60998724 -17.600511     45.89754
31         g1home                 01 = 'No'  0.00000000   0.000000     63.49805
32         g1home                02 = 'Yes'  0.25855267   7.460253     70.95830
33          g1inc                   00 Miss  0.00000000   0.000000     63.49805
34          g1inc       01 in ('W01','W02') -0.50406837 -14.544339     48.95371
35          g1inc 02 in ('W03','W04','W05') -0.42082027 -12.142306     51.35575
36          g1inc       03 in ('W06','W07')  0.03864433   1.115040     64.61309
37          g1inc 04 in ('W08','W09','W10')  0.63194734  18.234146     81.73220
   Points
1       0
2      63
3      55
4      61
5      70
6     104
7      63
8      49
9      48
10     63
11     72
12     62
13     59
14     63
15     53
16     87
17     63
18     65
19     86
20     92
21     63
22     51
23     37
24     63
25     67
26     82
27     84
28     63
29     55
30     46
31     63
32     71
33     63
34     49
35     51
36     65
37     82

[1] 536 781
$pdo
[1] 20

$odds
[1] 99

$factor
[1] 28.8539

$score
[1] 720

$offset
[1] 587.4129

$intercept
[1] 1.648569

$interceptweight
[1] 47.56765

$nchr
[1] 10

$interceptbychr
[1] 4.756765

$offsetbychr
[1] 58.74129

$scorebychr
[1] 63.49805


Call:
glm(formula = f, family = binomial(), data = train)

Deviance Residuals: 
    Min       1Q   Median       3Q      Max  
-3.4327   0.1139   0.2992   0.5367   1.9285  

Coefficients:
                               Estimate Std. Error z value   Pr(>|z|)    
(Intercept)                     1.64857    0.46933   3.513   0.000444 ***
g1cbs101 <= 38.81              -0.28377    0.28880  -0.983   0.325813    
g1cbs102 <= 51.7701            -0.08315    0.25530  -0.326   0.744656    
g1cbs103 <= 65.36               0.23280    0.26466   0.880   0.379068    
g1cbs104 > 65.36                1.41459    0.42884   3.299   0.000972 ***
g1cbinq02 = '01'               -0.50290    0.24139  -2.083   0.037215 *  
g1cbinq03 = '02'               -0.52214    0.26268  -1.988   0.046837 *  
g1cblineut02 <= 40              0.30958    0.26469   1.170   0.242172    
g1cblineut03 <= 50             -0.03859    0.24704  -0.156   0.875880    
g1cblineut04 > 50              -0.15797    0.24977  -0.632   0.527088    
g1pmt02 = 'M'                  -0.35568    0.17135  -2.076   0.037918 *  
g1pmt03 = 'P'                   0.81906    0.35739   2.292   0.021917 *  
g1tob02 <= 2                    0.04055    0.18687   0.217   0.828225    
g1tob03 <= 3                    0.77891    0.23268   3.348   0.000815 ***
g1tob04 > 3                     0.97801    0.27799   3.518   0.000435 ***
g1dpd02 = '01Lo'               -0.44961    0.19375  -2.321   0.020310 *  
g1dpd03 = '02Hi'               -0.90528    0.20462  -4.424 0.00000968 ***
g1dep02 <= 12000                0.13422    0.18412   0.729   0.466026    
g1dep03 <= 15000                0.64105    0.20970   3.057   0.002235 ** 
g1dep04 > 15000                 0.69876    0.32640   2.141   0.032291 *  
g1od02 = '01'                  -0.29232    0.19239  -1.519   0.128658    
g1od03 = '02'                  -0.60999    0.18296  -3.334   0.000856 ***
g1home02 = 'Yes'                0.25855    0.23341   1.108   0.267991    
g1inc01 in ('W01','W02')       -0.50407    0.30014  -1.679   0.093066 .  
g1inc02 in ('W03','W04','W05') -0.42082    0.27068  -1.555   0.120024    
g1inc03 in ('W06','W07')        0.03864    0.28624   0.135   0.892607    
g1inc04 in ('W08','W09','W10')  0.63195    0.28940   2.184   0.028985 *  
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

(Dispersion parameter for binomial family taken to be 1)

    Null deviance: 1807.1  on 1758  degrees of freedom
Residual deviance: 1249.5  on 1732  degrees of freedom
AIC: 1303.5

Number of Fisher Scoring iterations: 6

-- Replace 'TableName' with your table in SQL 
alter table TableName add 
g1cbs1Points int not null, 
g1cbinqPoints int not null, 
g1cblineutPoints int not null, 
g1pmtPoints int not null, 
g1tobPoints int not null, 
g1dpdPoints int not null, 
g1depPoints int not null, 
g1odPoints int not null, 
g1homePoints int not null, 
g1incPoints int not null, 
Score int not null 
go 
 
-- Replace 'TableName' with your table in SQL 
update TableName set 
g1cbs1Points=( 
 case 
 when g1cbs1 = '00 Miss' then 63  
 when g1cbs1 = '01 <= 38.81' then 55  
 when g1cbs1 = '02 <= 51.7701' then 61  
 when g1cbs1 = '03 <= 65.36' then 70  
 when g1cbs1 = '04 > 65.36' then 104  
 else Null end 
 ), 
g1cbinqPoints=( 
 case 
 when g1cbinq = '01 = ''00''' then 63  
 when g1cbinq = '02 = ''01''' then 49  
 when g1cbinq = '03 = ''02''' then 48  
 else Null end 
 ), 
g1cblineutPoints=( 
 case 
 when g1cblineut = '01 <= 30' then 63  
 when g1cblineut = '02 <= 40' then 72  
 when g1cblineut = '03 <= 50' then 62  
 when g1cblineut = '04 > 50' then 59  
 else Null end 
 ), 
g1pmtPoints=( 
 case 
 when g1pmt = '01 = ''A''' then 63  
 when g1pmt = '02 = ''M''' then 53  
 when g1pmt = '03 = ''P''' then 87  
 else Null end 
 ), 
g1tobPoints=( 
 case 
 when g1tob = '01 <= 1' then 63  
 when g1tob = '02 <= 2' then 65  
 when g1tob = '03 <= 3' then 86  
 when g1tob = '04 > 3' then 92  
 else Null end 
 ), 
g1dpdPoints=( 
 case 
 when g1dpd = '01 = ''00No''' then 63  
 when g1dpd = '02 = ''01Lo''' then 51  
 when g1dpd = '03 = ''02Hi''' then 37  
 else Null end 
 ), 
g1depPoints=( 
 case 
 when g1dep = '01 <= 10000' then 63  
 when g1dep = '02 <= 12000' then 67  
 when g1dep = '03 <= 15000' then 82  
 when g1dep = '04 > 15000' then 84  
 else Null end 
 ), 
g1odPoints=( 
 case 
 when g1od = '01 = ''00''' then 63  
 when g1od = '02 = ''01''' then 55  
 when g1od = '03 = ''02''' then 46  
 else Null end 
 ), 
g1homePoints=( 
 case 
 when g1home = '01 = ''No''' then 63  
 when g1home = '02 = ''Yes''' then 71  
 else Null end 
 ), 
g1incPoints=( 
 case 
 when g1inc = '00 Miss' then 63  
 when g1inc = '01 in (''W01'',''W02'')' then 49  
 when g1inc = '02 in (''W03'',''W04'',''W05'')' then 51  
 when g1inc = '03 in (''W06'',''W07'')' then 65  
 when g1inc = '04 in (''W08'',''W09'',''W10'')' then 82  
 else Null end 
 ), 
Score=( 
  g1cbs1Points + g1cbinqPoints + g1cblineutPoints + g1pmtPoints + g1tobPoints + g1dpdPoints + g1depPoints + g1odPoints + g1homePoints + g1incPoints
) 

smbinning documentation built on May 1, 2019, 10:06 p.m.