{"id":33187130,"url":"https://jared-fowler.github.io/prettyglm/","last_synced_at":"2025-11-25T18:00:40.833Z","repository":{"id":143716735,"uuid":"298994335","full_name":"jared-fowler/prettyglm","owner":"jared-fowler","description":"prettyglm provides a set of functions which can easily create beautiful coefficient summaries which can readily be shared and explained.","archived":false,"fork":false,"pushed_at":"2025-04-09T04:59:26.000Z","size":18302,"stargazers_count":3,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-11-20T18:14:06.352Z","etag":null,"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"],"latest_commit_sha":null,"homepage":"https://jared-fowler.github.io/prettyglm","language":"R","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jared-fowler.png","metadata":{"files":{"readme":"README.Rmd","changelog":"NEWS.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2020-09-27T09:10:54.000Z","updated_at":"2025-04-09T04:55:15.000Z","dependencies_parsed_at":"2024-01-18T04:08:09.030Z","dependency_job_id":"219d906f-ccea-4910-bde4-da810ac7b6be","html_url":"https://github.com/jared-fowler/prettyglm","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/jared-fowler/prettyglm","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jared-fowler%2Fprettyglm","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jared-fowler%2Fprettyglm/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jared-fowler%2Fprettyglm/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jared-fowler%2Fprettyglm/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jared-fowler","download_url":"https://codeload.github.com/jared-fowler/prettyglm/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jared-fowler%2Fprettyglm/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286079811,"owners_count":27282121,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-11-25T02:00:05.816Z","response_time":54,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"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"],"created_at":"2025-11-16T05:00:30.374Z","updated_at":"2025-11-25T18:00:40.826Z","avatar_url":"https://github.com/jared-fowler.png","language":"R","funding_links":["https://www.buymeacoffee.com/tictap"],"categories":["Data and models"],"sub_categories":[],"readme":"---\noutput: github_document\n---\n\n\u003c!-- README.md is generated from README.Rmd. Please edit that file --\u003e\n\n```{r, include = FALSE}\nknitr::opts_chunk$set(\n  collapse = TRUE,\n  comment = \"#\u003e\",\n  fig.path = \"man/figures/README-\",\n  out.width = \"100%\"\n)\n```\n\n# prettyglm \u003cimg src='man/figures/logo.png' align=\"right\" height=\"139\" /\u003e\n\n\u003c!-- badges: start --\u003e\n[![CRAN_Status_Badge](https://www.r-pkg.org/badges/version/prettyglm)](https://cran.r-project.org/package=prettyglm)\n[![Downloads](https://cranlogs.r-pkg.org/badges/grand-total/prettyglm)](https://cran.r-project.org/package=prettyglm)\n[![R build status](https://github.com/jared-fowler/prettyglm/workflows/R-CMD-check/badge.svg)](https://github.com/jared-fowler/prettyglm/actions)\n[![Lifecycle: stable](https://img.shields.io/badge/lifecycle-stable-brightgreen.svg)](https://lifecycle.r-lib.org/articles/stages.html#stable)\n\u003c!-- badges: end --\u003e\n\nOne 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.\n\n## Forword \n\n`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.\n\nIf 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`\n\n## Installation\n\nYou can install the latest CRAN release with:\n\n``` r\ninstall.packages('prettyglm')\n```\n\n\u003c!-- You can install the development version from [GitHub](https://github.com/) with: --\u003e\n\n\u003c!-- ``` r --\u003e\n\u003c!-- devtools::install_github(\"jared-fowler/prettyglm\") --\u003e\n\u003c!-- ``` --\u003e\n\n## Documentation\n\nPlease see the website [prettyglm]( https://jared-fowler.github.io/prettyglm/) for more detailed documentation and examples.\n\n## A Simple Example\n\nTo 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.\n\n### Pre-processing\n\nA critical step for this package to work well is to **set all categorical predictors as factors**.\n\n```{r preprocessing, echo=TRUE, message=FALSE, warning=FALSE}\nlibrary(prettyglm)\nlibrary(dplyr)\ndata(\"bank\")\n\n# Easiest way to convert multiple columns to a factor.\ncolumns_to_factor \u003c- c('job',\n                       'marital',\n                       'education',\n                       'default',\n                       'housing',\n                       'loan')\nbank_data  \u003c- bank_data  %\u003e%\n  dplyr::filter(loan != 'unknown') %\u003e% \n  dplyr::filter(default != 'yes') %\u003e% \n  dplyr::mutate(age = as.numeric(age)) %\u003e% \n  dplyr::mutate_at(columns_to_factor, list(~factor(.))) %\u003e% # multiple columns to factor\n  dplyr::mutate(T_DEPOSIT = as.factor(base::ifelse(y=='yes',1,0))) #convert target to 0 and 1 for performance plots\n```\n\n### Building a glm\n\nFor 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.\n\n```{r build model, echo=TRUE}\ndeposit_model \u003c- stats::glm(T_DEPOSIT ~ marital +\n                                        default:loan +\n                                        loan +\n                                        age,\n                             data = bank_data,\n                             family = binomial)\n```\n\n### Visualising Fitted Model Coefficients\n\n#### Create table of model coefficients with `pretty_coefficients()`\n\n* `pretty_coefficients()` automatically includes categorical variable base levels.\n* You can complete a type III test on the coefficients by specifying a `type_iii` argument.\n* 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.)\n\n* You can return the data set instead of `kable` but setting `Return_Data =  TRUE`\n\n```{r visualise coefficients type iii, eval=FALSE, include=TRUE}\npretty_coefficients(deposit_model, type_iii = 'Wald')\n```\n\n\u003cp align=\"center\"\u003e\n  \u003cimg src= './man/figures/indextable.png' align=\"center\"/\u003e\n\u003c/p\u003e\n\n#### Create plots of the model relativities with `pretty_relativities()`\n\n* 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.\n* `pretty_relativities()` automatically extracts the training data from the model object and plots the number of records on the second y axis.\n\n```{r visualise relativitiy, eval=FALSE, include=TRUE}\npretty_relativities(feature_to_plot = 'marital',\n                    model_object = deposit_model)\n```\n\n\u003cp align=\"center\"\u003e\n  \u003cimg src= './man/figures/maritalrel.png' align=\"center\"/\u003e\n\u003c/p\u003e\n\n* 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.\n\n```{r age visualise relativitiy, eval=FALSE, include=TRUE}\npretty_relativities(feature_to_plot = 'age',\n                    model_object = deposit_model)\n```\n\n\u003cp align=\"center\"\u003e\n  \u003cimg src= './man/figures/agerel.png' align=\"center\"/\u003e\n\u003c/p\u003e\n\n* For interactions you can colour or facet by one of the variables.\n\n```{r default visualise relativitiy, eval=FALSE, include=TRUE}\npretty_relativities(feature_to_plot = 'default:loan',\n                    model_object = deposit_model,\n                    iteractionplottype = 'colour',\n                    facetorcolourby = 'loan')\n```\n\n\u003cp align=\"center\"\u003e\n  \u003cimg src= './man/figures/defualtloanrel.png'  align=\"center\"/\u003e\n\u003c/p\u003e\n\n### Visualising one-way model performance with `one_way_ave()`\n\n`one_way_ave()` creates one-way model performance plots.\n\n#### education\n\nFor discrete variables the number of records in each group will be plotted on a second axis.\n\n```{r education ave, eval=FALSE, include=TRUE}\none_way_ave(feature_to_plot = 'education',\n            model_object = deposit_model,\n            target_variable = 'T_DEPOSIT',\n            data_set = bank_data)\n```\n\n\u003cp align=\"center\"\u003e\n  \u003cimg src= './man/figures/educationave.png' align=\"center\"/\u003e\n\u003c/p\u003e\n\n\n#### age\n\nFor continuous variables the `stats::density()` will be plotted on a second axis.\n\n```{r aeg ave, eval=FALSE, include=TRUE}\none_way_ave(feature_to_plot = 'age',\n            model_object = deposit_model,\n            target_variable = 'T_DEPOSIT',\n            data_set = bank_data)\n```\n\n\u003cp align=\"center\"\u003e\n  \u003cimg src= './man/figures/ageave.png' align=\"center\"/\u003e\n\u003c/p\u003e\n\n\n#### Plot actual vs expected by predicted band with `actual_expected_bucketed()`\n\n`actual_expected_bucketed()` creates actual vs expected performance plots by predicted band.\n\n```{r visualise actual_expected_bucketed, eval=FALSE, include=TRUE}\nactual_expected_bucketed(target_variable = 'T_DEPOSIT',\n                         model_object = deposit_model,\n                         data_set = bank_data)\n```\n\n\u003cp align=\"center\"\u003e\n  \u003cimg src= './man/figures/aveband.png' align=\"center\"/\u003e\n\u003c/p\u003e\n\n### Support My Work\n\n[![\"Buy Me A Coffee\"](https://www.buymeacoffee.com/assets/img/custom_images/orange_img.png)](https://www.buymeacoffee.com/tictap)\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/jared-fowler.github.io%2Fprettyglm%2F","html_url":"https://awesome.ecosyste.ms/projects/jared-fowler.github.io%2Fprettyglm%2F","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/jared-fowler.github.io%2Fprettyglm%2F/lists"}