【问题标题】:How to get the deviation to lower and higher values from mean如何从平均值获得更低和更高值的偏差
【发布时间】:2014-06-28 08:32:03
【问题描述】:

在 PHP(例如stats_standard_deviation())或 MySQL(STDDEV())中很容易获得标准差。由于标准偏差是在两个方向(较低和较高)均有效的平均值,因此无法比较两个方向之间的偏差。

所以我想知道是否有本地 PHP 或 MySQL 函数来获取这些值?

【问题讨论】:

    标签: php mysql statistics standard-deviation


    【解决方案1】:

    我建议手动进行计算:

    select avg(case when col > t.avg then col - t.avgcol end),
           avg(case when col < t.avg then t.avgcol - col end)
    from table t cross join
         (select avg(col) as avgcol) as tavg;
    

    这给出了平均值。如果您想要“方差”,只需将差异平方,将它们相加并取平方根:

    select sum(case when col > t.avg then (col - t.avgcol) * (col - t.avgcol) end) / sum(col > t.avg),
           sum(case when col < t.avg then (col - t.avgcol) * (col - t.avgcol) end) / sum(col > t.avg)
    from table t cross join
         (select avg(col) as avgcol) as tavg;
    

    我怀疑您正在学习将这些概念应用于真实数据。您可能有兴趣了解统计偏差,它提供了另一种衡量平均值“居中”程度的方法。一个好的起点是Wikipedia

    【讨论】:

    • 谢谢,这是一个有趣的方法!
    猜你喜欢
    • 2021-02-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-04
    • 2014-09-07
    • 1970-01-01
    • 1970-01-01
    • 2012-03-18
    相关资源
    最近更新 更多