Title: | Shiny User Interface for 'monobin' Package |
---|---|
Description: | This is an add-on package to the 'monobin' package that simplifies its use. It provides shiny-based user interface (UI) that is especially handy for less experienced 'R' users as well as for those who intend to perform quick scanning of numeric risk factors when building credit rating models. The additional functions implemented in 'monobinShiny' that do no exist in 'monobin' package are: descriptive statistics, special case and outliers imputation. The function descriptive statistics is exported and can be used in 'R' sessions independently from the user interface, while special case and outlier imputation functions are written to be used with shiny UI. |
Authors: | Andrija Djurovic [aut, cre] |
Maintainer: | Andrija Djurovic <[email protected]> |
License: | GPL (>= 3) |
Version: | 0.1.0 |
Built: | 2025-03-09 03:11:10 UTC |
Source: | https://github.com/andrija-djurovic/monobinshiny |
Server side for monobin functions' inputs
algo.ui(id)
algo.ui(id)
id |
Namespace id. |
No return value, server side call for user interface of the selected binning algorithm.
if (interactive()) { algo.ui(id = "monobin") }
if (interactive()) { algo.ui(id = "monobin") }
Check for categorical variables when importing the data
check.vars(tbl)
check.vars(tbl)
tbl |
Imported data frame. |
Returns a character vector which describes variables type of imported data frame.
if (interactive()) { check.msg <- check.vars(tbl = rv$db) }
if (interactive()) { check.msg <- check.vars(tbl = rv$db) }
cum.bin - monobin functions' inputs
cum.ui(id)
cum.ui(id)
id |
Namespace id. |
No return value, called for user interface of the cum.bin - monobin functions' inputs.
if (interactive()) { output$algo.args <- renderUI({tagList(switch(algo.select, "cum.bin" = cum.ui(id = id), "iso.bin" = iso.ui(id = id), "ndr.bin" = ndr.sts.ui(id = id), "sts.bin" = ndr.sts.ui(id = id), "pct.bin" = pct.ui(id = id), "woe.bin" = woe.ui(id = id), "mdt.bin" = mdt.ui(id = id))) }) }
if (interactive()) { output$algo.args <- renderUI({tagList(switch(algo.select, "cum.bin" = cum.ui(id = id), "iso.bin" = iso.ui(id = id), "ndr.bin" = ndr.sts.ui(id = id), "sts.bin" = ndr.sts.ui(id = id), "pct.bin" = pct.ui(id = id), "woe.bin" = woe.ui(id = id), "mdt.bin" = mdt.ui(id = id))) }) }
Descriptive statistics report
desc.report(target, rf, sc, sc.method, db)
desc.report(target, rf, sc, sc.method, db)
target |
Selected target. |
rf |
Vector of a selected numeric risk factors. |
sc |
Numeric vector of special case values. |
sc.method |
Define how special cases will be treated, all together or in separate bins. |
db |
Data frame of target and numeric risk factors. |
Returns a data frame with descriptive statistics for the selected risk drivers.
if (interactive()) { srv$desc.stat <- withProgress(message = "Running descriptive statistics report", value = 0, { desc.report(target = "qual", rf = rf, sc = sc, sc.method = sc.method, db = isolate(rv$db)) }) }
if (interactive()) { srv$desc.stat <- withProgress(message = "Running descriptive statistics report", value = 0, { desc.report(target = "qual", rf = rf, sc = sc, sc.method = sc.method, db = isolate(rv$db)) }) }
desc.stat
returns the descriptive statistics of numeric risk factor. Reported metrics covers mainly
univariate and part of bivariate analysis which are usually standard steps in credit rating model development.
Metrics are reported for special (if exists) and complete case groups separately.
Report includes:
risk.factor: Risk factor name.
type: Special case or complete case group.
bin: When special case method is together
then bin is the same as type, otherwise
all special cases are reported separately.
cnt: Number of observations.
pct: Percentage of observations.
min: Minimum value.
p1, p5, p25, p50, p75, p95, p99: Percentile values.
avg: Mean value.
avg.se: Standard error of mean.
max: Maximum value.
neg: Number of negative values.
pos: Number of positive values.
cnt.outliers: Number of outliers.
Records above and below Q75 + 1.5 * IQR
, where IQR = Q75 - Q25
, where
IQR is interquartile range.
desc.stat(x, y, sc = c(NA, NaN, Inf), sc.method = "together")
desc.stat(x, y, sc = c(NA, NaN, Inf), sc.method = "together")
x |
Numeric risk factor. |
y |
Numeric target vector (binary or continuous). |
sc |
Numeric vector with special case elements. Default values are c(NA, NaN, Inf). Recommendation is to keep the default values always and add new ones if needed. Otherwise, if these values exist in x and are not defined in the sc vector, function will report the error. |
sc.method |
Define how special cases will be treated, all together or in separate bins.
Possible values are |
Data frame of descriptive statistics metrics, separately for complete and special case groups.
suppressMessages(library(monobinShiny)) data(gcd) desc.stat(x = gcd$age, y = gcd$qual) gcd$age[1:10] <- NA gcd$age[50:75] <- Inf desc.stat(x = gcd$age, y = gcd$qual, sc.method = "together") desc.stat(x = gcd$age, y = gcd$qual, sc.method = "separately")
suppressMessages(library(monobinShiny)) data(gcd) desc.stat(x = gcd$age, y = gcd$qual) gcd$age[1:10] <- NA gcd$age[50:75] <- Inf desc.stat(x = gcd$age, y = gcd$qual, sc.method = "together") desc.stat(x = gcd$age, y = gcd$qual, sc.method = "separately")
Descriptive statistics and imputation module - server side
di.server(id)
di.server(id)
id |
Namespace id. |
No return value, called for descriptive statistics and imputation module server side.
if (interactive()) { di.server(id = "desc.imputation") }
if (interactive()) { di.server(id = "desc.imputation") }
Descriptive statistics and imputation module - user interface
di.ui(id)
di.ui(id)
id |
Namespace id. |
No return value, called for descriptive statistics and imputation module user interface.
if (interactive()) { di.ui(id = "desc.imputation") }
if (interactive()) { di.ui(id = "desc.imputation") }
Data manager module - server side
dm.server(id)
dm.server(id)
id |
Namespace id. |
No return value, called for data manager module server side.
if (interactive()) { dm.server(id = "data.manager") }
if (interactive()) { dm.server(id = "data.manager") }
Data manager module - user interface
dm.ui(id)
dm.ui(id)
id |
Namespace id. |
No return value, called for data manager module user interface.
if (interactive()) { dm.ui(id = "data.manager") }
if (interactive()) { dm.ui(id = "data.manager") }
Hide download buttons from descriptive statistics module
hide.dwnl.buttons(id)
hide.dwnl.buttons(id)
id |
Namespace id. |
No return value, called in order to hide download buttons (imp.div and out.div) from descriptive statistics module.
if (interactive()) { observeEvent(rv$dwnl.sync, { hide.dwnl.buttons(id = "desc.imputation") }, ignoreInit = TRUE) }
if (interactive()) { observeEvent(rv$dwnl.sync, { hide.dwnl.buttons(id = "desc.imputation") }, ignoreInit = TRUE) }
iso.bin - monobin functions' inputs
iso.ui(id)
iso.ui(id)
id |
Namespace id. |
No return value, called for user interface of the iso.bin - monobin functions' inputs.
if (interactive()) { output$algo.args <- renderUI({tagList(switch(algo.select, "cum.bin" = cum.ui(id = id), "iso.bin" = iso.ui(id = id), "ndr.bin" = ndr.sts.ui(id = id), "sts.bin" = ndr.sts.ui(id = id), "pct.bin" = pct.ui(id = id), "woe.bin" = woe.ui(id = id), "mdt.bin" = mdt.ui(id = id))) }) }
if (interactive()) { output$algo.args <- renderUI({tagList(switch(algo.select, "cum.bin" = cum.ui(id = id), "iso.bin" = iso.ui(id = id), "ndr.bin" = ndr.sts.ui(id = id), "sts.bin" = ndr.sts.ui(id = id), "pct.bin" = pct.ui(id = id), "woe.bin" = woe.ui(id = id), "mdt.bin" = mdt.ui(id = id))) }) }
Monobin module - server side
mb.server(id)
mb.server(id)
id |
Namespace id. |
No return value, called for monobin module server side.
if (interactive()) { mb.server(id = "monobin") }
if (interactive()) { mb.server(id = "monobin") }
Monobin module - user interface
mb.ui(id)
mb.ui(id)
id |
Namespace id. |
No return value, called for monobin module user interface.
if (interactive()) { mb.ui(id = "monobin") }
if (interactive()) { mb.ui(id = "monobin") }
mdt.bin - monobin functions' inputs
mdt.ui(id)
mdt.ui(id)
id |
Namespace id. |
No return value, called for user interface of the iso.bin - monobin functions' inputs.
if (interactive()) { output$algo.args <- renderUI({tagList(switch(algo.select, "cum.bin" = cum.ui(id = id), "iso.bin" = iso.ui(id = id), "ndr.bin" = ndr.sts.ui(id = id), "sts.bin" = ndr.sts.ui(id = id), "pct.bin" = pct.ui(id = id), "woe.bin" = woe.ui(id = id), "mdt.bin" = mdt.ui(id = id))) }) }
if (interactive()) { output$algo.args <- renderUI({tagList(switch(algo.select, "cum.bin" = cum.ui(id = id), "iso.bin" = iso.ui(id = id), "ndr.bin" = ndr.sts.ui(id = id), "sts.bin" = ndr.sts.ui(id = id), "pct.bin" = pct.ui(id = id), "woe.bin" = woe.ui(id = id), "mdt.bin" = mdt.ui(id = id))) }) }
Check for numeric arguments - monobin module
mono.inputs.check(x, args.e)
mono.inputs.check(x, args.e)
x |
Binning algorithm from monobin package. |
args.e |
Argument elements of the selected monobin function. |
Returns a list of two vectors: logical if validation is successful and character vector with validation message.
if (interactive()) { num.inp <- mono.inputs.check(x = bin.algo, args.e = args.e) }
if (interactive()) { num.inp <- mono.inputs.check(x = bin.algo, args.e = args.e) }
Evaluation expression of the selected monobin function and its arguments
monobin.fun(x)
monobin.fun(x)
x |
Binning algorithm from monobin package. |
Returns an evaluation expression of the selected monobin algorithm.
if (interactive()) { expr.eval <- monobin.fun(x = algo) } monobin.fun(x = "ndr.bin")
if (interactive()) { expr.eval <- monobin.fun(x = algo) } monobin.fun(x = "ndr.bin")
Run monobin algorithm for the selected inputs
monobin.run(algo, target.n, rf, sc, args.e, db)
monobin.run(algo, target.n, rf, sc, args.e, db)
algo |
Binning algorithm from monobin package. |
target.n |
Selected target. |
rf |
Vector of a selected numeric risk factors. |
sc |
Numeric vector of special case values. |
args.e |
Argument elements of the selected monobin function. |
db |
Data frame of target and numeric risk factors. |
Returns a list of two data frame. The first data frame contains the results of implemented binning algorithm, while the second one contains transformed risk factors.
if (interactive()) { tbls <- withProgress(message = "Running the binning algorithm", value = 0, { suppressWarnings( monobin.run(algo = bin.algo, target.n = isolate(input$trg.select), rf = isolate(input$rf.select), sc = scr.check.res[[1]], args.e = args.e, db = isolate(rv$db)) )}) }
if (interactive()) { tbls <- withProgress(message = "Running the binning algorithm", value = 0, { suppressWarnings( monobin.run(algo = bin.algo, target.n = isolate(input$trg.select), rf = isolate(input$rf.select), sc = scr.check.res[[1]], args.e = args.e, db = isolate(rv$db)) )}) }
Starts shiny application for the monobin package
monobinShinyApp()
monobinShinyApp()
Starts shiny application for the monobin package.
if (interactive()) { suppressMessages(library(monobinShiny)) monobinShinyApp() }
if (interactive()) { suppressMessages(library(monobinShiny)) monobinShinyApp() }
ndr.bin / sts.bin - monobin functions' inputs
ndr.sts.ui(id)
ndr.sts.ui(id)
id |
Namespace id. |
No return value, called for user interface of the ndr.bin / sts.bin - monobin functions' inputs.
if (interactive()) { output$algo.args <- renderUI({tagList(switch(algo.select, "cum.bin" = cum.ui(id = id), "iso.bin" = iso.ui(id = id), "ndr.bin" = ndr.sts.ui(id = id), "sts.bin" = ndr.sts.ui(id = id), "pct.bin" = pct.ui(id = id), "woe.bin" = woe.ui(id = id), "mdt.bin" = mdt.ui(id = id))) }) }
if (interactive()) { output$algo.args <- renderUI({tagList(switch(algo.select, "cum.bin" = cum.ui(id = id), "iso.bin" = iso.ui(id = id), "ndr.bin" = ndr.sts.ui(id = id), "sts.bin" = ndr.sts.ui(id = id), "pct.bin" = pct.ui(id = id), "woe.bin" = woe.ui(id = id), "mdt.bin" = mdt.ui(id = id))) }) }
Numeric arguments - monobin module
num.inputs(x)
num.inputs(x)
x |
Binning algorithm from monobin package. |
Returns a list of two vectors: index and UI element label of numeric arguments of the selected monobin function.
if (interactive()) { inp.indx <- num.inputs(x = x) } num.inputs(x = "cum.bin")
if (interactive()) { inp.indx <- num.inputs(x = x) } num.inputs(x = "cum.bin")
Outliers imputation
out.impute(tbl, rf, ub, lb, sc)
out.impute(tbl, rf, ub, lb, sc)
tbl |
Data frame with risk factors ready for imputation. |
rf |
Vector of risk factors to be imputed. |
ub |
Upper bound percentiles. |
lb |
Lower bound percentiles. |
sc |
Numeric vector of special case values. |
Returns a list of three elements. The first element is a data frame with imputed values, the second element is a vector of newly created risk factors (with imputed values) and the third one is a data frame with information about possible imputation errors.
if (interactive()) { imp.res <- suppressWarnings( out.impute(tbl = rv$db, rf = input$rf.out, ub = upper.pct, lb = lower.pct, sc = sca.check.res[[1]]) ) }
if (interactive()) { imp.res <- suppressWarnings( out.impute(tbl = rv$db, rf = input$rf.out, ub = upper.pct, lb = lower.pct, sc = sca.check.res[[1]]) ) }
pct.bin - monobin functions' inputs
pct.ui(id)
pct.ui(id)
id |
Namespace id. |
No return value, called for user interface of the pct.bin - monobin functions' inputs.
if (interactive()) { output$algo.args <- renderUI({tagList(switch(algo.select, "cum.bin" = cum.ui(id = id), "iso.bin" = iso.ui(id = id), "ndr.bin" = ndr.sts.ui(id = id), "sts.bin" = ndr.sts.ui(id = id), "pct.bin" = pct.ui(id = id), "woe.bin" = woe.ui(id = id), "mdt.bin" = mdt.ui(id = id))) }) }
if (interactive()) { output$algo.args <- renderUI({tagList(switch(algo.select, "cum.bin" = cum.ui(id = id), "iso.bin" = iso.ui(id = id), "ndr.bin" = ndr.sts.ui(id = id), "sts.bin" = ndr.sts.ui(id = id), "pct.bin" = pct.ui(id = id), "woe.bin" = woe.ui(id = id), "mdt.bin" = mdt.ui(id = id))) }) }
Special cases - check input values
sc.check(x)
sc.check(x)
x |
Numeric vector of special case values. |
Returns a list of three vectors: special case input(s) converted to numeric type,
number of special case input(s) that cannot be converted to
numeric type (including NA
, NaN
and Inf
) and special case input(s)
that cannot be converted to numeric type.
if (interactive()) { sca.check.res <- sc.check(x = input$sc.all) scr.check.res <- sc.check(x = input$sc.replace) } sc.check(x = "NA, NaN, Inf") sc.check(x = "NA, abc") sc.check(x = "NaN, abc") sc.check(x = "Inf, abc") sc.check(x = "9999999999, abc") sc.check(x = "NA, NaN, Inf, 9999999999")
if (interactive()) { sca.check.res <- sc.check(x = input$sc.all) scr.check.res <- sc.check(x = input$sc.replace) } sc.check(x = "NA, NaN, Inf") sc.check(x = "NA, abc") sc.check(x = "NaN, abc") sc.check(x = "Inf, abc") sc.check(x = "9999999999, abc") sc.check(x = "NA, NaN, Inf, 9999999999")
Special case imputation
sc.impute(tbl, rf, sc, sc.replace, imp.method)
sc.impute(tbl, rf, sc, sc.replace, imp.method)
tbl |
Data frame with risk factors ready for imputation. |
rf |
Vector of risk factors to be imputed. |
sc |
Numeric vector of special case values. |
sc.replace |
Numeric vector of special case values that are selected for imputation. |
imp.method |
Imputation method (mean or median). |
Returns a list of three elements. The first element is a data frame with imputed values, the second element is a vector of newly created risk factors (with imputed values) and the third one is a data frame with information about possible imputation errors.
if (interactive()) { imp.res <- suppressWarnings( sc.impute(tbl = rv$db, rf = rf, sc = sca.check.res[[1]], sc.replace = scr.check.res[[1]], imp.method = imp.method) ) }
if (interactive()) { imp.res <- suppressWarnings( sc.impute(tbl = rv$db, rf = rf, sc = sca.check.res[[1]], sc.replace = scr.check.res[[1]], imp.method = imp.method) ) }
Sync between descriptive statistics and monobin module after data import
sync.m23(id, num.rf, module)
sync.m23(id, num.rf, module)
id |
Namespace id. |
num.rf |
Vector of updated numeric risk factors. |
module |
Descriptive statistic or monobin module. |
No return value, called in order to sync between descriptive statistics and monobin modules' UI elements after data import.
if (interactive()) { observeEvent(rv$sync, { sync.m23(id = "desc.imputation", num.rf = rv$num.rf, module = "desc") sync.m23(id = "monobin", num.rf = rv$num.rf, module = "monobin") rv$rf.imp <- NULL rv$rf.out <- NULL }, ignoreInit = TRUE) }
if (interactive()) { observeEvent(rv$sync, { sync.m23(id = "desc.imputation", num.rf = rv$num.rf, module = "desc") sync.m23(id = "monobin", num.rf = rv$num.rf, module = "monobin") rv$rf.imp <- NULL rv$rf.out <- NULL }, ignoreInit = TRUE) }
Sync between descriptive statistics and monobin module after imputation process
sync.m23.imp(id, num.rf, module)
sync.m23.imp(id, num.rf, module)
id |
Namespace id. |
num.rf |
Vector of updated numeric risk factors. |
module |
Descriptive statistic or monobin module. |
No return value, called in order to sync between descriptive statistics and monobin modules' UI elements after imputation process.
if (interactive()) { observeEvent(rv$sync2, { rf.update.2 <- c(rv$num.rf[!rv$num.rf%in%rv$target.select.2], rv$rf.imp, rv$rf.out) sync.m23.imp(id = "desc.imputation", num.rf = rf.update.2, module = "desc") }, ignoreInit = TRUE) }
if (interactive()) { observeEvent(rv$sync2, { rf.update.2 <- c(rv$num.rf[!rv$num.rf%in%rv$target.select.2], rv$rf.imp, rv$rf.out) sync.m23.imp(id = "desc.imputation", num.rf = rf.update.2, module = "desc") }, ignoreInit = TRUE) }
Update data manager UI output
upd.dm(id, dummy)
upd.dm(id, dummy)
id |
Namespace id. |
dummy |
A logical value indicating whether gcd data (from monobin package) or specific csv file are imported. |
No return value, called in order to update data manager UI output after data import.
if (interactive()) { observeEvent(rv$dm.uptd, { upd.dm(id = "data.manager", dummy = rv$import.dummy) }, ignoreInit = TRUE) }
if (interactive()) { observeEvent(rv$dm.uptd, { upd.dm(id = "data.manager", dummy = rv$import.dummy) }, ignoreInit = TRUE) }
Sync between descriptive statistics and monobin module
upd.si.m23(upd.rf, num.rf, session)
upd.si.m23(upd.rf, num.rf, session)
upd.rf |
Vector of risk factor field ids that need to be updated. |
num.rf |
Vector of updated numeric risk factors. |
session |
Session object. |
No return value, called in order to sync between descriptive statistics and monobin modules' UI elements after imputation procedures.
if (interactive()) { upd.si.m23(upd.rf = upd.rf, num.rf = num.rf, session = session) }
if (interactive()) { upd.si.m23(upd.rf = upd.rf, num.rf = num.rf, session = session) }
woe.bin - monobin functions' inputs
woe.ui(id)
woe.ui(id)
id |
Namespace id. |
No return value, called for user interface of the woe.bin - monobin functions' inputs.
if (interactive()) { output$algo.args <- renderUI({tagList(switch(algo.select, "cum.bin" = cum.ui(id = id), "iso.bin" = iso.ui(id = id), "ndr.bin" = ndr.sts.ui(id = id), "sts.bin" = ndr.sts.ui(id = id), "pct.bin" = pct.ui(id = id), "woe.bin" = woe.ui(id = id), "mdt.bin" = mdt.ui(id = id))) }) }
if (interactive()) { output$algo.args <- renderUI({tagList(switch(algo.select, "cum.bin" = cum.ui(id = id), "iso.bin" = iso.ui(id = id), "ndr.bin" = ndr.sts.ui(id = id), "sts.bin" = ndr.sts.ui(id = id), "pct.bin" = pct.ui(id = id), "woe.bin" = woe.ui(id = id), "mdt.bin" = mdt.ui(id = id))) }) }