[R] Regarding a error while plotting R chart using qcc package.
Luca Scrucca
luca at stat.unipg.it
Thu Feb 11 10:31:11 CET 2010
On 11 Feb 2010, at 06:53, Vikrant Shimpi wrote:
> Dear Luka ,
> I am using qcc package in R to plot SPC charts. BUt while plotting
> R chart I had a error. My question is it necessary while plotting
> R Chart the group sample size must be < 25 ?. Because when I took
> group sample size as 1000 it gave me error, till I took group sample
> size as 26, But as sooon as I changed the group sample size to 25
> the R chart was plotted successfully.
> I had a discussion in the R forum, at the end of it was suggested to
> write to you regarding the error. I am giving the link for the same.
>
>
> http://n4.nabble.com/problems-with-SPC-charts-in-R-td1467901.html#a1469800
>
>
>
> Also I am attaching the dataset and the code which gave me error
> while plotting R chart.
>
> R code is as follows: -
>
> SAMPLE_SIZE<-1000
> y<-read.csv("data.csv",sep=",",header=TRUE)
> y<-subset(y, !is.null(y[,1]),)
> unique_b_vals = unique(y[,2])
> final_set <- NULL
> for(b_val in unique_b_vals)
> {
> temp1 = subset(y,week==b_val,)
> temp1 = temp1[sample(dim(temp1)[1], SAMPLE_SIZE),]
> if (is.null(final_set))
> final_set <<- temp1
> else
> final_set <<- rbind(final_set,temp1)
> print(b_val)
> }
First of all, here I got an error:
Error in sample(dim(temp1)[1], SAMPLE_SIZE) :
cannot take a sample larger than the population when 'replace =
FALSE'
The final_set matrix has however dimension
> dim(final_set)
[1] 17000 3
and I will continue with this.
> library(qcc)
> attach(final_set)
> a<- qcc.groups(ST,week)
> dim(a)
> obj <- qcc(a[,],type="R")
>
> summary(obj)
> detach(final_set)
>
>
> Here I am selecting a sample of size 1000 for each group. And it
> gives me following error
>
>
> Error in limits.R(center = 62614.0571428571, std.dev = NA_real_,
> sizes = c(1000L, :
> group size must be less than 51 when giving nsigmas
Yes and it must be like that. You shouldn't use R charts for
monitoring dispersion using sample sizes larger than 20, and for
sample sizes greater than 25 you get an error. From theory, R chart
used the distribution of relative range for estimating sigma, which is
tabulated up to a sample size of 25
> qcc.options("exp.R.unscaled")
The number 51 comes from another tabulated data
> qcc.options("se.R.unscaled")
In this case you must simply use an S chart:
> obj <- qcc(a,type="S")
Some sparse notes:
- don't use a[,] to select a whole matrix, simply a, i.e. qcc(a)
- don't use <<- for assignment (it has another meaning...), <- is enough
I hope this help.
Luca Scrucca
--------------------------------------------------
Luca Scrucca
Dipartimento di Economia, Finanza e Statistica
Sezione di Statistica
Università degli Studi di Perugia
Via A. Pascoli, 20
06123 PERUGIA (ITALY)
Tel. +39-075-5855233
Fax: +39-075-5855950
E-mail: luca at stat.unipg.it
Web page: http://www.stat.unipg.it/luca
More information about the R-help
mailing list