library(ggplot2) library(ggQC) library(qcc) ####### Graficos de controle por variáveis dados <- read.csv("https://raw.githubusercontent.com/cibelerusso/Gestao-da-qualidade/main/Dados/Cozimento.csv", header=TRUE, sep=';', dec=',') X <- c(cbind(dados$x1, dados$x2, dados$x3, dados$x4, dados$x5)) n_amostra <- rep(dados$Amostra, 5) amostra <- c(rep(1,45), rep(2,45), rep(3,45), rep(4,45), rep(5,45)) df <- data.frame(n_amostra=n_amostra, amostra = amostra, X = X) View(df) # Usando o qcc # Todas as observações qcc(dados[,2:6], type='xbar') qcc(dados[,2:6], type='R') # Pacote ggQC: https://cran.r-project.org/web/packages/ggQC/ggQC.pdf ### Gráfico de Xbarra e R XbarraeR <- ggplot(df, aes(x = n_amostra, y = X)) + stat_summary(fun.y = "mean", color = "blue", geom = c("point")) + stat_summary(fun.y = "mean", color = "blue", geom = c("line")) + stat_QC(method = "xBar.rBar") + stat_QC(method = "rBar") XbarraeR # Uses the same data as previous example. QC_Violations <- ggplot(df, aes(x = n_amostra, y = X)) + #init ggplot stat_qc_violations(method = "xBar.rBar" #show.facets = 4 #if you just want facet 4 ) QC_Violations # Uses the same data as the first example CapabilityAnaylsis <- ggplot(df, aes(x = X)) + #init ggplot geom_histogram(binwidth = .02, color="purple") + #make the histogram stat_QC_Capability( LSL=1, USL=2, #Specify LSL and USL show.cap.summary = c("Cp", "Cpk"), #selected summary digits = 2, #report two digits method="XmR") + #Use the XmR method scale_x_continuous(expand = expansion(mult = c(0.15,.65))) #pad the X-axis #plot the graph CapabilityAnaylsis ## ## Grouped-data ## # Gráfico de controle para a soma cumulativa: https://www.rdocumentation.org/packages/qcc/versions/2.6/topics/cusum # install.packages('qcc') library(qcc) # CUSUM tabular para os dados do cozimento df2 <- qcc.groups(X, n_amostra) cusum(df2, decision.interval = 3, se.shift = 1) # Máscara V # https://rdrr.io/cran/vMask/man/vMask-package.html # https://www.itl.nist.gov/div898/handbook/pmc/section3/pmc323.htm # https://www.pure.ed.ac.uk/ws/portalfiles/portal/11028324/Cusum_Charts.pdf # Pacote vMask - Instalar manualmente utilizando https://cran.r-project.org/src/contrib/Archive/vMask/ # install.packages("vMask") # install.packages("~/Downloads/vMask_1.0.tar.gz", repos = NULL, type = "source") library(vMask) ### Example 1: V-Mask CUSUM chart with vectored data based on the real data from: # https://www.itl.nist.gov/div898/handbook/pmc/section3/pmc323.htm # In this applied example We are going to quickly detect a shift in mean as large as one # sigma by CUSUM chart. Data = dados$Xbarra n = 5 mean(Data) sd(Data) sd(Data)/sqrt(n) vMask.method3(data=Data, mu0=1.5, k=1, alpha=.0027, beta=.01, s="PressEnter" ) ### Example 2: V-Mask CUSUM chart based on a data matrix. # A wood products company manufactures charcoal briquettes for barbecues. It packages these # briquettes in bags of various sizes, the largest of which is supposed to contain 40 lbs. # The weights of bags from 16 different samples, each of size n=4 are given in below. n = 5 m = 45 mu0 = 1.5 sigma = .14 Data = dados[,2:6] M = Data M # X.bar Control Chart: ( LCL = mu0 - 3*sigma/sqrt(n) ) ( UCL = mu0 + 3*sigma/sqrt(n) ) plot(1:45, rowMeans(M), col=3, pch=16, ylim=c(LCL-.2,UCL+.2)) abline(h=c(mu0, LCL, UCL), col=2, lty=c(3,1,1)) # Three different strategies for putting v-mask on CUSUM Control Chart: M <- cumsum(apply(Data,1,mean)-mu0) vMask.method2(M, mu0=0, d=0.5, h=0.4, sl="PressEnter" ) vMask.method6( data=M, mu0=0, mu1=0.3, sigma=.5, h=1, w=2, sl="PressEnter" ) vMask.method5( data=M, mu0=0, mu1=0.3, alpha=.1, beta=.01, sl="PressEnter")