smbinning.psi: Population Stability Index

Description Usage Arguments Value Examples

View source: R/smbinning.R

Description

Often models are developed using multiple periods in time for a number of reasons. For example, to avoid seasonality, to increase the size of the population, and some others. With a metrics like the Population Stability Index (PSI), users can check if there is a significant variation in the distribution of a certain feature by partition (usually time) using the first one as the reference.

Usage

1

Arguments

df

Data frame.

y

Column name the indicates the different partitions.

x

Feature to be evaluated in terms of stability (It must be factor).

Value

Three crosstabs by feature and period that show the frequency (psicnt), percentage (psipct) and PSI (psimg), and a plot for the analyzed characteristic.

Examples

1
2
3
4
5
# Load library and its dataset
library(smbinning)

# Check stability for income
smbinning.psi(df=smbsimdf1,y="period",x="inc") 

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 
$psicnt
      
       2017-12-31 2018-01-31 2018-02-28 2018-03-31 2018-04-30 2018-05-31
  W01          11         14         17         15          8         21
  W02           9         19         18         11         19          8
  W03          16         19         17         14         20         19
  W04          23         14         17         14         16         18
  W05          20         13         14         20         12         23
  W06          25         30         30         23         22         29
  W07          32         18         19         26         23         24
  W08          32         23         35         37         35         37
  W09          36         34         32         37         30         36
  W10          28         37         30         22         25         30
  <NA>         24         13         26         25         22         23
      
       2018-06-30 2018-07-31 2018-08-31 2018-09-30
  W01          22         12          8         16
  W02           9         16          9         11
  W03          24         11         19         27
  W04          22         14         10         19
  W05          13         13         17         18
  W06          23         39         17         26
  W07          22         23         26         25
  W08          43         42         47         37
  W09          34         29         32         36
  W10          31         25         27         30
  <NA>         16         30         23         18

$psipct
      
       2017-12-31 2018-01-31 2018-02-28 2018-03-31 2018-04-30 2018-05-31
  W01  0.04296875 0.05982906 0.06666667 0.06147541 0.03448276 0.07835821
  W02  0.03515625 0.08119658 0.07058824 0.04508197 0.08189655 0.02985075
  W03  0.06250000 0.08119658 0.06666667 0.05737705 0.08620690 0.07089552
  W04  0.08984375 0.05982906 0.06666667 0.05737705 0.06896552 0.06716418
  W05  0.07812500 0.05555556 0.05490196 0.08196721 0.05172414 0.08582090
  W06  0.09765625 0.12820513 0.11764706 0.09426230 0.09482759 0.10820896
  W07  0.12500000 0.07692308 0.07450980 0.10655738 0.09913793 0.08955224
  W08  0.12500000 0.09829060 0.13725490 0.15163934 0.15086207 0.13805970
  W09  0.14062500 0.14529915 0.12549020 0.15163934 0.12931034 0.13432836
  W10  0.10937500 0.15811966 0.11764706 0.09016393 0.10775862 0.11194030
  <NA> 0.09375000 0.05555556 0.10196078 0.10245902 0.09482759 0.08582090
      
       2018-06-30 2018-07-31 2018-08-31 2018-09-30
  W01  0.08494208 0.04724409 0.03404255 0.06083650
  W02  0.03474903 0.06299213 0.03829787 0.04182510
  W03  0.09266409 0.04330709 0.08085106 0.10266160
  W04  0.08494208 0.05511811 0.04255319 0.07224335
  W05  0.05019305 0.05118110 0.07234043 0.06844106
  W06  0.08880309 0.15354331 0.07234043 0.09885932
  W07  0.08494208 0.09055118 0.11063830 0.09505703
  W08  0.16602317 0.16535433 0.20000000 0.14068441
  W09  0.13127413 0.11417323 0.13617021 0.13688213
  W10  0.11969112 0.09842520 0.11489362 0.11406844
  <NA> 0.06177606 0.11811024 0.09787234 0.06844106

$psimg
     2017-12-31 2018-01-31 2018-02-28 2018-03-31 2018-04-30 2018-05-31
W01  0.00000000 0.00558107 0.01040888 0.00662842 0.00186703 0.02126261
W02  0.00000000 0.03853901 0.02469826 0.00246833 0.03952615 0.00086794
W03  0.00000000 0.00489302 0.00026891 0.00043813 0.00762375 0.00105818
W04  0.00000000 0.01220339 0.00691528 0.01455897 0.00552157 0.00659821
W05  0.00000000 0.00769452 0.00819218 0.00018446 0.01088733 0.00072305
W06  0.00000000 0.00831473 0.00372300 0.00012005 0.00008314 0.00108282
W07  0.00000000 0.02334172 0.02612277 0.00294400 0.00599487 0.01182153
W08  0.00000000 0.00642055 0.00114615 0.00514649 0.00486342 0.00129777
W09  0.00000000 0.00015283 0.00172339 0.00083057 0.00094909 0.00028845
W10  0.00000000 0.01796581 0.00060309 0.00371067 0.00002407 0.00005947
<NA> 0.00000000 0.01998517 0.00068935 0.00077363 0.00001232 0.00070069
PSI  0.00000000 0.14509182 0.08449126 0.03780372 0.07735274 0.04576072
     2018-06-30 2018-07-31 2018-08-31 2018-09-30
W01  0.02860468 0.00040554 0.00207857 0.00621292
W02  0.00000474 0.01623409 0.00026890 0.00115834
W03  0.01187906 0.00704093 0.00472434 0.01993106
W04  0.00027500 0.01696673 0.03534105 0.00383745
W05  0.01235803 0.01139565 0.00044499 0.00128154
W06  0.00084134 0.02529051 0.00759653 0.00001473
W07  0.01547614 0.01110625 0.00175281 0.00819948
W08  0.01164293 0.01129021 0.03525027 0.00185398
W09  0.00064342 0.00551202 0.00014340 0.00010097
W10  0.00092981 0.00115505 0.00027165 0.00019720
<NA> 0.01333683 0.00562689 0.00017739 0.00796368
PSI  0.09599198 0.11202387 0.08804990 0.05075135

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