anhoej / qicharts2

R package: Quality improvement charts
38 stars 12 forks source link

t-chart (via qic.i) chart calculation question #43

Closed Rmadillo closed 6 months ago

Rmadillo commented 6 months ago

In the helper functions file, I was wondering whether this was a typo or purposeful to calculate the moving range for the t/i charts:

qic.i <- function(x) {
  base <- x$baseline & x$include
  if (anyNA(x$cl))
    x$cl <- mean(x$y[base], na.rm = TRUE)

  # Average moving range
  mr  <- abs(diff(x$y[base] - x$cl[base]))

Typically, the MR is based on the difference between x and x-1, rather than the center line (cl), which is what it looks like this code is doing? Or am I missing how this code worked?

Thanks!

anhoej commented 6 months ago

Thanx, Rmadillo

This is exactly what open source is about :) The calculation is correct. However, I wonder why I subtract the center line from y before calculating amr. There must have been a reason. I'll look into that.

But subtracting a constant (x$cl[base] from the y values before calculating the pairwise differences makes no difference to the result. Here is an example.

` set.seed(1) y <- rnorm(12)

cl <- mean(y) amr <- mean(abs(diff(y))) ucl1 <- cl + 3 * amr / 1.128

ucl2 <- qicharts2::qic(y, chart = 'i')$data$ucl[1] identical(ucl1, ucl2) `

Rmadillo commented 6 months ago

Ah, of course. 1) I miscounted the parentheses and 2) (worse) I was testing results for a t-chart but in in qic I had written chart = 'g'. Idiot = me. But thank you for responding to a dumb question!

anhoej commented 6 months ago

No such thing as a dumb question. You got my pulse up, though, which is a good thing :)