luca-scr / qcc

An R package for Quality Control Charts
https://luca-scr.github.io/qcc/
43 stars 17 forks source link

Error in mqcc in T2.single type when newdata has less than 4 observations. #19

Closed S-KD closed 4 years ago

S-KD commented 4 years ago

In function mqcc with type "T2.single", if newdata has less than 4 observations and newlabels are not set then functions give an error due to lines 79 and 80. according to my tests, the problem is "length(newstats)" as this will evaluate to be 4. So, I propose following to resolve this error:

Following two lines instead of line 79: new_m <- unique(sapply(newdata, nrow)) newlabels <- seq(start + 1, start + new_m)

and then following line instead of line 80: if (length(newlabels) != new_m)

luca-scr commented 4 years ago

Can you provide a minimal reproducible example?

S-KD commented 4 years ago

Here is a minimal example

library(qcc)

Make dummy data

set.seed(0) data = matrix(rnorm(100),nrow=20,ncol=5) newdata1 = matrix(rnorm(5),nrow=1,ncol=5) newdata2 = matrix(rnorm(20),nrow=4,ncol=5)

This will give an error (if newdata have less than 4 rows and newlabels is not set)

q <- mqcc(data, type="T2.single",confidence.level=0.975, pred.limits=T,newdata=newdata1)

Both of these will not give an error

q <- mqcc(data, type="T2.single",confidence.level=0.975, pred.limits=T,newdata=newdata1,newlabels="newdata1")

q <- mqcc(data, type="T2.single",confidence.level=0.975, pred.limits=T,newdata=newdata2)

luca-scr commented 4 years ago

The bug has been fixed in the current version of the package available in GitHub.