The hardware and bandwidth for this mirror is donated by METANET, the Webhosting and Full Service-Cloud Provider.
If you wish to report a bug, or if you are interested in having us mirror your free-software or open-source project, please feel free to contact us at mirror[@]metanet.ch.

XmR

Kenith Grey

2018-11-30

Preparing an XmR plot is common when dealing with processes where a single product/item is made or measured and there is a significant time gap between the next production or observation. XmR plots can also be useful when dealing with outputs from a batch process rather than a continuous one.

Generating an XmR plot with ggQC is simple. To get us started, let’s simulate some data on the diameter of a golden egg produced monthly by a golden goose.

set.seed(5555)
Golden_Egg_df <- data.frame(month=1:12,
                 egg_diameter = rnorm(n = 12, mean = 1.5, sd = 0.2)
                 )

For fun, lets make the egg on the third month intentionally larger than “normal”.

Golden_Egg_df$egg_diameter[3] <- 2.5

Simple XmR Plot

Great! Let’s make the plot:

library(ggplot2)
library(ggQC)

XmR_Plot <- ggplot(Golden_Egg_df, aes(x = month, y = egg_diameter)) +
               geom_point() + geom_line() + 
               stat_QC(method = "XmR")

XmR_Plot

As expected, the 3rd egg is not typical for our golden goose, falling slightly outside the upper control limit. Wouldn’t it be nice if it produced more large eggs like this. Perhaps we should go back and see if the feed was different during the month.

You take the control chart to your boss. He too asks about the feed stock during the third month, but he also wants to know what the control limits are on the plot. To display the control limits, you use the stat_QC_labels function as shown below.

Labeled XmR Plot

XmR_Plot + stat_QC_labels(method="XmR")

mR Plot

You return back to your boss. He is pleased with the plot, but now wishes to see a plot illustrating egg-to-egg consistency. For this, you will need a Moving Range (mR) plot. Using ggQC, we will call the stat_mR function to render the necessary data.

**Note** it is normal for stat_mR() to produce a warning, because the first point becomes an NA. 
mR_Plot <- ggplot(Golden_Egg_df, aes(x = month, y = egg_diameter)) +
               stat_mR() + 
               stat_QC_labels(method="mR")

mR_Plot

Faceting

The consistency looks good with the exception of the third month. Your boss is pleased, business is good. Actually so much so, that other towns have moved into the business (Trentown and Maxhall). There is a town fair coming up and there will be eggs from all producers, so you go back to last year’s monthly data and compare goose performance using control charts.

Below, we put the data provided in data frames and bind them together into one data frame. (data is simulated)

set.seed(123456)

last_year <- seq(from = as.POSIXct("2000-01-01", tz = "GMT"), length.out = 12, by = "month")

OurGoose <- data.frame(month=last_year, egg_diameter = rnorm(n = length(last_year), mean = 1.5, sd = 0.2),
                       group = "OurGoose"
)
TrentTown <- data.frame(month=last_year, egg_diameter = rnorm(n = length(last_year), mean = 2.5, sd = 0.6),
                        group = "TrentTown"
)
Maxhall <- data.frame(month=last_year, egg_diameter = rnorm(n = length(last_year), mean = .5, sd = 0.1),
                      group = "Maxhall"
)

GooseData <- rbind(OurGoose, TrentTown, Maxhall)

Knowing the farmer will want to look at the diameter of the eggs and the consistency of production, you anticipate his request with the following faceted plot.

library(gridExtra)

XmR_Town <- ggplot(GooseData, aes(x = month, y = egg_diameter)) +
               geom_point() + geom_line() + 
               stat_QC(method = "XmR") + 
               stat_QC_labels(method="XmR") +
               facet_grid(.~group) 
mR_Town <- ggplot(GooseData, aes(x = month, y = egg_diameter)) +
               stat_mR(method = "mR") + 
               stat_QC_labels(method="mR") +
               facet_grid(.~group) + ylab("mR")


grid.arrange(XmR_Town,  mR_Town, nrow = 2)

Summarizing Result in a Table

Farmer is again pleased, and makes a final request that you summarize the mean and control limits for each goose in a table that he can print and put in his wallet for the fair.

This can be done quickly using ddply and the QC_Lines function.

library(plyr)

ddply(GooseData, .variables = "group", 
      .fun = function(df)
        {QC_Lines(data = df$egg_diameter, method = "XmR")}
      )
##       group xBar_one_LCL      mean xBar_one_UCL mR_LCL         mR
## 1  OurGoose     1.089317 1.5970656    2.1048145      0 0.19088307
## 2 TrentTown     1.123161 2.7691761    4.4151913      0 0.61880273
## 3   Maxhall     0.218737 0.4544595    0.6901819      0 0.08861748
##      mR_UCL      sigma
## 1 0.6238059 0.16924965
## 2 2.0222473 0.54867175
## 3 0.2896019 0.07857416

For more Information and Examples using ggQC please visit (ggQC.r-bar.net)

These binaries (installable software) and packages are in development.
They may not be fully stable and should be used with caution. We make no claims about them.