KensoBI / spc-chart

GNU Affero General Public License v3.0
7 stars 1 forks source link

SPC Formula Accuracy: R-bar and S-bar Calculation Check #54

Closed jeanfliu closed 2 days ago

jeanfliu commented 3 weeks ago

Summary

Thank you for providing this valuable plugin! While reviewing the SPC calculations, I noticed that some results might differ from the standard SPC formulas. Specifically, the R-bar and S-bar calculations seem to not reflect the intended statistical process control (SPC) methodology, which could lead to inaccurate process monitoring.

Details

In src/data/spcCalculations.tsx, it appears that certain calculations may not align with traditional SPC practices. Please let me know if I’ve misunderstood any aspect:

  1. R-bar Calculation: (@#L118)

    • The current calcRange(values) seems to compute the range as the global max minus min of all values. However, typically, R-bar is calculated as the average range across subgroups.
    • Maybe: Replace calcRange(values) with a function that computes each subgroup's range and averages it.
  2. S-bar Calculation: (@#L178)

    • Currently, stdDev(values) calculates the standard deviation over the entire dataset. However, S-bar is often the average of each subgroup's standard deviation.
    • Maybe: Replace stdDev(values) with a function that calculates each subgroup’s standard deviation and averages it.

Reference Formula

For reference, I found R-bar calculation formulas in the x̅ and R chart and S-bar calculation formulas in the x̅ and s chart.

image

Thanks a lot! Looking forward to your thoughts!

mrtomeq commented 3 weeks ago

Hi @jeanfliu! Thanks for catching this — you're absolutely right; there is an issue with the calculations. We're working on resolving this in version 2 of the panel, which is currently in development. You can follow the progress and implementation of the formulas here: xmr.ts and xbars.ts.

Feel free to reach out if you have any other questions, and thanks again for your input!

jeanfliu commented 3 weeks ago

Hi @mrtomeq, Thank you for the quick response! It’s great to hear there's an upcoming development version and ongoing work to update the formulas. I’ll keep an eye on the progress and look forward to seeing the improvements.

Thanks again!

mrtomeq commented 5 days ago

Hi @jeanfliu, We are testing version 2 right now, and it would be awesome if you could check it out and share your thoughts! You can grab the zip file here: https://github.com/KensoBI/spc-chart/releases/tag/2.0.0.

jeanfliu commented 4 days ago

Thanks for the update and solving the calculation problem! I have tested version 2 and can confirm that the R-bar and S-bar calculations are now as expected. 👍


However, I have a couple of points I'd like to confirm regarding the control line calculation results display:

1. Timing of the Display of Calculation Results:

It seems that the calculated result now appears towards the end of the last data point, in the blank space. The time label for this point appears to be the timestamp when the calculation was processed, not the actual time of the last data point. Is this the intended behavior? image

2. Decimal Precision in Calculation Results:

I've noticed that the results are rounded to 3 valuable digits. While the actual series values follow the "Standard options > Decimals" setting, other calculated results display only 3 significant digits. In some cases, this may not accurately reflect the result. image

If necessary, I can open a new issue on these points or provide test data to help further. Thanks again!

mrtomeq commented 3 days ago

Thank you so much @jeanfliu for taking the time to test it out! Both issues have been fixed. I also added:

image

jeanfliu commented 3 days ago

Thanks so much for the quick fixes and the updates! I’ve tested the latest version, and both issues have been resolved. image

I also noticed the improvements you mentioned, such as showing all series in the tooltip by default and applying units/decimal settings to control lines – both are very helpful.

If everything looks good from your end, feel free to close the issue. Really appreciate your help!