Skip to content

Instantly share code, notes, and snippets.

@rsalaza4
Last active October 11, 2020 16:33
Show Gist options
  • Save rsalaza4/29c4e3fab27bd05e56b44ce0fceb1082 to your computer and use it in GitHub Desktop.
Save rsalaza4/29c4e3fab27bd05e56b44ce0fceb1082 to your computer and use it in GitHub Desktop.
# Import the qcc library
library(qcc)
# Create a measures column
measures <- rnorm(200, 3, 1)
# Specify the sample size
sample_size <- 5
# Get the total number of samples
number_of_samples <- length(measures)/sample_size
# Assign the measures to the corresponding sample
sample <- rep(1:number_of_samples, each = sample_size)
# Create a data frame with the measures and sample columns
df <- data.frame(measures, sample)
# Group the measures per sample
measure <- with(df, qcc.groups(measures, sample))
# View the grouped measures
head(measure)
# Specify the measures unit
measure_unit <- "lbs"
# Create the x-bar chart
xbar <- qcc(measure, type = "xbar", data.name = measure_unit)
# Specify the warning limits (2 sigmas)
(warn.limits.2 = limits.xbar(xbar$center, xbar$std.dev, xbar$sizes, 2))
# Specify the warning limits (1 sigmas)
(warn.limits.1 = limits.xbar(xbar$center, xbar$std.dev, xbar$sizes, 1))
# Plot the x-bar chart
plot(xbar, restore.par = FALSE)
# Plot the warning limit lines
abline(h = warn.limits.2, lty = 2, col = "blue")
abline(h = warn.limits.1, lty = 2, col = "lightblue")
# Get the summary for x-bar chart
summary(xbar)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment