R Markdown

This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.

When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:

summary(cars)
##      speed           dist       
##  Min.   : 4.0   Min.   :  2.00  
##  1st Qu.:12.0   1st Qu.: 26.00  
##  Median :15.0   Median : 36.00  
##  Mean   :15.4   Mean   : 42.98  
##  3rd Qu.:19.0   3rd Qu.: 56.00  
##  Max.   :25.0   Max.   :120.00

Including Plots

You can also embed plots, for example:

Note that the echo = FALSE parameter was added to the code chunk to prevent printing of the R code that generated the plot.

Well, trying to remember how to use R markdown. This is text. Here’s some code, but I suspect I’ll have to import or install or library the stats package. Let’s try that first:

library(stats)

Now, let’s try running some stats stuff

dbinom(x=11,size=235,prob=.059)
## [1] 0.08726632

Ok, that seems to be working. How about

1-pbinom(q=10,size=235,prob=.059)
## [1] 0.8232511

Now the plot:

x<-0:25
plot(dbinom(x,235,.059))

Binomial Experiment - characteristics series of n trials each trial is a success (bad die) or failure constant probability of success p trials are independent X is the number of successes in n trials X~Bin(n,p) we know what P(x) = n choose x px(1-p)(n-x) = np var(x) = np(1-p) The cumulative density function F(x) is the sum of the P(x)

Let’s say we have a process that delivers a constant defect rate of 5.9%. If we select a random sample of 235 chips, what is the probability of 11 bad chips? n= 235 X = number of defects X = 1, 2, 3, ……235 X ~ bin(235,0.059) want P(X=11) = 235 choose 11 (0.059)^11 * (0.941)^224

We’ll put some code in here in a minute, but first what’s the probability of P(X>= 11) easier to calculate 1- P(X<=10) - 1 - F(10) could also ask what is the expected number of defective chips? That’s = np = 235 * 0.059 Using R, dbinom is the probability mass function for binomial distribution. dbinom(x,n,p) Also, in R, the cumulative probability is pbinom(X,n,p)

dbinom(x=11,size=235,prob=0.059)
## [1] 0.08726632
235*.059 #number of defective boards
## [1] 13.865

What’s the probability of x>11 - 1 - probability of x <10

1-pbinom(q=10,size=235,prob=0.059)
## [1] 0.8232511

Poison Distribution: Have area of opportunity, space or time find non-conformities in the area or time assuming non-conformities are purely random Assume a 2x5 foot table. After staining and coating you find defect from dust, dirt, etc. Since these are random, we find a Poisson distribution x = number of non-conformities/space or time x can be 0, 1,2,3, to infinity P(x) = lambda^xexp(-lambda)/(xfactorial) lambda is the expected rate of nonconformities, i.e., number per unit area or number per unit time. IF we know lambda we know everything. Now we can calculate mass and density Poisson process with rate of 7.35 contaminants/wafer. What is probability we find a wafer with =12 or more than 12 defects?

P(x=12) ? As above this is P(12) = 7.35^12exp(-7.35?12!) now want P(x>=12) = 1 - P(x<=11) = 1 - F(11) density is dpois, cum is ppois

dpois(x=12,lambda=7.35) #pro(x=12 with lambda =n7.35)
## [1] 0.03334622
1-ppois(q=11,lambda=7.35) #prob(x>=12)
## [1] 0.07076956

Now want np and p charts. Based in the Binomial Distribution np chart is for fixed subgroup size n – easier to use p chart allows for variable subgroup sizes Derive Shewhart Charts Type 1 and 2 errors are calculated from Binomial distribution

Example … find np and p charts for previous example What is in-control ARL? If percent defective suddenly shifts to 8%, what is out-the corresponding out-of-control ARL?

Shewhart charts: recall UCL = + 3 sigma(w) LCL = - 3 sigma(w) = np sigma^2 = np(1-p) UCL = np + 3 * sqrt (np(1-p)) CL = np LCL = np - 3 sqrt(np*(1-p))

What about p charts? To make independent of n, divide by n UCL = p + 3 * sqrt(p(1-p)/n) CL = p LCL = p - 3 sqrt(p*(1-p)/n)

A manufacturing process produces semiconductor chips with a known failure rate of 5.9% . If a random sample of 235 chips is selected, what is probability that there will be exactly 11 defective chips? What is the probability of 11 or more defective chips?? (work by hand and using R)

For this example

