-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.html
380 lines (348 loc) · 38.5 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
<!DOCTYPE html>
<!-- Generated by pkgdown: do not edit by hand --><html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Easier CUSUM Control Charts • cusumcharter</title>
<!-- favicons --><link rel="icon" type="image/png" sizes="16x16" href="favicon-16x16.png">
<link rel="icon" type="image/png" sizes="32x32" href="favicon-32x32.png">
<link rel="apple-touch-icon" type="image/png" sizes="180x180" href="apple-touch-icon.png">
<link rel="apple-touch-icon" type="image/png" sizes="120x120" href="apple-touch-icon-120x120.png">
<link rel="apple-touch-icon" type="image/png" sizes="76x76" href="apple-touch-icon-76x76.png">
<link rel="apple-touch-icon" type="image/png" sizes="60x60" href="apple-touch-icon-60x60.png">
<!-- jquery --><script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js" integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo=" crossorigin="anonymous"></script><!-- Bootstrap --><link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.4.1/css/bootstrap.min.css" integrity="sha256-bZLfwXAP04zRMK2BjiO8iu9pf4FbLqX6zitd+tIvLhE=" crossorigin="anonymous">
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.4.1/js/bootstrap.min.js" integrity="sha256-nuL8/2cJ5NDSSwnKD8VqreErSWHtnEP9E7AySL+1ev4=" crossorigin="anonymous"></script><!-- bootstrap-toc --><link rel="stylesheet" href="bootstrap-toc.css">
<script src="bootstrap-toc.js"></script><!-- Font Awesome icons --><link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.12.1/css/all.min.css" integrity="sha256-mmgLkCYLUQbXn0B1SRqzHar6dCnv9oZFPEC1g1cwlkk=" crossorigin="anonymous">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.12.1/css/v4-shims.min.css" integrity="sha256-wZjR52fzng1pJHwx4aV2AO3yyTOXrcDW7jBpJtTwVxw=" crossorigin="anonymous">
<!-- clipboard.js --><script src="https://cdnjs.cloudflare.com/ajax/libs/clipboard.js/2.0.6/clipboard.min.js" integrity="sha256-inc5kl9MA1hkeYUt+EC3BhlIgyp/2jDIyBLS6k3UxPI=" crossorigin="anonymous"></script><!-- headroom.js --><script src="https://cdnjs.cloudflare.com/ajax/libs/headroom/0.11.0/headroom.min.js" integrity="sha256-AsUX4SJE1+yuDu5+mAVzJbuYNPHj/WroHuZ8Ir/CkE0=" crossorigin="anonymous"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/headroom/0.11.0/jQuery.headroom.min.js" integrity="sha256-ZX/yNShbjqsohH1k95liqY9Gd8uOiE1S4vZc+9KQ1K4=" crossorigin="anonymous"></script><!-- pkgdown --><link href="pkgdown.css" rel="stylesheet">
<script src="pkgdown.js"></script><meta property="og:title" content="Easier CUSUM Control Charts ">
<meta property="og:description" content="Create CUSUM (cumulative sum) statistics from a vector or dataframe.
Also create single or faceted CUSUM control charts, with or without control limits.
Accepts vector, dataframe, tibble or data.table inputs.">
<meta property="og:image" content="https://johnmackintosh.github.io/cusumcharter/logo.png">
<!-- mathjax --><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js" integrity="sha256-nvJJv9wWKEm88qvoQl9ekL2J+k/RWIsaSScxxlsrv8k=" crossorigin="anonymous"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/config/TeX-AMS-MML_HTMLorMML.js" integrity="sha256-84DKXVJXs0/F8OTMzX4UR909+jtl4G7SPypPavF+GfA=" crossorigin="anonymous"></script><!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body data-spy="scroll" data-target="#toc">
<div class="container template-home">
<header><div class="navbar navbar-default navbar-fixed-top" role="navigation">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<span class="navbar-brand">
<a class="navbar-link" href="index.html">cusumcharter</a>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">0.1.9000</span>
</span>
</div>
<div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li>
<a href="index.html">
<span class="fas fa-home fa-lg"></span>
</a>
</li>
<li>
<a href="articles/cusumcharter.html">Get started</a>
</li>
<li>
<a href="reference/index.html">Reference</a>
</li>
<li>
<a href="news/index.html">Changelog</a>
</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li>
<a href="https://github.com/johnmackintosh/cusumcharter/">
<span class="fab fa-github fa-lg"></span>
</a>
</li>
</ul>
</div>
<!--/.nav-collapse -->
</div>
<!--/.container -->
</div>
<!--/.navbar -->
</header><div class="row">
<div class="contents col-md-9">
<div id="cusumcharter-" class="section level1">
<div class="page-header"><h1 class="hasAnchor">
<a href="#cusumcharter-" class="anchor"></a>cusumcharter <img src="reference/figures/logo.png" width="160px" align="right">
</h1></div>
<!-- badges: start -->
<p><a href="https://app.codecov.io/gh/johnmackintosh/cusumcharter?branch=master"><img src="https://codecov.io/gh/johnmackintosh/cusumcharter/branch/master/graph/badge.svg" alt="Codecov test coverage"></a></p>
<p><a href="https://github.com/johnmackintosh/cusumcharter/actions/workflows/render-readme.yaml"><img src="https://github.com/johnmackintosh/cusumcharter/actions/workflows/render-readme.yaml/badge.svg" alt="Render README"></a></p>
<p><a href="https://www.repostatus.org/#active"><img src="https://www.repostatus.org/badges/latest/active.svg" alt="Project Status: Active – The project has reached a stable, usable state and is being actively developed."></a></p>
<p><a href="https://CRAN.R-project.org/package=cusumcharter"><img src="https://www.r-pkg.org/badges/version/cusumcharter" alt="CRAN status"></a> <!-- badges: end --></p>
<p>The 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.</p>
<p>CUSUM 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.</p>
<p>They 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. Any points outside these limits are an indication that the process is out of control.</p>
<div id="installation" class="section level2">
<h2 class="hasAnchor">
<a href="#installation" class="anchor"></a>Installation</h2>
<p>Install the latest stable version from CRAN :</p>
<div class="sourceCode" id="cb1"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="fu"><a href="https://rdrr.io/r/utils/install.packages.html">install.packages</a></span><span class="op">(</span><span class="st">"cusumcharter"</span><span class="op">)</span></code></pre></div>
<p>Install the development version from <a href="https://github.com/">GitHub</a> with:</p>
<div class="sourceCode" id="cb2"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="co"># install.packages("remotes")</span>
<span class="fu">remotes</span><span class="fu">::</span><span class="fu"><a href="https://remotes.r-lib.org/reference/install_github.html">install_github</a></span><span class="op">(</span><span class="st">"johnmackintosh/cusumcharter"</span><span class="op">)</span></code></pre></div>
</div>
<div id="a-simple-cusum-calculation" class="section level2">
<h2 class="hasAnchor">
<a href="#a-simple-cusum-calculation" class="anchor"></a>A Simple CUSUM calculation</h2>
<p>This returns the CUSUM statistics for a single vector, centred on a supplied target value:</p>
<div class="sourceCode" id="cb3"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="kw"><a href="https://rdrr.io/r/base/library.html">library</a></span><span class="op">(</span><span class="va"><a href="https://github.com/johnmackintosh/cusumcharter">cusumcharter</a></span><span class="op">)</span>
<span class="va">test_vec</span> <span class="op"><-</span> <span class="fu"><a href="https://rdrr.io/r/base/c.html">c</a></span><span class="op">(</span><span class="fl">0.175</span>, <span class="fl">0.152</span>, <span class="fl">0.15</span>, <span class="fl">0.207</span>, <span class="fl">0.136</span>, <span class="fl">0.212</span>, <span class="fl">0.166</span><span class="op">)</span>
<span class="va">cusum_res</span> <span class="op"><-</span> <span class="fu"><a href="reference/cusum_single.html">cusum_single</a></span><span class="op">(</span><span class="va">test_vec</span>, target <span class="op">=</span> <span class="fl">0.16</span><span class="op">)</span>
<span class="va">cusum_res</span>
<span class="co">#> [1] 0.175 0.167 0.157 0.204 0.180 0.232 0.238</span></code></pre></div>
</div>
<div id="expanded-outputs-with-cusum_single_df" class="section level2">
<h2 class="hasAnchor">
<a href="#expanded-outputs-with-cusum_single_df" class="anchor"></a>Expanded outputs with cusum_single_df</h2>
<p>This function takes a single vector as input and returns a data.frame with additional information used to calculate the CUSUM statistic</p>
<div class="sourceCode" id="cb4"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="va">test_vec2</span> <span class="op"><-</span> <span class="fu"><a href="https://rdrr.io/r/base/c.html">c</a></span><span class="op">(</span><span class="fl">0.175</span>, <span class="fl">0.152</span>, <span class="fl">0.15</span>, <span class="fl">0.207</span>, <span class="fl">0.136</span>, <span class="fl">0.212</span>, <span class="fl">0.166</span><span class="op">)</span>
<span class="fu"><a href="reference/cusum_single_df.html">cusum_single_df</a></span><span class="op">(</span><span class="va">test_vec2</span>, target <span class="op">=</span> <span class="fl">0.16</span><span class="op">)</span>
<span class="co">#> x target si cusumx cusum_target</span>
<span class="co">#> 1 0.175 0.16 0.015 0.015 0.175</span>
<span class="co">#> 2 0.152 0.16 -0.008 0.007 0.167</span>
<span class="co">#> 3 0.150 0.16 -0.010 -0.003 0.157</span>
<span class="co">#> 4 0.207 0.16 0.047 0.044 0.204</span>
<span class="co">#> 5 0.136 0.16 -0.024 0.020 0.180</span>
<span class="co">#> 6 0.212 0.16 0.052 0.072 0.232</span>
<span class="co">#> 7 0.166 0.16 0.006 0.078 0.238</span></code></pre></div>
<p>Here we don’t supply a target, so the mean is used</p>
<div class="sourceCode" id="cb5"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="va">test_vec3</span> <span class="op"><-</span> <span class="fu"><a href="https://rdrr.io/r/base/c.html">c</a></span><span class="op">(</span><span class="fl">1</span>,<span class="fl">1</span>,<span class="fl">2</span>,<span class="fl">11</span>,<span class="fl">3</span>,<span class="fl">5</span>,<span class="fl">7</span>,<span class="fl">2</span>,<span class="fl">4</span>,<span class="fl">3</span>,<span class="fl">5</span><span class="op">)</span>
<span class="fu"><a href="reference/cusum_single_df.html">cusum_single_df</a></span><span class="op">(</span><span class="va">test_vec3</span><span class="op">)</span>
<span class="co">#> x target si cusumx cusum_target</span>
<span class="co">#> 1 1 4 -3 -3 1</span>
<span class="co">#> 2 1 4 -3 -6 -2</span>
<span class="co">#> 3 2 4 -2 -8 -4</span>
<span class="co">#> 4 11 4 7 -1 3</span>
<span class="co">#> 5 3 4 -1 -2 2</span>
<span class="co">#> 6 5 4 1 -1 3</span>
<span class="co">#> 7 7 4 3 2 6</span>
<span class="co">#> 8 2 4 -2 0 4</span>
<span class="co">#> 9 4 4 0 0 4</span>
<span class="co">#> 10 3 4 -1 -1 3</span>
<span class="co">#> 11 5 4 1 0 4</span></code></pre></div>
</div>
<div id="cusum-control-limits" class="section level2">
<h2 class="hasAnchor">
<a href="#cusum-control-limits" class="anchor"></a>CUSUM control limits</h2>
<p>Two 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.</p>
<div class="sourceCode" id="cb6"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="va">test_vec3</span> <span class="op"><-</span> <span class="fu"><a href="https://rdrr.io/r/base/c.html">c</a></span><span class="op">(</span><span class="fl">1</span>,<span class="fl">1</span>,<span class="fl">2</span>,<span class="fl">3</span>,<span class="fl">5</span>,<span class="fl">7</span>,<span class="fl">11</span>,<span class="fl">7</span>,<span class="fl">5</span>,<span class="fl">7</span>,<span class="fl">8</span>,<span class="fl">9</span>,<span class="fl">5</span><span class="op">)</span>
<span class="va">controls</span> <span class="op"><-</span> <span class="fu"><a href="reference/cusum_control.html">cusum_control</a></span><span class="op">(</span><span class="va">test_vec3</span>, target <span class="op">=</span> <span class="fl">4</span><span class="op">)</span>
<span class="va">controls</span>
<span class="co">#> x target variance std_dev cusum cplus cneg cum_nplus cum_nneg</span>
<span class="co">#> 1 1 4 -3 1.77305 -3 0.0000000 -2.113475 0 1</span>
<span class="co">#> 2 1 4 -3 1.77305 -6 0.0000000 -4.226950 0 2</span>
<span class="co">#> 3 2 4 -2 1.77305 -8 0.0000000 -5.340426 0 3</span>
<span class="co">#> 4 3 4 -1 1.77305 -9 0.0000000 -5.453901 0 4</span>
<span class="co">#> 5 5 4 1 1.77305 -8 0.1134752 -3.567376 1 5</span>
<span class="co">#> 6 7 4 3 1.77305 -5 2.2269504 0.000000 2 0</span>
<span class="co">#> 7 11 4 7 1.77305 2 8.3404255 0.000000 3 0</span>
<span class="co">#> 8 7 4 3 1.77305 5 10.4539007 0.000000 4 0</span>
<span class="co">#> 9 5 4 1 1.77305 6 10.5673759 0.000000 5 0</span>
<span class="co">#> 10 7 4 3 1.77305 9 12.6808511 0.000000 6 0</span>
<span class="co">#> 11 8 4 4 1.77305 13 15.7943262 0.000000 7 0</span>
<span class="co">#> 12 9 4 5 1.77305 18 19.9078014 0.000000 8 0</span>
<span class="co">#> 13 5 4 1 1.77305 19 20.0212766 0.000000 9 0</span>
<span class="co">#> ucl lcl centre obs</span>
<span class="co">#> 1 7.092199 -7.092199 0 1</span>
<span class="co">#> 2 7.092199 -7.092199 0 2</span>
<span class="co">#> 3 7.092199 -7.092199 0 3</span>
<span class="co">#> 4 7.092199 -7.092199 0 4</span>
<span class="co">#> 5 7.092199 -7.092199 0 5</span>
<span class="co">#> 6 7.092199 -7.092199 0 6</span>
<span class="co">#> 7 7.092199 -7.092199 0 7</span>
<span class="co">#> 8 7.092199 -7.092199 0 8</span>
<span class="co">#> 9 7.092199 -7.092199 0 9</span>
<span class="co">#> 10 7.092199 -7.092199 0 10</span>
<span class="co">#> 11 7.092199 -7.092199 0 11</span>
<span class="co">#> 12 7.092199 -7.092199 0 12</span>
<span class="co">#> 13 7.092199 -7.092199 0 13</span></code></pre></div>
<p>Also see the <code>cusum_control_median</code> function</p>
</div>
<div id="cusum-control-chart" class="section level2">
<h2 class="hasAnchor">
<a href="#cusum-control-chart" class="anchor"></a>CUSUM Control Chart</h2>
<div class="sourceCode" id="cb7"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="va">test_vec3</span> <span class="op"><-</span> <span class="fu"><a href="https://rdrr.io/r/base/c.html">c</a></span><span class="op">(</span><span class="fl">1</span>,<span class="fl">1</span>,<span class="fl">2</span>,<span class="fl">3</span>,<span class="fl">5</span>,<span class="fl">7</span>,<span class="fl">11</span>,<span class="fl">7</span>,<span class="fl">5</span>,<span class="fl">7</span>,<span class="fl">8</span>,<span class="fl">9</span>,<span class="fl">5</span><span class="op">)</span>
<span class="va">controls</span> <span class="op"><-</span> <span class="fu"><a href="reference/cusum_control.html">cusum_control</a></span><span class="op">(</span><span class="va">test_vec3</span>, target <span class="op">=</span> <span class="fl">4</span><span class="op">)</span>
<span class="fu"><a href="reference/cusum_control_plot.html">cusum_control_plot</a></span><span class="op">(</span><span class="va">controls</span>,
xvar <span class="op">=</span> <span class="va">obs</span>,
title_text <span class="op">=</span> <span class="st">"CUSUM out of control since 7th observation"</span><span class="op">)</span></code></pre></div>
<p><img src="reference/figures/README-single-control_chart-1.png"><!-- --></p>
</div>
<div id="multiple-cusum-control-charts" class="section level2">
<h2 class="hasAnchor">
<a href="#multiple-cusum-control-charts" class="anchor"></a>Multiple CUSUM Control Charts</h2>
<div class="sourceCode" id="cb8"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="kw"><a href="https://rdrr.io/r/base/library.html">library</a></span><span class="op">(</span><span class="va"><a href="https://dplyr.tidyverse.org">dplyr</a></span><span class="op">)</span>
<span class="co">#> </span>
<span class="co">#> Attaching package: 'dplyr'</span>
<span class="co">#> The following objects are masked from 'package:stats':</span>
<span class="co">#> </span>
<span class="co">#> filter, lag</span>
<span class="co">#> The following objects are masked from 'package:base':</span>
<span class="co">#> </span>
<span class="co">#> intersect, setdiff, setequal, union</span>
<span class="kw"><a href="https://rdrr.io/r/base/library.html">library</a></span><span class="op">(</span><span class="va"><a href="https://tibble.tidyverse.org/">tibble</a></span><span class="op">)</span>
<span class="co">#> Warning: package 'tibble' was built under R version 4.1.1</span>
<span class="kw"><a href="https://rdrr.io/r/base/library.html">library</a></span><span class="op">(</span><span class="va"><a href="https://ggplot2.tidyverse.org">ggplot2</a></span><span class="op">)</span>
<span class="kw"><a href="https://rdrr.io/r/base/library.html">library</a></span><span class="op">(</span><span class="va"><a href="https://github.com/johnmackintosh/cusumcharter">cusumcharter</a></span><span class="op">)</span>
<span class="va">testdata</span> <span class="op"><-</span> <span class="fu">tibble</span><span class="fu">::</span><span class="fu"><a href="https://tibble.tidyverse.org/reference/tibble.html">tibble</a></span><span class="op">(</span>
N <span class="op">=</span> <span class="fu"><a href="https://rdrr.io/r/base/c.html">c</a></span><span class="op">(</span><span class="fl">1L</span>,<span class="fl">2L</span>,<span class="fl">1L</span>,<span class="fl">3L</span>,<span class="fl">1L</span>,<span class="fl">1L</span>,<span class="fl">1L</span>,<span class="fl">1L</span>,<span class="fl">1L</span>,
<span class="fl">1L</span>,<span class="fl">3L</span>,<span class="fl">2L</span>,<span class="fl">3L</span>,<span class="fl">2L</span>,<span class="fl">7L</span>,<span class="fl">11L</span>,<span class="fl">7L</span>,<span class="fl">9L</span><span class="op">)</span>,
metric <span class="op">=</span> <span class="fu"><a href="https://rdrr.io/r/base/c.html">c</a></span><span class="op">(</span><span class="st">"metric1"</span>,<span class="st">"metric1"</span>,<span class="st">"metric1"</span>,<span class="st">"metric1"</span>,<span class="st">"metric1"</span>,
<span class="st">"metric1"</span>,<span class="st">"metric1"</span>,<span class="st">"metric1"</span>,<span class="st">"metric1"</span>,<span class="st">"metric2"</span>,
<span class="st">"metric2"</span>,<span class="st">"metric2"</span>,<span class="st">"metric2"</span>,<span class="st">"metric2"</span>,<span class="st">"metric2"</span>,
<span class="st">"metric2"</span>,<span class="st">"metric2"</span>,<span class="st">"metric2"</span><span class="op">)</span><span class="op">)</span>
<span class="va">testres</span> <span class="op"><-</span> <span class="va">testdata</span> <span class="op"><a href="https://magrittr.tidyverse.org/reference/pipe.html">%>%</a></span>
<span class="fu">dplyr</span><span class="fu">::</span><span class="fu"><a href="https://dplyr.tidyverse.org/reference/group_by.html">group_by</a></span><span class="op">(</span><span class="va">metric</span><span class="op">)</span> <span class="op"><a href="https://magrittr.tidyverse.org/reference/pipe.html">%>%</a></span>
<span class="fu">dplyr</span><span class="fu">::</span><span class="fu"><a href="https://dplyr.tidyverse.org/reference/mutate.html">mutate</a></span><span class="op">(</span><span class="fu"><a href="reference/cusum_control.html">cusum_control</a></span><span class="op">(</span><span class="va">N</span><span class="op">)</span><span class="op">)</span> <span class="op"><a href="https://magrittr.tidyverse.org/reference/pipe.html">%>%</a></span>
<span class="fu">dplyr</span><span class="fu">::</span><span class="fu"><a href="https://dplyr.tidyverse.org/reference/group_by.html">ungroup</a></span><span class="op">(</span><span class="op">)</span>
<span class="co">#> no target value supplied, so using the mean of x</span>
<span class="co">#> no target value supplied, so using the mean of x</span>
<span class="va">p</span> <span class="op"><-</span> <span class="fu"><a href="reference/cusum_control_plot.html">cusum_control_plot</a></span><span class="op">(</span><span class="va">testres</span>,
xvar <span class="op">=</span> <span class="va">obs</span>,
facet_var <span class="op">=</span> <span class="va">metric</span>,
title_text <span class="op">=</span> <span class="st">"Faceted CUSUM Control plots"</span><span class="op">)</span>
<span class="va">p</span></code></pre></div>
<p><img src="reference/figures/README-faceted_chart1-1.png"><!-- --></p>
</div>
<div id="flexible-x-axis" class="section level2">
<h2 class="hasAnchor">
<a href="#flexible-x-axis" class="anchor"></a>Flexible x axis</h2>
<p>Here we add a date column, specify that the <code>scale_type</code> is <code>'date'</code>, and provide the <code>datebreaks</code> argument to plot our data over time</p>
<div class="sourceCode" id="cb9"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="kw"><a href="https://rdrr.io/r/base/library.html">library</a></span><span class="op">(</span><span class="va"><a href="https://dplyr.tidyverse.org">dplyr</a></span><span class="op">)</span>
<span class="kw"><a href="https://rdrr.io/r/base/library.html">library</a></span><span class="op">(</span><span class="va"><a href="https://ggplot2.tidyverse.org">ggplot2</a></span><span class="op">)</span>
<span class="kw"><a href="https://rdrr.io/r/base/library.html">library</a></span><span class="op">(</span><span class="va"><a href="https://github.com/johnmackintosh/cusumcharter">cusumcharter</a></span><span class="op">)</span>
<span class="va">testdata</span> <span class="op"><-</span> <span class="fu">tibble</span><span class="fu">::</span><span class="fu"><a href="https://tibble.tidyverse.org/reference/tibble.html">tibble</a></span><span class="op">(</span>
N <span class="op">=</span> <span class="fu"><a href="https://rdrr.io/r/base/c.html">c</a></span><span class="op">(</span><span class="fl">1L</span>,<span class="fl">2L</span>,<span class="fl">1L</span>,<span class="fl">3L</span>,<span class="fl">1L</span>,<span class="fl">1L</span>,<span class="fl">1L</span>,<span class="fl">1L</span>,<span class="fl">1L</span>,
<span class="fl">1L</span>,<span class="fl">3L</span>,<span class="fl">2L</span>,<span class="fl">3L</span>,<span class="fl">2L</span>,<span class="fl">7L</span>,<span class="fl">11L</span>,<span class="fl">7L</span>,<span class="fl">9L</span><span class="op">)</span>,
metric <span class="op">=</span> <span class="fu"><a href="https://rdrr.io/r/base/c.html">c</a></span><span class="op">(</span><span class="st">"metric1"</span>,<span class="st">"metric1"</span>,<span class="st">"metric1"</span>,<span class="st">"metric1"</span>,<span class="st">"metric1"</span>,
<span class="st">"metric1"</span>,<span class="st">"metric1"</span>,<span class="st">"metric1"</span>,<span class="st">"metric1"</span>,<span class="st">"metric2"</span>,
<span class="st">"metric2"</span>,<span class="st">"metric2"</span>,<span class="st">"metric2"</span>,<span class="st">"metric2"</span>,<span class="st">"metric2"</span>,
<span class="st">"metric2"</span>,<span class="st">"metric2"</span>,<span class="st">"metric2"</span><span class="op">)</span><span class="op">)</span>
<span class="va">datecol</span> <span class="op"><-</span> <span class="fu"><a href="https://rdrr.io/r/base/as.Date.html">as.Date</a></span><span class="op">(</span><span class="fu"><a href="https://rdrr.io/r/base/c.html">c</a></span><span class="op">(</span><span class="st">"2021-01-01"</span>,<span class="st">"2021-01-02"</span>, <span class="st">"2021-01-03"</span>, <span class="st">"2021-01-04"</span> ,
<span class="st">"2021-01-05"</span>, <span class="st">"2021-01-06"</span>,<span class="st">"2021-01-07"</span>, <span class="st">"2021-01-08"</span>,
<span class="st">"2021-01-09"</span><span class="op">)</span><span class="op">)</span>
<span class="va">testres</span> <span class="op"><-</span> <span class="va">testdata</span> <span class="op"><a href="https://magrittr.tidyverse.org/reference/pipe.html">%>%</a></span>
<span class="fu">dplyr</span><span class="fu">::</span><span class="fu"><a href="https://dplyr.tidyverse.org/reference/group_by.html">group_by</a></span><span class="op">(</span><span class="va">metric</span><span class="op">)</span> <span class="op"><a href="https://magrittr.tidyverse.org/reference/pipe.html">%>%</a></span>
<span class="fu">dplyr</span><span class="fu">::</span><span class="fu"><a href="https://dplyr.tidyverse.org/reference/mutate.html">mutate</a></span><span class="op">(</span><span class="fu"><a href="reference/cusum_control.html">cusum_control</a></span><span class="op">(</span><span class="va">N</span><span class="op">)</span><span class="op">)</span> <span class="op"><a href="https://magrittr.tidyverse.org/reference/pipe.html">%>%</a></span>
<span class="fu">dplyr</span><span class="fu">::</span><span class="fu"><a href="https://dplyr.tidyverse.org/reference/group_by.html">ungroup</a></span><span class="op">(</span><span class="op">)</span> <span class="op"><a href="https://magrittr.tidyverse.org/reference/pipe.html">%>%</a></span>
<span class="fu">dplyr</span><span class="fu">::</span><span class="fu"><a href="https://dplyr.tidyverse.org/reference/group_by.html">group_by</a></span><span class="op">(</span><span class="va">metric</span><span class="op">)</span> <span class="op"><a href="https://magrittr.tidyverse.org/reference/pipe.html">%>%</a></span>
<span class="fu">dplyr</span><span class="fu">::</span><span class="fu"><a href="https://dplyr.tidyverse.org/reference/mutate.html">mutate</a></span><span class="op">(</span>report_date <span class="op">=</span> <span class="va">datecol</span><span class="op">)</span> <span class="op"><a href="https://magrittr.tidyverse.org/reference/pipe.html">%>%</a></span>
<span class="fu"><a href="https://dplyr.tidyverse.org/reference/group_by.html">ungroup</a></span><span class="op">(</span><span class="op">)</span>
<span class="co">#> no target value supplied, so using the mean of x</span>
<span class="co">#> no target value supplied, so using the mean of x</span>
<span class="va">p2</span> <span class="op"><-</span> <span class="fu"><a href="reference/cusum_control_plot.html">cusum_control_plot</a></span><span class="op">(</span><span class="va">testres</span>,
xvar <span class="op">=</span> <span class="va">report_date</span>,
facet_var <span class="op">=</span> <span class="va">metric</span>,
title_text <span class="op">=</span> <span class="st">"Faceted plots with date axis"</span>,
scale_type <span class="op">=</span> <span class="st">"date"</span>,
datebreaks <span class="op">=</span> <span class="st">'4 days'</span><span class="op">)</span>
<span class="va">p2</span> <span class="op"><-</span> <span class="va">p2</span> <span class="op">+</span> <span class="fu">ggplot2</span><span class="fu">::</span><span class="fu"><a href="https://ggplot2.tidyverse.org/reference/theme.html">theme</a></span><span class="op">(</span>axis.text.x <span class="op">=</span> <span class="fu">ggplot2</span><span class="fu">::</span><span class="fu"><a href="https://ggplot2.tidyverse.org/reference/element.html">element_text</a></span><span class="op">(</span>angle <span class="op">=</span> <span class="fl">90</span>,
hjust <span class="op">=</span> <span class="fl">1</span>,
vjust <span class="op">=</span> <span class="fl">0.5</span><span class="op">)</span><span class="op">)</span>
<span class="va">p2</span></code></pre></div>
<p><img src="reference/figures/README-faceted_chart2-1.png"><!-- --></p>
</div>
<div id="highlight-above-and-below-control-limits" class="section level2">
<h2 class="hasAnchor">
<a href="#highlight-above-and-below-control-limits" class="anchor"></a>Highlight above and below control limits</h2>
<p>Points outside the Upper Control Limit are always highlighted. Use the <code>show_below</code> option to enable highlighting points below the Lower Control Limit</p>
<div class="sourceCode" id="cb10"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="kw"><a href="https://rdrr.io/r/base/library.html">library</a></span><span class="op">(</span><span class="va"><a href="https://dplyr.tidyverse.org">dplyr</a></span><span class="op">)</span>
<span class="kw"><a href="https://rdrr.io/r/base/library.html">library</a></span><span class="op">(</span><span class="va"><a href="https://ggplot2.tidyverse.org">ggplot2</a></span><span class="op">)</span>
<span class="kw"><a href="https://rdrr.io/r/base/library.html">library</a></span><span class="op">(</span><span class="va"><a href="https://github.com/johnmackintosh/cusumcharter">cusumcharter</a></span><span class="op">)</span>
<span class="va">testdata</span> <span class="op"><-</span> <span class="fu">tibble</span><span class="fu">::</span><span class="fu"><a href="https://tibble.tidyverse.org/reference/tibble.html">tibble</a></span><span class="op">(</span>
N <span class="op">=</span> <span class="fu"><a href="https://rdrr.io/r/base/c.html">c</a></span><span class="op">(</span><span class="op">-</span><span class="fl">15L</span>,<span class="fl">2L</span>,<span class="op">-</span><span class="fl">11L</span>,<span class="fl">3L</span>,<span class="fl">1L</span>,<span class="fl">1L</span>,<span class="op">-</span><span class="fl">11L</span>,<span class="fl">1L</span>,<span class="fl">1L</span>,
<span class="fl">2L</span>,<span class="fl">1L</span>,<span class="fl">1L</span>,<span class="fl">1L</span>,<span class="fl">10L</span>,<span class="fl">7L</span>,<span class="fl">9L</span>,<span class="fl">11L</span>,<span class="fl">9L</span><span class="op">)</span>,
metric <span class="op">=</span> <span class="fu"><a href="https://rdrr.io/r/base/c.html">c</a></span><span class="op">(</span><span class="st">"metric1"</span>,<span class="st">"metric1"</span>,<span class="st">"metric1"</span>,<span class="st">"metric1"</span>,<span class="st">"metric1"</span>,
<span class="st">"metric1"</span>,<span class="st">"metric1"</span>,<span class="st">"metric1"</span>,<span class="st">"metric1"</span>,<span class="st">"metric2"</span>,
<span class="st">"metric2"</span>,<span class="st">"metric2"</span>,<span class="st">"metric2"</span>,<span class="st">"metric2"</span>,<span class="st">"metric2"</span>,
<span class="st">"metric2"</span>,<span class="st">"metric2"</span>,<span class="st">"metric2"</span><span class="op">)</span><span class="op">)</span>
<span class="va">datecol</span> <span class="op"><-</span> <span class="fu"><a href="https://rdrr.io/r/base/as.Date.html">as.Date</a></span><span class="op">(</span><span class="fu"><a href="https://rdrr.io/r/base/c.html">c</a></span><span class="op">(</span><span class="st">"2021-01-01"</span>,<span class="st">"2021-01-02"</span>, <span class="st">"2021-01-03"</span>, <span class="st">"2021-01-04"</span> ,
<span class="st">"2021-01-05"</span>, <span class="st">"2021-01-06"</span>,<span class="st">"2021-01-07"</span>, <span class="st">"2021-01-08"</span>,
<span class="st">"2021-01-09"</span><span class="op">)</span><span class="op">)</span>
<span class="va">testres</span> <span class="op"><-</span> <span class="va">testdata</span> <span class="op"><a href="https://magrittr.tidyverse.org/reference/pipe.html">%>%</a></span>
<span class="fu">dplyr</span><span class="fu">::</span><span class="fu"><a href="https://dplyr.tidyverse.org/reference/group_by.html">group_by</a></span><span class="op">(</span><span class="va">metric</span><span class="op">)</span> <span class="op"><a href="https://magrittr.tidyverse.org/reference/pipe.html">%>%</a></span>
<span class="fu">dplyr</span><span class="fu">::</span><span class="fu"><a href="https://dplyr.tidyverse.org/reference/mutate.html">mutate</a></span><span class="op">(</span><span class="fu"><a href="reference/cusum_control.html">cusum_control</a></span><span class="op">(</span><span class="va">N</span><span class="op">)</span><span class="op">)</span> <span class="op"><a href="https://magrittr.tidyverse.org/reference/pipe.html">%>%</a></span>
<span class="fu">dplyr</span><span class="fu">::</span><span class="fu"><a href="https://dplyr.tidyverse.org/reference/group_by.html">ungroup</a></span><span class="op">(</span><span class="op">)</span> <span class="op"><a href="https://magrittr.tidyverse.org/reference/pipe.html">%>%</a></span>
<span class="fu">dplyr</span><span class="fu">::</span><span class="fu"><a href="https://dplyr.tidyverse.org/reference/group_by.html">group_by</a></span><span class="op">(</span><span class="va">metric</span><span class="op">)</span> <span class="op"><a href="https://magrittr.tidyverse.org/reference/pipe.html">%>%</a></span>
<span class="fu">dplyr</span><span class="fu">::</span><span class="fu"><a href="https://dplyr.tidyverse.org/reference/mutate.html">mutate</a></span><span class="op">(</span>report_date <span class="op">=</span> <span class="va">datecol</span><span class="op">)</span> <span class="op"><a href="https://magrittr.tidyverse.org/reference/pipe.html">%>%</a></span>
<span class="fu"><a href="https://dplyr.tidyverse.org/reference/group_by.html">ungroup</a></span><span class="op">(</span><span class="op">)</span>
<span class="co">#> no target value supplied, so using the mean of x</span>
<span class="co">#> no target value supplied, so using the mean of x</span>
<span class="va">p5</span> <span class="op"><-</span> <span class="fu"><a href="reference/cusum_control_plot.html">cusum_control_plot</a></span><span class="op">(</span><span class="va">testres</span>,
xvar <span class="op">=</span> <span class="va">report_date</span>,
show_below <span class="op">=</span> <span class="cn">TRUE</span>,
facet_var <span class="op">=</span> <span class="va">metric</span>,
title_text <span class="op">=</span> <span class="st">"Highlights above and below control limits"</span><span class="op">)</span>
<span class="va">p5</span></code></pre></div>
<p><img src="reference/figures/README-highlightbelow-1.png"><!-- --></p>
</div>
</div>
</div>
<div class="col-md-3 hidden-xs hidden-sm" id="pkgdown-sidebar">
<div class="links">
<h2>Links</h2>
<ul class="list-unstyled">
<li>Download from CRAN at <br><a href="https://cloud.r-project.org/package=cusumcharter">https://cloud.r-project.org/package=cusumcharter</a>
</li>
<li>Browse source code at <br><a href="https://github.com/johnmackintosh/cusumcharter/">https://github.com/johnmackintosh/cusumcharter/</a>
</li>
<li>Report a bug at <br><a href="https://github.com/johnmackintosh/cusumcharter/issues">https://github.com/johnmackintosh/cusumcharter/issues</a>
</li>
</ul>
</div>
<div class="license">
<h2>License</h2>
<ul class="list-unstyled">
<li><a href="LICENSE.html">Full license</a></li>
<li><small>GPL (>= 3)</small></li>
</ul>
</div>
<div class="developers">
<h2>Developers</h2>
<ul class="list-unstyled">
<li>John MacKintosh <br><small class="roles"> Author, maintainer </small> </li>
</ul>
</div>
<div class="dev-status">
<h2>Dev status</h2>
<ul class="list-unstyled">
<li><a href="https://github.com/johnmackintosh/cusumcharter/actions"><img src="https://github.com/johnmackintosh/cusumcharter/workflows/R-CMD-check/badge.svg" alt="R-CMD-check"></a></li>
</ul>
</div>
</div>
</div>
<footer><div class="copyright">
<p>Developed by John MacKintosh.</p>
</div>
<div class="pkgdown">
<p>Site built with <a href="https://pkgdown.r-lib.org/">pkgdown</a> 1.6.1.</p>
</div>
</footer>
</div>
</body>
</html>