prettyglm
prettyglm provides a set of functions which can easily create beautiful coefficient summaries which can readily be shared and explained.
Science Score: 26.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
○CITATION.cff file
-
✓codemeta.json file
Found codemeta.json file -
✓.zenodo.json file
Found .zenodo.json file -
○DOI references
-
○Academic publication links
-
○Academic email domains
-
○Institutional organization owner
-
○JOSS paper metadata
-
○Scientific vocabulary similarity
Low similarity (23.0%) to scientific vocabulary
Keywords
classification
classification-model
data-science
data-visualization
glm
linear-models
r
r-package
regression
regression-analysis
regression-model
regression-models
rstats
rstats-package
statistical-models
Last synced: 6 months ago
·
JSON representation
Repository
prettyglm provides a set of functions which can easily create beautiful coefficient summaries which can readily be shared and explained.
Basic Info
- Host: GitHub
- Owner: jared-fowler
- Language: R
- Default Branch: master
- Homepage: https://jared-fowler.github.io/prettyglm
- Size: 17.5 MB
Statistics
- Stars: 3
- Watchers: 1
- Forks: 2
- Open Issues: 0
- Releases: 0
Topics
classification
classification-model
data-science
data-visualization
glm
linear-models
r
r-package
regression
regression-analysis
regression-model
regression-models
rstats
rstats-package
statistical-models
Created over 5 years ago
· Last pushed 11 months ago
Metadata Files
Readme
Changelog
README.Rmd
---
output: github_document
---
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```
# prettyglm
[](https://cran.r-project.org/package=prettyglm)
[](https://cran.r-project.org/package=prettyglm)
[](https://github.com/jared-fowler/prettyglm/actions)
[](https://lifecycle.r-lib.org/articles/stages.html#stable)
One of the main advantages of using Generalised Linear Models is their interpretability. The goal of prettyglm is to provide a set of functions which easily create beautiful coefficient summaries which can readily be shared and explained.
## Forword
`prettyglm` was created to solve some common faced when building Generalised Linear Models, such as displaying categorical base levels, and visualizing the number of records in each category on a duel axis. Since then a number of other functions which are useful when fitting glms have been added.
If you don't find the function you are looking for here consider checking out some other great packages which help visualize the output from glms:`tidycat`, `jtools` or `GGally`
## Installation
You can install the latest CRAN release with:
``` r
install.packages('prettyglm')
```
## Documentation
Please see the website [prettyglm]( https://jared-fowler.github.io/prettyglm/) for more detailed documentation and examples.
## A Simple Example
To explore the functionality of prettyglm we will use a data set sourced from [kaggle](https://www.kaggle.com/volodymyrgavrysh/bank-marketing-campaigns-dataset) which contains information about a Portugal banks marketing campaigns results. The campaign was based mostly on direct phone calls, offering clients a term deposit. The target variable `y` indicates if the client agreed to place the deposit after the phone call.
### Pre-processing
A critical step for this package to work well is to **set all categorical predictors as factors**.
```{r preprocessing, echo=TRUE, message=FALSE, warning=FALSE}
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
```
### Building a glm
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.
```{r build model, echo=TRUE}
deposit_model <- stats::glm(T_DEPOSIT ~ marital +
default:loan +
loan +
age,
data = bank_data,
family = binomial)
```
### Visualising Fitted Model Coefficients
#### Create table of model coefficients with `pretty_coefficients()`
* `pretty_coefficients()` automatically includes categorical variable base levels.
* You can complete a type III test on the coefficients by specifying a `type_iii` argument.
* You can include a "relativity" column in the output by including a `relativity_transform` input. (Note "relativity" is sometimes referred to as "likelihood" or "odds-ratio", you can change the title of this column with the `relativity_label` input.)
* You can return the data set instead of `kable` but setting `Return_Data = TRUE`
```{r visualise coefficients type iii, eval=FALSE, include=TRUE}
pretty_coefficients(deposit_model, type_iii = 'Wald')
```
#### Create plots of the model relativities with `pretty_relativities()`
* A model relativity is a transform of the model estimate. By default `pretty_relativities()` uses 'exp(estimate)-1' which is useful for GLM's which use a log or logit link function.
* `pretty_relativities()` automatically extracts the training data from the model object and plots the number of records on the second y axis.
```{r visualise relativitiy, eval=FALSE, include=TRUE}
pretty_relativities(feature_to_plot = 'marital',
model_object = deposit_model)
```
* If the variable you are plotting is a continuous variable `prettyglm` will plot the density on a second axis, and attempt to plot the fit with confidence intervals.
```{r age visualise relativitiy, eval=FALSE, include=TRUE}
pretty_relativities(feature_to_plot = 'age',
model_object = deposit_model)
```
* For interactions you can colour or facet by one of the variables.
```{r default visualise relativitiy, eval=FALSE, include=TRUE}
pretty_relativities(feature_to_plot = 'default:loan',
model_object = deposit_model,
iteractionplottype = 'colour',
facetorcolourby = 'loan')
```
### Visualising one-way model performance with `one_way_ave()`
`one_way_ave()` creates one-way model performance plots.
#### education
For discrete variables the number of records in each group will be plotted on a second axis.
```{r education ave, eval=FALSE, include=TRUE}
one_way_ave(feature_to_plot = 'education',
model_object = deposit_model,
target_variable = 'T_DEPOSIT',
data_set = bank_data)
```
#### age
For continuous variables the `stats::density()` will be plotted on a second axis.
```{r aeg ave, eval=FALSE, include=TRUE}
one_way_ave(feature_to_plot = 'age',
model_object = deposit_model,
target_variable = 'T_DEPOSIT',
data_set = bank_data)
```
#### Plot actual vs expected by predicted band with `actual_expected_bucketed()`
`actual_expected_bucketed()` creates actual vs expected performance plots by predicted band.
```{r visualise actual_expected_bucketed, eval=FALSE, include=TRUE}
actual_expected_bucketed(target_variable = 'T_DEPOSIT',
model_object = deposit_model,
data_set = bank_data)
```
### Support My Work
[](https://www.buymeacoffee.com/tictap)
Owner
- Name: Jared Fowler
- Login: jared-fowler
- Kind: user
- Location: Australia
- Repositories: 1
- Profile: https://github.com/jared-fowler
GitHub Events
Total
- Push event: 2
- Pull request event: 1
Last Year
- Push event: 2
- Pull request event: 1
Issues and Pull Requests
Last synced: 6 months ago
All Time
- Total issues: 0
- Total pull requests: 2
- Average time to close issues: N/A
- Average time to close pull requests: 5 months
- Total issue authors: 0
- Total pull request authors: 2
- Average comments per issue: 0
- Average comments per pull request: 0.5
- Merged pull requests: 1
- Bot issues: 0
- Bot pull requests: 0
Past Year
- Issues: 0
- Pull requests: 0
- Average time to close issues: N/A
- Average time to close pull requests: N/A
- Issue authors: 0
- Pull request authors: 0
- Average comments per issue: 0
- Average comments per pull request: 0
- Merged pull requests: 0
- Bot issues: 0
- Bot pull requests: 0
Top Authors
Issue Authors
Pull Request Authors
- haozhu233 (2)
- olivroy (2)
Top Labels
Issue Labels
Pull Request Labels
Packages
- Total packages: 1
-
Total downloads:
- cran 330 last-month
- Total dependent packages: 0
- Total dependent repositories: 0
- Total versions: 3
- Total maintainers: 1
cran.r-project.org: prettyglm
Pretty Summaries of Generalized Linear Model Coefficients
- Homepage: https://jared-fowler.github.io/prettyglm/
- Documentation: http://cran.r-project.org/web/packages/prettyglm/prettyglm.pdf
- License: GPL-3
-
Latest release: 1.0.1
published over 2 years ago
Rankings
Forks count: 21.9%
Stargazers count: 26.2%
Dependent packages count: 29.8%
Average: 34.7%
Dependent repos count: 35.5%
Downloads: 60.0%
Maintainers (1)
Last synced:
6 months ago
Dependencies
.github/workflows/R-CMD-check.yaml
actions
- actions/cache v2 composite
- actions/checkout v2 composite
- actions/upload-artifact main composite
- r-lib/actions/setup-pandoc v1 composite
- r-lib/actions/setup-r v1 composite
.github/workflows/pkgdown.yaml
actions
- JamesIves/github-pages-deploy-action v4.4.1 composite
- actions/checkout v3 composite
- r-lib/actions/setup-pandoc v2 composite
- r-lib/actions/setup-r v2 composite
- r-lib/actions/setup-r-dependencies v2 composite
DESCRIPTION
cran
- R >= 2.10 depends
- RColorBrewer * imports
- broom * imports
- car * imports
- dplyr * imports
- forcats * imports
- kableExtra * imports
- knitr * imports
- methods * imports
- plotly * imports
- stringr * imports
- tibble * imports
- tidycat * imports
- tidyr * imports
- tidyselect * imports
- vip * imports
- rmarkdown * suggests
- testthat * suggests