February 2020

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

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

  • 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:

Nightingale’s Crimea…

Getting data

Being #rstats though

install.packages("HistData")

library(HistData)

data("Nightingale")

Replot in qicharts2

Run chart code

Built on ggplot2

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

Sprinkle ggplot2 magic…

Facets

Just imagine…

Producing…

  • 30 incident categories

  • 10 wards

  • 25 LSOAs

To look for signals

The magic is one line of code

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

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

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

Other SPC charts are available

Rare events - time between

The code requires a count of days difference.

Cabg = coronary artery bypass operations

# 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!

Breaking into the chart

Getting the data

The numbers generated to create the charts can be viewed/saved by typing:

newObject <- tchart$data

When is this useful?

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