-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathqicharts2.Rmd
318 lines (195 loc) · 5.19 KB
/
qicharts2.Rmd
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
---
title: "qicharts2"
author: "Zoë Turner @DataScienceNott @Letxuga007"
date: "February 2020"
modified date: 20200220
output: ioslides_presentation
---
```{r libs, include=FALSE}
knitr::opts_chunk$set(echo = FALSE, message = FALSE, warning = FALSE, results = 'asis')
library(dplyr)
library(readxl)
library(qicharts2)
library(lubridate)
library(pander)
```
## Questions | Because I always forget this part...
* Who uses Statistical Process Control charts?
(or run charts and funnel plots)
* Who has used qicharts2 package in R?
## Package details {.flexbox .vcenter}
```{r package, echo=TRUE, eval=FALSE}
install.packages("qicharts2")
library(qicharts2)
```
- Available on CRAN
- Comes with sample healthcare datasets
- Created by Jacob Anhøj, a doctor in Denmark
- Supercedes qichart package
# Why I like this package ...
## Reasons to be joyful {.flexbox .vcenter}
* I skim instructions
* I just _get_ healthcare data (not plants and certainly not cars)
* Reproducible examples in the vignette
* More than one type of SPC available
## Like this | Snapshot of the vignette:
```{r Run, out.width = "1000px"}
knitr::include_graphics("img/FirstRunChart2.png")
```
# Nightingale's Crimea...
## Getting data { .vcenter}
Copied data manually from: https://understandinguncertainty.org/node/214
library(datapasta) to copy directly to R
Saved in a script for quick retrieval later
```{r Crimea, echo=TRUE, results='hide'}
source("Crimea.R")
```
## Being #rstats though
```{r data, echo=TRUE, eval=FALSE}
install.packages("HistData")
library(HistData)
data("Nightingale")
```
```{r Crimea pic}
knitr::include_graphics("img/Coxcomb.png")
```
# Replot in qicharts2
## Run chart code
Built on ggplot2
```{r Crimea run, echo=TRUE, eval=FALSE}
qic(startMonth,number,
data = crimeaLong,
chart = 'run',
decimals = 0,
x.angle = 90,
title = 'Run chart deaths in Crimea War',
ylab = 'Number of deaths',
xlab = 'Month'
)
```
## Produces this
```{r Crimea run chart}
qic(startMonth,number,
data = crimeaLong,
chart = 'run',
decimals = 0,
x.angle = 90,
title = 'Run chart deaths in Crimea War',
ylab = 'Number of deaths',
xlab = 'Month'
)
```
# Sprinkle ggplot2 magic...
## Facets
```{r Crimea run facet chart}
qic(startMonth,number,
data = crimeaLong,
chart = 'run',
decimals = 0,
facets = ~death_cause,
x.angle = 90,
title = 'Run chart deaths in Crimea War',
ylab = 'Number of deaths',
xlab = 'Month'
)
```
# Just imagine...
Producing...
* 30 incident categories
* 10 wards
* 25 LSOAs
To look for signals
## The magic is one line of code
```{r Crimea run facet, echo=TRUE, eval=FALSE}
qic(startMonth,number,
data = crimeaLong,
chart = 'run',
decimals = 0,
x.angle = 90,
title = 'Run chart deaths in Crimea War',
ylab = 'Number of deaths',
xlab = 'Month'
)
```
## With the facet line
```{r Show facet line, echo=TRUE, eval=FALSE}
qic(startMonth,number,
data = crimeaLong,
chart = 'run',
decimals = 0,
facets = ~death_cause,
x.angle = 90,
title = 'Run chart deaths in Crimea War',
ylab = 'Number of deaths',
xlab = 'Month'
)
```
## Moving Range SPC
```{r mr Chart code, echo=TRUE, eval=FALSE}
qic(startMonth,number,
data = crimeaLong,
chart = 'mr',
decimals = 0,
facet = ~death_cause,
x.angle = 90,
title = 'SPC mr chart deaths in Crimea War',
ylab = 'Number of deaths',
xlab = 'Month'
)
```
## mr Chart (or is that Mr Chart!)
As seen on Twitter @Letxuga007
```{r mr Chart}
qic(startMonth,number,
data = crimeaLong,
chart = 'mr',
decimals = 0,
facet = ~death_cause,
x.angle = 90,
title = 'SPC mr chart deaths in Crimea War',
ylab = 'Number of deaths',
xlab = 'Month'
)
```
# Other SPC charts are available
## Rare events - time between
The code requires a count of days difference.
Cabg = coronary artery bypass operations
```{r cabg, echo = TRUE}
# Altered slightly from the vignette
fatalities <- cabg %>%
filter(death) %>%
mutate(dt = date - lag(date))
```
## T-chart
A point above the upper control limit is a good thing!
```{r cabg chart}
tchart <- qic(dt,
data = fatalities,
chart = 't',
title = 'Days between deaths (T chart)',
ylab = 'Days',
xlab = 'Death #')
tchart
```
# Breaking into the chart
## Getting the data
The numbers generated to create the charts can be viewed/saved by typing:
```{r Chart code, echo=TRUE}
newObject <- tchart$data
```
## When is this useful?
In this blog: https://www.r-bloggers.com/backed-by-data/ @_johnmackintosh shows how to:
* tweak the charts
And I used this code
* to include only those charts with a signal
# Other interesting things
## Further information
Jacob has created this Flexdashboard https://hospinf.shinyapps.io/hospinf/
SPC Shiny dashboards are being discussed on the NHS-R Slack site
- please join us and contribute
link: nhsrcommunity.slack.com
- Twitter: @NHSrCommunity
- Our Team: @DataScienceNott
- Me: @Letxuga007
Follow the hashtag #rstats