gpt4 book ai didi

php - 如何从均值获得较低和较高值的偏差

转载 作者:行者123 更新时间:2023-11-29 06:37:31 24 4
gpt4 key购买 nike

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

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

最佳答案

我建议手动进行计算:

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 .

关于php - 如何从均值获得较低和较高值的偏差,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23584297/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com