本文介绍了计算加权平均值和标准差的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个时间序列x_0 ... x_t.我想计算数据的指数加权方差.那就是:

I have a time series x_0 ... x_t. I would like to compute the exponentially weighted variance of the data. That is:

V = SUM{w_i*(x_i - x_bar)^2, i=1 to T} where SUM{w_i} = 1 and x_bar=SUM{w_i*x_i}

ref: http://en.wikipedia.org/wiki/Weighted_mean#Weighted_sample_variance

目标是从根本上权衡那些可以使时间倒退得更短的观察结果.这实现起来非常简单,但是我想使用尽可能多的内置函数.有人知道R中对应什么吗?

The goal is to basically weight observations that are further back in time less. This is very simple to implement but I would like to use as much built in funcitonality as possible. Does anyone know what this corresponds to in R?

谢谢

推荐答案

R提供加权平均值.实际上,?weighted.mean显示了以下示例:

R provides weighted mean. In fact, ?weighted.mean shows this example:

 ## GPA from Siegel 1994
 wt <- c(5,  5,  4,  1)/15
 x <- c(3.7,3.3,3.5,2.8)
 xm <- weighted.mean(x, wt)

又一步:

v <- sum(wt * (x - xm)^2)

这篇关于计算加权平均值和标准差的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-26 10:27