prettyglm is an R package which provides a set of functions which create beautiful coefficient summaries of generalised linear models.
You can install the latest CRAN release with:
install.packages('prettyglm')
To explore the functionality of prettyglm we will use a data set sourced from kaggle. To learn more about each of the provided functions please read the articles.
A critical step for this package to work well is to set all categorical predictors as factors.
library(prettyglm)
library(dplyr)
data("bank")
# Easiest way to convert multiple columns to a factor.
columns_to_factor <- c('job',
'marital',
'education',
'default',
'housing',
'loan')
bank_data <- bank_data %>%
dplyr::filter(loan != 'unknown') %>%
dplyr::filter(default != 'yes') %>%
dplyr::mutate(age = as.numeric(age)) %>%
dplyr::mutate_at(columns_to_factor, list(~factor(.))) %>% # multiple columns to factor
dplyr::mutate(T_DEPOSIT = as.factor(base::ifelse(y=='yes',1,0))) #convert target to 0 and 1 for performance plots
For this example we will build a glm using stats::glm()
, however
prettyglm
is working to support parsnip
and workflow
model objects
which use the glm model engine.
deposit_model <- stats::glm(T_DEPOSIT ~ marital +
default:loan +
loan +
age,
data = bank_data,
family = binomial)
pretty_coefficients()
creates a neat table of the model coefficients,
see vignette("creating_pretty_coefficients")
.
pretty_coefficients(deposit_model, type_iii = 'Wald')
pretty_relativities()
creates beautiful plots of model coefficients,
see vignette("simple_pretty_relativities")
and
vignette("interaction_pretty_relativities")
to get started.
pretty_relativities(feature_to_plot = 'marital',
model_object = deposit_model)
pretty_relativities(feature_to_plot = 'age',
model_object = deposit_model)
pretty_relativities(feature_to_plot = 'default:loan',
model_object = deposit_model,
iteractionplottype = 'colour',
facetorcolourby = 'loan')
one_way_ave()
creates one-way model performance plots, see
vignette("onewayave")
to get started.
one_way_ave(feature_to_plot = 'age',
model_object = deposit_model,
target_variable = 'T_DEPOSIT',
data_set = bank_data)
one_way_ave(feature_to_plot = 'education',
model_object = deposit_model,
target_variable = 'T_DEPOSIT',
data_set = bank_data)
actual_expected_bucketed()
creates actual vs expected performance
plots by predicted band, see vignette("visualisingoverallave")
to get
started.
actual_expected_bucketed(target_variable = 'T_DEPOSIT',
model_object = deposit_model)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.