Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rtraining 1.2.5 #103

Merged
merged 4 commits into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: rtraining
Title: R Training
Version: 1.2.4
Version: 1.2.5
Authors@R:
person("John", "Benninghoff", , "jbenninghoff@mac.com", role = c("aut", "cre"),
comment = c(ORCID = "0000-0002-6230-4742"))
Expand Down
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# rtraining 1.2.5

* Updated Constraints vs Performance: Added "Transparent Donut" section

# rtraining 1.2.4

* Updated Constraints vs Performance: Added "Growth of Controls" section
Expand Down
4 changes: 2 additions & 2 deletions _freeze/analysis/constraints/execute-results/html.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"hash": "358f18699c0ed68bbe1560c938b92ea9",
"hash": "3152510323d5e2b19e5f0cb5589617f0",
"result": {
"engine": "knitr",
"markdown": "---\ntitle: \"Constraints vs Performance\"\nauthor: \"John Benninghoff\"\ndate: '2024-04-30'\ndate-modified: '2024-04-30'\ncategories: notes\norder: 107\noutput:\n html_notebook:\n theme:\n version: 5\n preset: bootstrap\n css: assets/extra.css\n pandoc_args: --shift-heading-level-by=1\n toc: yes\n toc_float:\n collapsed: no\n smooth_scroll: no\n---\n\n\nVisualizations exploring the use of constraints vs performance improvements in risk management.\n\n# Questions/TODO\n\n- [ ] Questions/TODO list here\n\n\n::: {.cell}\n\n```{.r .cell-code}\nlibrary(ggplot2)\nlibrary(jbplot)\nlibrary(fs)\nlibrary(tibble)\nlibrary(dplyr)\n```\n:::\n\n\n# Normal Performance\n\nReplicate a version of Figure 9 from the\n[Safety-II White Paper](https://www.england.nhs.uk/signuptosafety/wp-content/uploads/sites/16/2015/10/safety-1-safety-2-whte-papr.pdf),\nwith help from <https://ggplot2tutor.com/tutorials/sampling_distributions>:\n\n\n::: {.cell}\n\n```{.r .cell-code}\nxmin <- -5\nxmax <- 5\n\nsave_png <- function(filename) {\n ggsave(filename = path(\"rendered\", filename), width = 16 * 0.6, height = 9 * 0.6, bg = \"white\")\n}\n\nbackground <- ggplot(data.frame(x = c(xmin, xmax)), aes(x)) +\n scale_x_continuous(breaks = -3:3, minor_breaks = NULL) +\n labs(x = NULL, y = NULL) +\n theme_quo(minor.y = FALSE)\n\nbaseline <- stat_function(fun = dnorm, geom = \"line\")\nbad <- stat_function(fun = dnorm, geom = \"area\", fill = \"red\", xlim = c(xmin, -2))\n\nbackground + bad + baseline\n```\n\n::: {.cell-output-display}\n![](constraints_files/figure-html/background-1.png){width=816}\n:::\n\n```{.r .cell-code}\nsave_png(\"01-baseline-bad.png\")\n```\n:::\n\n\nThe plot above shows \"bad\" outcomes in red. Let's add in \"good\" outcomes (>1) in green:\n\n\n::: {.cell}\n\n```{.r .cell-code}\ngood <- stat_function(fun = dnorm, geom = \"area\", fill = \"green\", xlim = c(1, xmax))\n\nbackground + bad + good + baseline\n```\n\n::: {.cell-output-display}\n![](constraints_files/figure-html/good-1.png){width=816}\n:::\n\n```{.r .cell-code}\nsave_png(\"02-baseline-bad-good.png\")\n```\n:::\n\n\n# Constrained Performance\n\nOne way of reducing \"bad\" outcomes is by constraining performance - reducing the standard\ndeviation.\n\n\n::: {.cell}\n\n```{.r .cell-code}\nconstrained <- stat_function(fun = dnorm, args = list(sd = 0.7), geom = \"line\", color = \"blue\")\ntaller <- scale_y_continuous(limits = c(0, 0.6))\n\nbackground +\n stat_function(\n fun = dnorm, args = list(sd = 0.7), geom = \"area\", fill = \"red\", xlim = c(xmin, -2)\n ) +\n stat_function(\n fun = dnorm, args = list(sd = 0.7), geom = \"area\", fill = \"green\", xlim = c(1, xmax)\n ) +\n constrained +\n taller\n```\n\n::: {.cell-output-display}\n![](constraints_files/figure-html/constrained-1.png){width=816}\n:::\n\n```{.r .cell-code}\nsave_png(\"03-constrained.png\")\n```\n:::\n\n\nPlotting both on the same grid shows the reduction in both \"bad\" and \"good\" outcomes:\n\n\n::: {.cell}\n\n```{.r .cell-code}\nbackground +\n bad +\n good +\n baseline +\n constrained +\n taller\n```\n\n::: {.cell-output-display}\n![](constraints_files/figure-html/overlay-1.png){width=816}\n:::\n\n```{.r .cell-code}\nsave_png(\"04-baseline-constrained.png\")\n```\n:::\n\n\n# Improved Performance\n\nAnother way of reducing bad outcomes is by improving performance - shifting the mean.\n\n\n::: {.cell}\n\n```{.r .cell-code}\nperformance <- stat_function(fun = dnorm, args = list(mean = 1), geom = \"line\", color = \"blue\")\nimproved <- stat_function(\n fun = dnorm, args = list(mean = 1), geom = \"area\", fill = \"green\", xlim = c(1, xmax)\n)\n\nbackground +\n stat_function(\n fun = dnorm, args = list(mean = 1), geom = \"area\", fill = \"red\", xlim = c(xmin, -2)\n ) +\n improved +\n performance\n```\n\n::: {.cell-output-display}\n![](constraints_files/figure-html/performance-1.png){width=816}\n:::\n\n```{.r .cell-code}\nsave_png(\"05-improved.png\")\n```\n:::\n\n\nPlotting both together shows a reduction in \"bad\" and an increase in \"good\" outcomes:\n\n\n::: {.cell}\n\n```{.r .cell-code}\nbackground +\n bad +\n improved +\n baseline +\n performance\n```\n\n::: {.cell-output-display}\n![](constraints_files/figure-html/overlay_perf-1.png){width=816}\n:::\n\n```{.r .cell-code}\nsave_png(\"06-baseline-improved.png\")\n```\n:::\n\n\nComparing all three:\n\n\n::: {.cell}\n\n```{.r .cell-code}\nbackground +\n bad +\n improved +\n baseline +\n constrained +\n performance +\n taller\n```\n\n::: {.cell-output-display}\n![](constraints_files/figure-html/overlay_all-1.png){width=816}\n:::\n\n```{.r .cell-code}\nsave_png(\"07-baseline-constrained-improved.png\")\n```\n:::\n\n\n# Growth of Controls\n\nVisualize an example of the growth of controls using the Cyentia/RiskRecon State of Third-Party Risk\nManagement 2020 and 2024 reports (data from 2023).\n\nSource:\n\n- 2020 data: <https://www.riskrecon.com/state-of-third-party-risk-management-report>\n- 2023 data: <https://www.riskrecon.com/state-of-third-party-risk-management-2024>\n\n\n::: {.cell}\n\n```{.r .cell-code}\nquestionnaire <- tribble(\n ~year, ~questions, ~percent,\n 2020, \">400\", 0.041,\n 2020, \"101-400\", 0.148,\n 2020, \"11-100\", 0.705,\n 2020, \"1-10\", 0.107,\n 2023, \">400\", 0.02,\n 2023, \"101-400\", 0.333,\n 2023, \"11-100\", 0.616,\n 2023, \"1-10\", 0.030\n) |>\n mutate(year = as.factor(year)) |>\n mutate(questions = factor(questions, levels = c(\"1-10\", \"11-100\", \"101-400\", \">400\")))\n\nggplot(questionnaire, aes(questions, percent, fill = year)) +\n geom_col(position = \"dodge\") +\n scale_y_continuous(labels = scales::label_percent()) +\n scale_fill_manual(values = c(\"steelblue2\", \"steelblue4\")) +\n labs(x = NULL, y = NULL, fill = \"Year\", title = \"Third-Party Questionnaire Length by Year\") +\n labs(caption = \"Source: Cyentia/RiskRecon State of Third-Party Risk Management, 2020 and 2024\") +\n theme_quo()\n```\n\n::: {.cell-output-display}\n![](constraints_files/figure-html/questionnaire-1.png){width=816}\n:::\n\n```{.r .cell-code}\nsave_png(\"08-questionnaire-length.png\")\n```\n:::\n",
"markdown": "---\ntitle: \"Constraints vs Performance\"\nauthor: \"John Benninghoff\"\ndate: '2024-04-30'\ndate-modified: '2024-04-30'\ncategories: notes\norder: 107\noutput:\n html_notebook:\n theme:\n version: 5\n preset: bootstrap\n css: assets/extra.css\n pandoc_args: --shift-heading-level-by=1\n toc: yes\n toc_float:\n collapsed: no\n smooth_scroll: no\n---\n\n\nVisualizations exploring the use of constraints vs performance improvements in risk management.\n\n# Questions/TODO\n\n- [ ] Questions/TODO list here\n\n\n::: {.cell}\n\n```{.r .cell-code}\nlibrary(ggplot2)\nlibrary(jbplot)\nlibrary(fs)\nlibrary(tibble)\nlibrary(dplyr)\n```\n:::\n\n\n# Normal Performance\n\nReplicate a version of Figure 9 from the\n[Safety-II White Paper](https://www.england.nhs.uk/signuptosafety/wp-content/uploads/sites/16/2015/10/safety-1-safety-2-whte-papr.pdf),\nwith help from <https://ggplot2tutor.com/tutorials/sampling_distributions>:\n\n\n::: {.cell}\n\n```{.r .cell-code}\nxmin <- -5\nxmax <- 5\n\nsave_png <- function(filename) {\n ggsave(filename = path(\"rendered\", filename), width = 16 * 0.6, height = 9 * 0.6, bg = \"white\")\n}\n\nbackground <- ggplot(data.frame(x = c(xmin, xmax)), aes(x)) +\n scale_x_continuous(breaks = -3:3, minor_breaks = NULL) +\n labs(x = NULL, y = NULL) +\n theme_quo(minor.y = FALSE)\n\nbaseline <- stat_function(fun = dnorm, geom = \"line\")\nbad <- stat_function(fun = dnorm, geom = \"area\", fill = \"red\", xlim = c(xmin, -2))\n\nbackground + bad + baseline\n```\n\n::: {.cell-output-display}\n![](constraints_files/figure-html/background-1.png){width=816}\n:::\n\n```{.r .cell-code}\nsave_png(\"01-baseline-bad.png\")\n```\n:::\n\n\nThe plot above shows \"bad\" outcomes in red. Let's add in \"good\" outcomes (>1) in green:\n\n\n::: {.cell}\n\n```{.r .cell-code}\ngood <- stat_function(fun = dnorm, geom = \"area\", fill = \"green\", xlim = c(1, xmax))\n\nbackground + bad + good + baseline\n```\n\n::: {.cell-output-display}\n![](constraints_files/figure-html/good-1.png){width=816}\n:::\n\n```{.r .cell-code}\nsave_png(\"02-baseline-bad-good.png\")\n```\n:::\n\n\n# Constrained Performance\n\nOne way of reducing \"bad\" outcomes is by constraining performance - reducing the standard\ndeviation.\n\n\n::: {.cell}\n\n```{.r .cell-code}\nconstrained <- stat_function(fun = dnorm, args = list(sd = 0.7), geom = \"line\", color = \"blue\")\ntaller <- scale_y_continuous(limits = c(0, 0.6))\n\nbackground +\n stat_function(\n fun = dnorm, args = list(sd = 0.7), geom = \"area\", fill = \"red\", xlim = c(xmin, -2)\n ) +\n stat_function(\n fun = dnorm, args = list(sd = 0.7), geom = \"area\", fill = \"green\", xlim = c(1, xmax)\n ) +\n constrained +\n taller\n```\n\n::: {.cell-output-display}\n![](constraints_files/figure-html/constrained-1.png){width=816}\n:::\n\n```{.r .cell-code}\nsave_png(\"03-constrained.png\")\n```\n:::\n\n\nPlotting both on the same grid shows the reduction in both \"bad\" and \"good\" outcomes:\n\n\n::: {.cell}\n\n```{.r .cell-code}\nbackground +\n bad +\n good +\n baseline +\n constrained +\n taller\n```\n\n::: {.cell-output-display}\n![](constraints_files/figure-html/overlay-1.png){width=816}\n:::\n\n```{.r .cell-code}\nsave_png(\"04-baseline-constrained.png\")\n```\n:::\n\n\n# Improved Performance\n\nAnother way of reducing bad outcomes is by improving performance - shifting the mean.\n\n\n::: {.cell}\n\n```{.r .cell-code}\nperformance <- stat_function(fun = dnorm, args = list(mean = 1), geom = \"line\", color = \"blue\")\nimproved <- stat_function(\n fun = dnorm, args = list(mean = 1), geom = \"area\", fill = \"green\", xlim = c(1, xmax)\n)\n\nbackground +\n stat_function(\n fun = dnorm, args = list(mean = 1), geom = \"area\", fill = \"red\", xlim = c(xmin, -2)\n ) +\n improved +\n performance\n```\n\n::: {.cell-output-display}\n![](constraints_files/figure-html/performance-1.png){width=816}\n:::\n\n```{.r .cell-code}\nsave_png(\"05-improved.png\")\n```\n:::\n\n\nPlotting both together shows a reduction in \"bad\" and an increase in \"good\" outcomes:\n\n\n::: {.cell}\n\n```{.r .cell-code}\nbackground +\n bad +\n improved +\n baseline +\n performance\n```\n\n::: {.cell-output-display}\n![](constraints_files/figure-html/overlay_perf-1.png){width=816}\n:::\n\n```{.r .cell-code}\nsave_png(\"06-baseline-improved.png\")\n```\n:::\n\n\nComparing all three:\n\n\n::: {.cell}\n\n```{.r .cell-code}\nbackground +\n bad +\n improved +\n baseline +\n constrained +\n performance +\n taller\n```\n\n::: {.cell-output-display}\n![](constraints_files/figure-html/overlay_all-1.png){width=816}\n:::\n\n```{.r .cell-code}\nsave_png(\"07-baseline-constrained-improved.png\")\n```\n:::\n\n\n# Growth of Controls\n\nVisualize an example of the growth of controls using the Cyentia/RiskRecon State of Third-Party Risk\nManagement 2020 and 2024 reports (data from 2023).\n\nSource:\n\n- 2020 data: <https://www.riskrecon.com/state-of-third-party-risk-management-report>\n- 2023 data: <https://www.riskrecon.com/state-of-third-party-risk-management-2024>\n\n\n::: {.cell}\n\n```{.r .cell-code}\nquestionnaire <- tribble(\n ~year, ~questions, ~percent,\n 2020, \">400\", 0.041,\n 2020, \"101-400\", 0.148,\n 2020, \"11-100\", 0.705,\n 2020, \"1-10\", 0.107,\n 2023, \">400\", 0.02,\n 2023, \"101-400\", 0.333,\n 2023, \"11-100\", 0.616,\n 2023, \"1-10\", 0.030\n) |>\n mutate(year = as.factor(year)) |>\n mutate(questions = factor(questions, levels = c(\"1-10\", \"11-100\", \"101-400\", \">400\")))\n\nggplot(questionnaire, aes(questions, percent, fill = year)) +\n geom_col(position = \"dodge\") +\n scale_y_continuous(labels = scales::label_percent()) +\n scale_fill_manual(values = c(\"steelblue2\", \"steelblue4\")) +\n labs(x = NULL, y = NULL, fill = \"Year\", title = \"Third-Party Questionnaire Length by Year\") +\n labs(caption = \"Source: Cyentia/RiskRecon State of Third-Party Risk Management, 2020 and 2024\") +\n theme_quo()\n```\n\n::: {.cell-output-display}\n![](constraints_files/figure-html/questionnaire-1.png){width=816}\n:::\n\n```{.r .cell-code}\nsave_png(\"08-questionnaire-length.png\")\n```\n:::\n\n\n# Transparent Donut\n\nCreate a transparent donut plot showing an 80% reduction.\n\n\n::: {.cell}\n\n```{.r .cell-code}\n# custom function based on ggplot_donut_percent()\ncustom_donut <- function(p, text = \"\", accuracy = NULL, hsize = 4, size = 12, family = \"Lato\") {\n data <- data.frame(group = c(TRUE, FALSE), n = c(p, 1 - p))\n label <- paste0(scales::label_percent(accuracy = accuracy)(p), \"\\n\", text)\n\n ggplot_donut(data, hsize = hsize) +\n guides(fill = \"none\") +\n geom_text(x = 0, label = label, size = size, family = family) +\n scale_fill_grey() +\n theme(plot.background = element_rect(fill = \"transparent\", color = NA))\n}\n\ncustom_donut(0.8, \"reduction\")\n```\n\n::: {.cell-output-display}\n![](constraints_files/figure-html/custom_donut-1.png){width=816}\n:::\n\n```{.r .cell-code}\nggsave(\"rendered/80-percent-safety.png\")\n```\n\n::: {.cell-output .cell-output-stderr}\n\n```\nSaving 8.5 x 5 in image\n```\n\n\n:::\n\n```{.r .cell-code}\ncustom_donut(0.8, \"reduction?\")\n```\n\n::: {.cell-output-display}\n![](constraints_files/figure-html/custom_donut-2.png){width=816}\n:::\n\n```{.r .cell-code}\nggsave(\"rendered/80-percent-security.png\")\n```\n\n::: {.cell-output .cell-output-stderr}\n\n```\nSaving 8.5 x 5 in image\n```\n\n\n:::\n:::\n",
"supporting": [
"constraints_files"
],
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
24 changes: 24 additions & 0 deletions analysis/constraints.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -185,3 +185,27 @@ ggplot(questionnaire, aes(questions, percent, fill = year)) +

save_png("08-questionnaire-length.png")
```

# Transparent Donut

Create a transparent donut plot showing an 80% reduction.

```{r custom_donut}
# custom function based on ggplot_donut_percent()
custom_donut <- function(p, text = "", accuracy = NULL, hsize = 4, size = 12, family = "Lato") {
data <- data.frame(group = c(TRUE, FALSE), n = c(p, 1 - p))
label <- paste0(scales::label_percent(accuracy = accuracy)(p), "\n", text)

ggplot_donut(data, hsize = hsize) +
guides(fill = "none") +
geom_text(x = 0, label = label, size = size, family = family) +
scale_fill_grey() +
theme(plot.background = element_rect(fill = "transparent", color = NA))
}

custom_donut(0.8, "reduction")
ggsave("rendered/80-percent-safety.png")

custom_donut(0.8, "reduction?")
ggsave("rendered/80-percent-security.png")
```
9 changes: 8 additions & 1 deletion docs/NEWS.html
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,8 @@
<h2 id="toc-title">On this page</h2>

<ul>
<li><a href="#rtraining-1.2.4" id="toc-rtraining-1.2.4" class="nav-link active" data-scroll-target="#rtraining-1.2.4">rtraining 1.2.4</a></li>
<li><a href="#rtraining-1.2.5" id="toc-rtraining-1.2.5" class="nav-link active" data-scroll-target="#rtraining-1.2.5">rtraining 1.2.5</a></li>
<li><a href="#rtraining-1.2.4" id="toc-rtraining-1.2.4" class="nav-link" data-scroll-target="#rtraining-1.2.4">rtraining 1.2.4</a></li>
<li><a href="#rtraining-1.2.3" id="toc-rtraining-1.2.3" class="nav-link" data-scroll-target="#rtraining-1.2.3">rtraining 1.2.3</a></li>
<li><a href="#rtraining-1.2.2" id="toc-rtraining-1.2.2" class="nav-link" data-scroll-target="#rtraining-1.2.2">rtraining 1.2.2</a></li>
<li><a href="#rtraining-1.2.1" id="toc-rtraining-1.2.1" class="nav-link" data-scroll-target="#rtraining-1.2.1">rtraining 1.2.1</a></li>
Expand Down Expand Up @@ -325,6 +326,12 @@ <h2 id="toc-title">On this page</h2>



<section id="rtraining-1.2.5" class="level1">
<h1>rtraining 1.2.5</h1>
<ul>
<li>Updated Constraints vs Performance: Added “Transparent Donut” section</li>
</ul>
</section>
<section id="rtraining-1.2.4" class="level1">
<h1>rtraining 1.2.4</h1>
<ul>
Expand Down
Loading