n <-235
p <- 0.059
CL <- n*p
UCL<- n*p + 3*sqrt(n*p*(1-p))
LCL<- n*p - 3*sqrt(n*p*(1-p))
CL
## [1] 13.865
UCL
## [1] 24.70117
LCL
## [1] 3.028825

Operator samples the production line drawing 235 parts and counting defects multiple times. Between 4 and 24 defects, the process is in control.Less than 3 or more than 24 is out of control.

What’s alpha? For normal distribution, alpha was 0.0027 and ARL was 1/alpha or 370.4. What about the binomial distribution?

Sometimes LCL will be less than zero. Alpha will not be 0.0027. False alarm, alpha. If process is in control, p=0.059. Let’s find prob(in control) and then alpha will be = 1-prob(in control). Can write all of the probabilities out x=4 to x =24, add them all up and subtract from 1. This is actually 1 - [prob(x<24) - prob(x<3)] = 1 - [F(24) -F(3)] In R

alpha = 1 - (pbinom(q=24, size=235, prob=0.059)+
               -pbinom(q=3, size=235, prob=0.059))
alpha #producer risk
## [1] 0.003773658
ARL0=1/alpha #ARL, average run length
ARL0
## [1] 264.9949

So, alpha, the out of control probability when the process is actually in control is now 0.00377 (producers risk, type 1 error), and the average run length is 265.

Let’s find beta and customers risk, type 2 error. Let’s say the percent defective jumps to 8%. What’s the probablity that I detect this, or what’s the average run length, ARL1

p1 = 0.08 what is ARL1, 1/(1-beta) beta is prob(4<=x<=24; prob = 0.08). Then we want 1-beta beta= [F(24)-F(3)], given prob=0.08

beta = (pbinom(q=24, size=235, prob=0.08)+
               -pbinom(q=3, size=235, prob=0.08))
beta  #customers risk, tpe 2
## [1] 0.9109067
ARL1=1/(1-beta) #ARL1, when prob is actually 0.08
ARL1
## [1] 11.22419

Ok, now C and U charts, based on the Poisson distribution: Based in the Poisson Distribution c chart is for fixed subgroup size n – easier to use u chart allows for variable subgroup sizes Derive Shewhart Charts Type 1 and 2 errors are calculated from Poisson distribution

Example … find c charts for previous example What is the in-control ARL? If the average number of defect per wafer suddenly shifts to 10.5, what is the corresponding out-of-control ARL?

For a c chart, H0 is lambda = lambda0, H1: lambda not = lambda0

CL = lamba0 UCL = lambda0 + 3 sqrt(lamda0) LCL = lambda0 - 3 sqrt(lambda0)

lambda0<-7.35
UCL <-lambda0 + 3*sqrt(lambda0)
CL <- lambda0
LCL <- lambda0 - 3*sqrt(lambda0)#must set LCL =0 if <0

CL
## [1] 7.35
UCL
## [1] 15.48327
LCL
## [1] -0.783265
alpha=1-ppois(q=15,lambda=7.35)
ARL0=1/alpha

alpha
## [1] 0.003821787
ARL0
## [1] 261.6577

What about out of control ARL1 when lambda1 shifts 10.5 Now need prob(0<x<15, given lambda1=10.5) beta = prob(0,x,15 given lambda =10.5)

beta = ppois(q=15,lambda=10.5)
ARL1=1/(1-beta) 
beta
## [1] 0.9316651
ARL1
## [1] 14.6338

Next: np, p, c. u charts with qcc

np-chart qcc(column defects, column size, type = “np”)

p-chart qcc(column defects, column size, type = “p”)

c-chart qcc(column non-conf, column size, type = “c”)

u-chart qcc(column non-conf, column size, type = “u”)

```{r}# dbinom(x=11,size=235,prob=.059) 1-pbinom(q=10,size=235,prob=.059)

x<-0:25 plot(dbinom(x,235,.059))

dpois(12,7.35) 1-ppois(11,7.35)

np<-235*.059 np 1-(pbinom(24,235,0.059))-pbinom(3,235,0.059) 1/(1-(pbinom(24,235,0.059))-pbinom(3,235,0.059))

pbinom(24,235,.08)-pbinom(3,235,.08) 1/(1-(pbinom(24,235,.08)-pbinom(3,235,.08)))

1-ppois(15,7.35) 1/(1-ppois(15,7.35)) ppois(15,10.5) 1/(ppois(15,10.5))

```