I can plot an EWMA control chart with 3 sigma limits (nsigmas=3
). Can anyone help me with plotting additional control lines on the same chart such as 1 and 2 sigma limits?
The only way I can think is to create separate qcc
objects with each of these limits, somehow extract their values, and then plot them onto the EWMA chart. Surely there's a simpler way?
library(qcc)
LRR <- c(-0.1, -0.1, -0.09, -0.07, -0.27, -0.18,
-0.8, -0.86, -0.82, 0.01, 0.02)
q1 <- ewma(LRR, center = -0.3, std.dev = 0.1 , lambda = 0.2,plot=F)
plot(q1, add.stats = F, label.limits = c("LCL", "UCL"),
xlab="Group", ylab= "LRR", ylim=c(-1.0,0.5),nsigmas = 3)
Now I'd just like to add 1 & 2 sigma control limits.
Thanks.
Thank you so much Paul. Your answer is certainly more sophisticated than mine was!
I ended up solving it by;
'escalc' to find the LRR, then
rma(yi=LRR,vi=LRR_var)
est = 'estimate' from this rma
q1 <- ewma(LRR, center = est, lambda = 0.2,labels=year,plot=F)
LCL1 <- est - q1$sigma
LCL2 <- est - 2*q1$sigma
UCL1 <- est + q1$sigma
UCL2 <- est + 2*q1$sigma
LCL3 <- est - 3*q1$sigma
UCL3 <- est + 3*q1$sigma
Then using plot
abline(h=center,lty=1)
lines(spline(1:4,LCL1,n=10), lty = "dotted", col = "grey")
lines(spline(1:4,UCL1,n=10), lty = "dotted", col = "grey")
lines(spline(1:4,LCL2,n=10), lty = "dotted", col = "black")
lines(spline(1:4,UCL2,n=10), lty = "dotted", col = "black")
lines(spline(1:4,LCL3,n=10), lty = "longdash", col = "black")
lines(spline(1:4,UCL3,n=10), lty = "longdash", col = "black")