打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
算法--样本方差、样本标准差、方差、标准方差与加权平均

样本方差与样本标准差

1、定义:样本中各数据与样本平均数的差的平方和的平均数叫做样本方差;样本方差的算术平方根叫做样本标准差。

注:样本方差和样本标准差都是衡量一个样本波动大小的量,样本方差或样本标准差越大,样本数据的波动就越大。

标准差与标准方差

1、定义:方差是各个数据与平均数之差的平方和的平均数。在概率论和数理统计中,方差用来度量随机变量和其数学期望(即均值)之间的偏离程度。标准差在概率统计中最常使用作为统计分布程度上的测量。标准差定义为方差的算术平方根,反映组内个体间的离散程度。

加权平均

1、定义:加权平均数(weighted average)是不同比重数据的平均数,就是把原始数据按照合理的比例来计算。

算法代码如下:

        public static double StandardDeviation(this IList<double> source)        {            if (source == null)            {                throw new ArgumentNullException("source");            }            if (source.Count == 0)            {                return double.NaN;            }            double variance = source.Variance();            return Math.Sqrt(variance);        }        public static double SampleStandardDeviation(this IList<double> source)        {            if (source == null)            {                throw new ArgumentNullException("source");            }            if (source.Count == 0 || source.Count == 1)            {                return double.NaN;            }            double variance = source.SampleVariance();            return Math.Sqrt(variance);        }        public static double Variance(this IList<double> source)        {            if (source == null)            {                throw new ArgumentNullException("source");            }            if (source.Count == 0)            {                return double.NaN;            }            int count = source.Count();            double deviation = CalculateDeviation(source, count);            return deviation / count;        }        public static double SampleVariance(this IList<double> source)        {            if (source == null)            {                throw new ArgumentNullException("source"); ;            }            if (source.Count == 0 || source.Count == 1)            {                return double.NaN;            }            int count = source.Count();            double deviation = CalculateDeviation(source, count);            return deviation / (count - 1);        }        public static double WeightedAverage(this IList<double> source, IList<double> factors)        {            if (source == null)            {                throw new ArgumentNullException("source");            }            if (source.Count != factors.Count)            {                throw new ArgumentException("source count is not equal to factors count.");            }            if (source.Count == 0)            {                return double.NaN;            }            double sum = factors.Sum();            if (sum == 0)            {                return double.NaN;            }            double weight = 0;            for (int index = 0; index < factors.Count; index++)            {                weight += source[index] * (factors[index] / sum);            }            return weight;        }        private static double CalculateDeviation(IList<double> source, int count)        {            double avg = source.Average();            double deviation = 0;            for (int index = 0; index < count; index++)            {                deviation += (source[index] - avg) * (source[index] - avg);            }            return deviation;        }
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
方差、标准差和协方差三者之间的定义与计算
学习PHP中统计扩展函数的使用
几个常用的统计概念
标准差(standard deviation)和标准误差(standard error)你能解释清楚吗?
Oracle SQL 內置函數大全
SPSS操作
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服