Control chart in R


#1

I am working to create control chart in R, able to do it with qcc Library. I need to know the way of how to get the reason for a point that goes out of control.
Also I want to show chart with OOC and without OOC to end user.


#2

Also please suggest me easy way to do a DPPM U chart in R, with axis specification


#3

Could you maybe provide links for and/or images of what you're referring to? That way people without your area of knowledge might be able to help you with the code.


#4

(upload://deQFMJqAf7ZbtlaG9caGBAE5Kn1.png)

I have attached image of my data and a sample chart where a Out of control point in 22 and 40 group. I want to know how we can identify the reason for the OOC and how to exclude that in chart. Need to give both chart with OOC and without OOC and also need to give reason for OOC.


#5

@ksasi2k3 - Your example has several points 'out of control'. The default for identifying rules is to apply Shewart's rules - see the documentation for the the function shewhart.rules The red points are beyond the limits. The yellow points are because a certain number of consecutive points fall on the same side of the mean. The default number is 7 specified by qcc.options("run.length").

A qcc object contains a violations component which contains the indices for the beyond.limits limits and violating.runs points. This will identify your reasons. Not sure what you mean by a chart without the OCC...


#6

The chart without OOC means, I want to first identify the reason for OOC and then remove those red points from the chart and display the new chart which will show different variation. Sure I will try this shewhart.rules,meantime any example would help better as I am new to R


#7

Best I can do without your code is to suggest you name your qcc object, i.e.

chrt <- qcc(....)

and then take a look at

chrt$violations

which will give you the indices for the OOC points - you can use those to remove them from your data set and re-plot.


#8

This is my data and here is my code.

First I used qicharts2 Library

qic((NUMERATOR/DENOMINATOR)*1000000,
	x=monthkey,
	data=df,
	chart='u',
	title='Control chart',
	ylab='Percent defects',
	xlab='Month')

Then Tried qcc Library:

obj<- qcc(data=currTableDF, type="u",xlab="Month")
library(qcc)
df2<- qcc.groups(DENOMINATOR,NUMERATOR)
obj<- qcc(data=df,type="u",sizes=NUMERATOR/DENOMINATOR)

#9

Hi @ksasi2k3, to get further help, you'll need to provide a reproducible example. To learn how to make one, consider the thread:


#10

sure will do that jrlewi .. meantime I want to attach excel which I cant. let me know how to do that, so that I will explain step by step about my problem


#11

1.My Goal: Need to create DPPM(Defective parts per million) U or P chart in R, then analyze the chart when OOC is found. Need to identify the reason for OOC and also remove those OOC points from chart and display it to end user either by mail or other means(suggestion please)

2.Data:

Matl_id Supplier monthkey Built Failed
781581-003 Seagate 12/1/2017 14496 5
781581-003 Toshiba 12/2/2017 10438 505
781581-003 WDC 12/3/2017 4196 5
781581-003 Seagate 12/4/2017 11745 1
781581-003 Toshiba 12/5/2017 9362 100
781581-003 WDC 12/6/2017 7251 1
781581-003 NOT FOUND 12/7/2017 1 2
781581-003 Seagate 12/8/2017 6676 200
781581-003 Toshiba 12/9/2017 863 22
781581-003 WDC 12/10/2017 7169 352
781581-003 Seagate 12/11/2017 3052 1
781581-003 Toshiba 12/12/2017 1802 1
781581-003 WDC 12/1/2018 2974 120
781581-003 Seagate 12/2/2018 2051 2
781581-003 Toshiba 12/3/2018 3700 2

Here we have ID, supplier, date, Built and failed. These are data for number of units built and failed during a period for particular Id and supplier. Need to know create DPPM(Defective parts per million) U or P chart and identify OOC, reason for OOC on particular point and highlight it either in text or other way. Finally need to remove the OOC point from chart and display the chart with other data to see any variation.

3.Code:
First I used

library(qicharts2)

qic((Failed/Built)*1000000,

	x=monthkey,
	data=df,
	chart='u',
	title='Control chart',
	ylab='Percent defects',
	xlab='Month')

unable to produce violating rules, hence used another library.

library(qcc)
library("readxl")
df<- read_excel("C:/Users/Desktop/Data6.xlsx")
print(df)
obj<- qcc(data=df,type="u",sizes= 100)

I used this but got blank chart, not sure how to give option in "qcc" library.
I want to calculate DPPM as ((Failed/Built)*1000000) and plot this with month in x axis. and then need to identify OOC , reason and eliminate those from chart and display to user.


#12

Hi Ksasi2k3 - if there is a way to attach an excel file...please don't. Generally, people are not going to download external files. Instead, the idea is to provide a smaller data set that demonstrates what you want to do directly in your R code - one way to do this is using dput. I suggest looking through the following discussion on stackoverflow:


#13

We have a discussion here, too, with a whole boatload of ideas for sharing your data in a way that makes it easy for people to help you:

And no, the forum settings do not allow attaching Excel files, due to the obvious security risks.


#14

Hi jrlewi, yeah I got it, I have already sent my entire problem as reply to REPREX.


#15
               **Issue with DPPM chart in R when OOC**
library("readxl")
df<- read_excel("C:/Users/ksasid/Desktop/Data6.xlsx")
print(df)
library(qicharts2)
qic((Failed/Built)*1000000,
	x=monthkey,
	data=df,
	chart='u',
	title='Control chart',
	ylab='Percent defects',
	xlab='Month')

I used this qicharts2 Library but unable to acheive my goal, hence thought of using qcc Library

data(df)
q1=with(currTableDF,qcc((NUMERATOR),sizes = monthkey,type = "p",plot = TRUE))
plot(q1,add.stats = TRUE)

Data:

Matl_id Supplier monthkey Built Failed
781581-003 Seagate 12/1/2017 14496 5
781581-003 Toshiba 12/2/2017 10438 505
781581-003 WDC 12/3/2017 4196 5
781581-003 Seagate 12/4/2017 11745 1
781581-003 Toshiba 12/5/2017 9362 100
781581-003 WDC 12/6/2017 7251 1
781581-003 NOT FOUND 12/7/2017 1 2
781581-003 Seagate 12/8/2017 6676 200
781581-003 Toshiba 12/9/2017 863 22
781581-003 WDC 12/10/2017 7169 352
781581-003 Seagate 12/11/2017 3052 1
781581-003 Toshiba 12/12/2017 1802 1
781581-003 WDC 12/1/2018 2974 120
781581-003 Seagate 12/2/2018 2051 2
781581-003 Toshiba 12/3/2018 3700 2

Task I need to achieve and which I am struggling:

  1. I want to use this data and create a U chart.
  2. Identify and highlight out of control point in that chart
    3.Notify the Out Of Control (OOC) in a text in table at bottom
    4.Remove the OOC from original chart and display it to users.

How to Create U chart
#16

This post was flagged by the community and is temporarily hidden.


#17

My team does a lot of SPC charts in R, typically with {qicharts2}, but yeah, what you're describing is pretty advanced. We are actually extracting the data out of the ggplot2 object of "qic()" and have begun playing with representing things like special cause variation.

My initial thought would be to do some combination of qcc (to get rule violations + which points violate for your tagle) and qic to plot.

I've been confronting a similar problem at work, and if I tackle it there I'll come back and post it here :grinning:


#18

yeah.. Christiannolan your thoughts are valid and let me know in future also if I solve this I will post. Mean time can you let me know to create U or P chart using my data with month labels in x axis.


#19

To create a U chart, you need to specify a vector containing the number of defects observed for each group, the sample size of each group, and set type to 'u'. For example:

library(qcc)
data("orangejuice")
with(orangejuice,
     qcc(D, sizes = size, type = 'u')
)

To change the labels on the x axis, provide a vector to the labels argument:

library(lubridate)
date_labels <- strftime(ymd('2018-08-08') + days(0:53), '%m/%d') 
with(orangejuice,
     qcc(D, sizes = size, type = 'u' , labels = date_labels)
)

#20

Hi, Thank you very much. I am able to create U chart using

library(qicharts2)
Uchart<-qic(Failed,
            n=Built,
            x=DateMonth,
            data=df1,
            # exclude = TRUE,
            # facets = NULL,
            show.labels = TRUE,
            multiply = 1000000,
            chart='u',
            title='Control chart before Analysis',
            xlab='Month',
            ylab='Defective parts per million',
          )
Uchart

Now I want to know how I can loop this using chart creation code.

Example: I have four columns Namely:

  1. Id
    2.Site
    3.Supplier
    4.Manufacturer

I want to loop through each column and create the chart. or for Individual column I need to run the chart code.

Please let me know for any suggestions.