Control Charts Another Package

April 19, 2019
By

[This article was first published on Analysis of AFL, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

I got an email from Alex Zanidean, who runs the xmrr package

“You might enjoy my package xmrr for similar charts – but mine recalculate the bounds automatically” and if we go to the vingette, “XMRs combine X-Bar control charts and Moving Range control charts. These functions also will recalculate the reference lines when significant change has occurred” This seems like a pretty handy thing. So lets do it.

First lets do our graphic from our previous post using ggQC

library(fitzRoy)
library(tidyverse)
## ── Attaching packages ───────────────────────────────────────────────────────── tidyverse 1.2.1 ──
## ✔ ggplot2 3.1.1       ✔ purrr   0.3.2  
## ✔ tibble  2.1.1       ✔ dplyr   0.8.0.1
## ✔ tidyr   0.8.3       ✔ stringr 1.4.0  
## ✔ readr   1.3.1       ✔ forcats 0.4.0
## ── Conflicts ──────────────────────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag()    masks stats::lag()
library(ggQC)
library(xmrr)
fitzRoy::match_results%>%
  mutate(total=Home.Points+Away.Points)%>%
  group_by(Season,Round)%>%
  summarise(meantotal=mean(total))%>%
filter(Season>1989 &  Round=="R1")%>%
  ggplot(aes(x=Season,y=meantotal))+geom_point()+
  geom_line()+stat_QC(method="XmR")+
  ylab("Mean Round 1 Total for Each Game") +ggtitle("Stop Freaking OUT over ONE ROUND")

df<-fitzRoy::match_results%>%
  mutate(total=Home.Points+Away.Points)%>%
  group_by(Season,Round)%>%
  summarise(meantotal=mean(total))%>%
filter(Season>1989 &  Round=="R1")

So when using a package for the first time, one of the best things about the R community is how the examples are usually fully reproducible and this helps.

From the github

Year <- seq(2001, 2009, 1)
Measure <-  runif(length(Year))

df <- data.frame(Year, Measure)
head(df)
##   Year   Measure
## 1 2001 0.6146880
## 2 2002 0.2854914
## 3 2003 0.6081190
## 4 2004 0.4357665
## 5 2005 0.1509844
## 6 2006 0.5935707
xmr(df, "Measure", recalc = T)
##   Year   Measure Order Central Line Moving Range Average Moving Range
## 1 2001 0.6146880     1        0.419           NA                   NA
## 2 2002 0.2854914     2        0.419        0.329                0.277
## 3 2003 0.6081190     3        0.419        0.323                0.277
## 4 2004 0.4357665     4        0.419        0.172                0.277
## 5 2005 0.1509844     5        0.419        0.285                0.277
## 6 2006 0.5935707     6        0.419        0.443                0.277
## 7 2007 0.5739720     7        0.419        0.020                0.277
## 8 2008 0.9961513     8        0.419        0.422                0.277
## 9 2009 0.9091553     9        0.419        0.087                0.277
##   Lower Natural Process Limit Upper Natural Process Limit
## 1                          NA                          NA
## 2                           0                       1.156
## 3                           0                       1.156
## 4                           0                       1.156
## 5                           0                       1.156
## 6                           0                       1.156
## 7                           0                       1.156
## 8                           0                       1.156
## 9                           0                       1.156

Lets create a similar dataframe as df, but using data from fitzRoy

df<-fitzRoy::match_results%>%
  mutate(total=Home.Points+Away.Points)%>%
  group_by(Season,Round)%>%
  summarise(meantotal=mean(total))%>%
filter(Season>1989 &  Round=="R1")%>%
  select(Season, meantotal)
df<-data.frame(df)
xmr_data <-xmr(df, "meantotal", recalc = T)

xmr_chart(df = xmr_data, 
          time = "Season", 
          measure = "meantotal",
          line_width = 0.75, text_size = 12, point_size = 2.5)

Does this tell a different story or a very similar one to earlier?

To leave a comment for the author, please follow the link and comment on their blog: Analysis of AFL.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.



If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Comments are closed.

Search R-bloggers

Sponsors

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)