计算C#中的绝对绝对偏差 [英] Calculating Median Absolute Deviation in C#
本文介绍了计算C#中的绝对绝对偏差的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要对一个数字集执行许多统计计算,而我需要计算的内容之一是中位数绝对偏差.我提供了一个ISO标准,它告诉我的只是
I am required to perform a number of statistical calculations on a number set and one of the things I need to calculate is the Median Absolute Deviation. I was supplied with an ISO standard and all it tells me is
我不知道该如何处理该信息,因为我没有进行任何统计数学培训.因此,我无法将以上内容转换为C#函数.
I have no idea what to do with that info as I do not have any statistical math training. As such, I can't translate the above into a C# function.
推荐答案
中位数是 sorted 数组的 middl e元素(如果数组包含偶数项):
Median is a middle element of the sorted array (or average of two middle items if the array has even items):
double[] source = new double[] { 1, 2, 3, 4, 5 };
Array.Sort(source);
double med = source.Length % 2 == 0
? (source[source.Length / 2 - 1] + source[source.Length / 2]) / 2.0
: source[source.Length / 2];
double[] d = source
.Select(x => Math.Abs(x - med))
.OrderBy(x => x)
.ToArray();
double MADe = 1.483 * (d.Length % 2 == 0
? (d[d.Length / 2 - 1] + d[d.Length / 2]) / 2.0
: d[d.Length / 2]);
这篇关于计算C#中的绝对绝对偏差的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文