{"id":14066853,"url":"https://github.com/johnmackintosh/cusumcharter","last_synced_at":"2025-03-20T03:20:39.649Z","repository":{"id":44546427,"uuid":"398088509","full_name":"johnmackintosh/cusumcharter","owner":"johnmackintosh","description":"Easier CUSUM control charts.  Returns simple CUSUM statistics,  CUSUMs with control limit calculations, and function to generate faceted CUSUM Control Charts","archived":false,"fork":false,"pushed_at":"2024-11-22T23:56:39.000Z","size":1992,"stargazers_count":27,"open_issues_count":2,"forks_count":3,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-18T00:37:05.982Z","etag":null,"topics":["cusum","ggplot2","health-informatics","healthcare","quality-improvement","r","r-package","rdatatable","rstats","statistical-process-control"],"latest_commit_sha":null,"homepage":"https://johnmackintosh.github.io/cusumcharter/","language":"R","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/johnmackintosh.png","metadata":{"files":{"readme":"README.Rmd","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2021-08-19T22:20:56.000Z","updated_at":"2025-01-30T12:52:56.000Z","dependencies_parsed_at":"2022-07-25T01:32:19.756Z","dependency_job_id":"c1bdef92-c952-46e4-8365-0f43182c6d8e","html_url":"https://github.com/johnmackintosh/cusumcharter","commit_stats":{"total_commits":110,"total_committers":3,"mean_commits":"36.666666666666664","dds":0.3909090909090909,"last_synced_commit":"d651adac10eec4bb326ba13b3364b47380298ab4"},"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/johnmackintosh%2Fcusumcharter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/johnmackintosh%2Fcusumcharter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/johnmackintosh%2Fcusumcharter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/johnmackintosh%2Fcusumcharter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/johnmackintosh","download_url":"https://codeload.github.com/johnmackintosh/cusumcharter/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244542172,"owners_count":20469282,"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","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":["cusum","ggplot2","health-informatics","healthcare","quality-improvement","r","r-package","rdatatable","rstats","statistical-process-control"],"created_at":"2024-08-13T07:05:17.915Z","updated_at":"2025-03-20T03:20:39.625Z","avatar_url":"https://github.com/johnmackintosh.png","language":"R","funding_links":[],"categories":["R"],"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  dpi = 300,\n  fig.width = 5\n)\n```\n\n# cusumcharter \u003cimg src=\"man/figures/logo.png\" width=\"160px\" align=\"right\" /\u003e \n\n\n\u003c!-- badges: start --\u003e\n\n[![R-CMD-check](https://github.com/johnmackintosh/cusumcharter/workflows/R-CMD-check/badge.svg)](https://github.com/johnmackintosh/cusumcharter/actions)\n\n[![Codecov test coverage](https://codecov.io/gh/johnmackintosh/cusumcharter/branch/master/graph/badge.svg)](https://app.codecov.io/gh/johnmackintosh/cusumcharter?branch=master)\n\n[![Render README](https://github.com/johnmackintosh/cusumcharter/actions/workflows/render-readme.yaml/badge.svg)](https://github.com/johnmackintosh/cusumcharter/actions/workflows/render-readme.yaml)\n\n[![Project Status: Active – The project has reached a stable, usable state and is being actively developed.](https://www.repostatus.org/badges/latest/active.svg)](https://www.repostatus.org/#active)\n\n[![CRAN status](https://www.r-pkg.org/badges/version/cusumcharter)](https://CRAN.R-project.org/package=cusumcharter)\n\n[![CRAN Downloads](https://cranlogs.r-pkg.org/badges/cusumcharter)](https://cran.r-project.org/package=cusumcharter)\n\n[![Total Downloads](https://cranlogs.r-pkg.org/badges/grand-total/cusumcharter)](https://cran.r-project.org/package=cusumcharter)\n\n\u003c!-- badges: end --\u003e\n\nThe goal of cusumcharter is to create both simple CUSUM charts, with and without control limits from a vector, or to create multiple CUSUM charts, with or without control limits, from a grouped dataframe, tibble or data.table.\n\n\nCUSUM charts detect small changes over time, and will alert quicker than a Statistical Process Control chart. They are an excellent alternative to run and control charts, particularly where data is scarce, infrequent, or expensive to obtain.  \n\nThey monitor the difference between each data point, relative to a target value, which is often the mean of all the currently available data points. Using these variances and targets, control limits are calculated.\nAny points outside these limits are an indication that the process is out of control.  \n\n\n## Installation\n\nInstall the latest stable version from CRAN :\n\n```{r, eval = FALSE}\ninstall.packages(\"cusumcharter\")\n```\n\nInstall the development version from [GitHub](https://github.com/) with:\n\n``` r\n# install.packages(\"remotes\")\nremotes::install_github(\"johnmackintosh/cusumcharter\")\n```\n\n## A Simple CUSUM calculation\n\nThis returns the CUSUM statistics for a single vector, centred on a supplied target value:\n\n```{r example}\nlibrary(cusumcharter)\ntest_vec \u003c- c(0.175, 0.152, 0.15, 0.207, 0.136, 0.212, 0.166)\n\ncusum_res \u003c- cusum_single(test_vec, target = 0.16)\ncusum_res\n\n```\n\n## Expanded outputs with cusum_single_df\n\nThis function takes a single vector as input and returns a data.frame with additional information used to calculate the CUSUM statistic\n\n```{r, example2}\ntest_vec2 \u003c- c(0.175, 0.152, 0.15, 0.207, 0.136, 0.212, 0.166)\ncusum_single_df(test_vec2, target = 0.16)\n```\n\nHere we don't supply a target, so the mean is used\n```{r, out.width='100%'}\ntest_vec3 \u003c- c(1,1,2,11,3,5,7,2,4,3,5)\ncusum_single_df(test_vec3)\n```\n\n\n## CUSUM control limits\n\nTwo additional functions allow you to calculate control limits from a single vector and plot a CUSUM chart with control limits. As before, the mean is used to determine the target if none is provided. Alternate functions are available if you wish to use the median instead.\n\n```{r, cusum_control_example}\ntest_vec3 \u003c- c(1,1,2,3,5,7,11,7,5,7,8,9,5)\ncontrols \u003c- cusum_control(test_vec3, target = 4)\ncontrols\n\n```\nAlso see the ```cusum_control_median``` function\n\n\n## CUSUM Control Chart\n\n```{r single-control_chart, fig.width=5, fig.height=3}\ntest_vec3 \u003c- c(1,1,2,3,5,7,11,7,5,7,8,9,5)\ncontrols \u003c- cusum_control(test_vec3, target = 4)\n\ncusum_control_plot(controls, \n                   xvar = obs, \n                   title_text = \"CUSUM out of control since 7th observation\")\n```\n\n\n## Multiple CUSUM Control Charts \n\n```{r faceted_chart1, fig.width=5, fig.height= 3}\nlibrary(dplyr)\nlibrary(tibble)\nlibrary(ggplot2)\nlibrary(cusumcharter)\n\ntestdata \u003c- tibble::tibble(\n  N = c(1L,2L,1L,3L,1L,1L,1L,1L,1L,\n        1L,3L,2L,3L,2L,7L,11L,7L,9L),\n  metric = c(\"metric1\",\"metric1\",\"metric1\",\"metric1\",\"metric1\",\n           \"metric1\",\"metric1\",\"metric1\",\"metric1\",\"metric2\",\n           \"metric2\",\"metric2\",\"metric2\",\"metric2\",\"metric2\",\n           \"metric2\",\"metric2\",\"metric2\"))\n\ntestres \u003c- testdata %\u003e% \n  dplyr::group_by(metric) %\u003e% \n  dplyr::mutate(cusum_control(N)) %\u003e% \n  dplyr::ungroup()\n\np \u003c- cusum_control_plot(testres, \n                        xvar = obs, \n                        facet_var = metric, \n                        title_text = \"Faceted CUSUM Control plots\")\np\n\n```\n\n\n## Flexible x axis\n\nHere we  add a date column, specify that the ```scale_type``` is ```'date'```, and provide the ```datebreaks``` argument to plot our data over time\n\n```{r faceted_chart2, fig.width=5, fig.height= 3}\nlibrary(dplyr)\nlibrary(ggplot2)\nlibrary(cusumcharter)\n\ntestdata \u003c- tibble::tibble(\n N = c(1L,2L,1L,3L,1L,1L,1L,1L,1L,\n        1L,3L,2L,3L,2L,7L,11L,7L,9L),\n  metric = c(\"metric1\",\"metric1\",\"metric1\",\"metric1\",\"metric1\",\n           \"metric1\",\"metric1\",\"metric1\",\"metric1\",\"metric2\",\n           \"metric2\",\"metric2\",\"metric2\",\"metric2\",\"metric2\",\n           \"metric2\",\"metric2\",\"metric2\"))\n\ndatecol \u003c- as.Date(c(\"2021-01-01\",\"2021-01-02\", \"2021-01-03\", \"2021-01-04\" ,\n             \"2021-01-05\", \"2021-01-06\",\"2021-01-07\", \"2021-01-08\", \n             \"2021-01-09\"))\n\ntestres \u003c- testdata %\u003e% \n  dplyr::group_by(metric) %\u003e% \n  dplyr::mutate(cusum_control(N)) %\u003e% \n  dplyr::ungroup() %\u003e% \n  dplyr::group_by(metric) %\u003e% \n  dplyr::mutate(report_date = datecol) %\u003e% \n  ungroup()\n\np2 \u003c- cusum_control_plot(testres, \n                         xvar = report_date,\n                         facet_var = metric, \n                         title_text = \"Faceted plots with date axis\", \n                         scale_type = \"date\", \n                         datebreaks = '4 days')\n\np2 \u003c- p2 + ggplot2::theme(axis.text.x = ggplot2::element_text(angle = 90,\n                                                              hjust = 1, \n                                                              vjust = 0.5))\np2\n```\n\n## Highlight above and below control limits\n\nPoints outside the Upper Control Limit are always highlighted. \nUse the ```show_below``` option to enable highlighting points below the Lower Control Limit\n\n```{r highlightbelow,fig.width=5, fig.height= 3}\nlibrary(dplyr)\nlibrary(ggplot2)\nlibrary(cusumcharter)\n\ntestdata \u003c- tibble::tibble(\nN = c(-15L,2L,-11L,3L,1L,1L,-11L,1L,1L,\n2L,1L,1L,1L,10L,7L,9L,11L,9L),\nmetric = c(\"metric1\",\"metric1\",\"metric1\",\"metric1\",\"metric1\",\n\"metric1\",\"metric1\",\"metric1\",\"metric1\",\"metric2\",\n\"metric2\",\"metric2\",\"metric2\",\"metric2\",\"metric2\",\n\"metric2\",\"metric2\",\"metric2\"))\n\ndatecol \u003c- as.Date(c(\"2021-01-01\",\"2021-01-02\", \"2021-01-03\", \"2021-01-04\" ,\n             \"2021-01-05\", \"2021-01-06\",\"2021-01-07\", \"2021-01-08\",\n             \"2021-01-09\"))\n\ntestres \u003c- testdata %\u003e%\n  dplyr::group_by(metric) %\u003e%\n  dplyr::mutate(cusum_control(N)) %\u003e%\n  dplyr::ungroup() %\u003e%\n  dplyr::group_by(metric) %\u003e%\n  dplyr::mutate(report_date = datecol) %\u003e%\n  ungroup()\n\n\np5 \u003c- cusum_control_plot(testres,\n                         xvar = report_date,\n                         show_below = TRUE,\n                         facet_var = metric,\n                         title_text = \"Highlights above and below control limits\")\np5\n\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjohnmackintosh%2Fcusumcharter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjohnmackintosh%2Fcusumcharter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjohnmackintosh%2Fcusumcharter/lists"}