SQL 或 SSRS 中组内的标准差(或者 - 计算 Sigma 或 Cpk)
我在 SSRS/SQl 中计算子组内的标准偏差时遇到严重问题(以更方便的为准)。这背后的真正原因是我需要计算 Sigma 值(根据六西格码原则)或 Cpk 值(过程能力),但我的努力停留在标准差上。
我不擅长统计,但似乎SSRS(和SQL)中的StDev和StDevP函数不是在“子组内”计算的,而且我找不到一个函数可以做到这一点。下面是一个 Excel 屏幕截图,显示了我想在 SQL/SSRS 中实现的计算步骤 编辑:尚无法发布图像,请在下面查找
棘手的部分是计算每对值之间的绝对差之和。给出值的顺序很重要。我忘了提及 Rbar 分母(第 7 行)中的数字 27 是样本大小减 1 (27)。下面也是 SQL 中的一个表:
DECLARE @Measurements TABLE(Val FLOAT)
INSERT INTO @Measurements (Val)(
SELECT 485
UNION ALL SELECT 490.6
UNION ALL SELECT 490.6
UNION ALL SELECT 485
UNION ALL SELECT 485
UNION ALL SELECT 489
UNION ALL SELECT 485
UNION ALL SELECT 477
UNION ALL SELECT 477
UNION ALL SELECT 484.6
UNION ALL SELECT 484.6
UNION ALL SELECT 484.6
UNION ALL SELECT 484.6
UNION ALL SELECT 485
UNION ALL SELECT 484.6
UNION ALL SELECT 484.6
UNION ALL SELECT 485
UNION ALL SELECT 485
UNION ALL SELECT 477
UNION ALL SELECT 484.6
UNION ALL SELECT 484.6
UNION ALL SELECT 484.6
UNION ALL SELECT 484.6
UNION ALL SELECT 484.6
UNION ALL SELECT 484.6
UNION ALL SELECT 482
UNION ALL SELECT 482
UNION ALL SELECT 482
)
SELECT STDEV(Val) FROM @Measurements
我猜我需要的可以通过使用 RollingValue 或 SSRS 中的某些存储过程来实现。当然,如果有更智能的方法来计算 Sigma 或 Cpk,我会很高兴听到它。
我希望这个问题得到很好的阐述,如果没有,请发表评论。这对我来说非常重要,所以我将不胜感激任何帮助:) 谢谢!
I have a serious problem with calculating Standard Deviation within subgroup in SSRS/SQl (whichever is more convenient). The real reason behind this is I need to calculate Sigma value (according to Six Sigma principles) or alternatively Cpk value (process capability), but my efforts stop at the standard deviation.
I'm not strong with statistics but it seems that StDev and StDevP functions in SSRS (and SQL) are not calculated 'within subgroup', and I cannot find a function that could do that. Below is an excel screen shot showing the calculation steps which I would like to achieve in SQL/SSRS
Edit: Cannot post images yet, please find below
The tricky part is calculating the sum of absolute differences between each pair of values. The order in which the values are given is significant. I forgot to mention that number 27 in denominator of Rbar (Row 7) is the sample size minus 1 (27). Below is also a table in SQL:
DECLARE @Measurements TABLE(Val FLOAT)
INSERT INTO @Measurements (Val)(
SELECT 485
UNION ALL SELECT 490.6
UNION ALL SELECT 490.6
UNION ALL SELECT 485
UNION ALL SELECT 485
UNION ALL SELECT 489
UNION ALL SELECT 485
UNION ALL SELECT 477
UNION ALL SELECT 477
UNION ALL SELECT 484.6
UNION ALL SELECT 484.6
UNION ALL SELECT 484.6
UNION ALL SELECT 484.6
UNION ALL SELECT 485
UNION ALL SELECT 484.6
UNION ALL SELECT 484.6
UNION ALL SELECT 485
UNION ALL SELECT 485
UNION ALL SELECT 477
UNION ALL SELECT 484.6
UNION ALL SELECT 484.6
UNION ALL SELECT 484.6
UNION ALL SELECT 484.6
UNION ALL SELECT 484.6
UNION ALL SELECT 484.6
UNION ALL SELECT 482
UNION ALL SELECT 482
UNION ALL SELECT 482
)
SELECT STDEV(Val) FROM @Measurements
I'm guessing that what I need could be achieved by using either RollingValue or some stored procedure in SSRS. Of course if there is a smarter way to calculate Sigma or Cpk I'll be very happy to hear about it.
I hope the question is well formulated, if not please comment. This is very important for me so I will be grateful for any assistance :) Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为这应该能解决问题?不确定 27 的分母或 d2 值是如何计算的,因此现在已将它们硬编码...
在使用此查询方面,保留行顺序很重要,因此我已将这些值放入临时表中使用标识列 - 如果您的值来自表并且有固定的排序条件,请改用 row_number() OVER(按 criteria_column 排序)
I think this should do the trick? Not sure how the denominator of 27 was calculated or the d2 value, so have hard coded them in for now...
In terms of using this query it is important to preserve the row order, so I have whacked the values into a temp table using an identity column - if your values are coming from a table and there is a fixed criteria for ordering, use
row_number() OVER (order by criteria_column)
instead您可以根据
SUM
和COUNT
聚合函数计算标准差:这不是最准确的方法,但很简单。
You can calculate the standard deviation in terms of the
SUM
andCOUNT
aggregate functions:Not the most accurate way, but it's easy.