如何计算一个数值矢量中的异常值的数量
我将如何计算数值向量中的离群值的数量,在该数值向量中,将异常值定义为远离平均值超过3个标准偏差的数据点?
How would I count the number of outliers in a numerical vector where an outlier is defined as any datapoint that is more than 3 standard deviations away from the mean?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您的向量被称为
x
,则可以通过在
x
中的每个值和整个向量的平均值(abs(x--)中找到每个值之间的绝对距离(x-),可以做到这一点。平均(x))
),然后测试以下哪个值大于3 * SD(x)
。结果是true
和false
的逻辑向量,如果我们sum
IT,我们获得了true
的总数代码>向量中的值。例如:
在2022-06-01创建的 reprex package (v2.0.1)
If your vector is called
x
you can doThis works by finding the absolute distance between each value in
x
and the mean of the whole vector (abs(x - mean(x))
), then testing which of these values is greater than3 * sd(x)
. The result is a logical vector ofTRUE
andFALSE
, and if wesum
it, we get the total number ofTRUE
values in the vector.For example:
Created on 2022-06-01 by the reprex package (v2.0.1)