_ | 覦覈襦 | 豕蠏手 | 殊螳 | 譯殊碁
FrontPage › EWMA

ewma <- function(x, lambda=0.94){
  rs <- c()
  for(idx in 1:length(x)){
    if (idx == 1){
      rs <- c(x[idx])
    } else {
      rs <- c(rs, lambda * x[idx] + (1-lambda)*rs[idx-1])
    }
  }
  return(data.frame(idx, x, ewma=rs))
}

x <- c(100, 150, 120, 150)
ewma(x, lambda = 0.3)

蟆郁骸
> ewma(x, lambda = 0.3)
  idx   x   ewma
1   4 100 100.00
2   4 150 115.00
3   4 120 116.50
4   4 150 126.55



蠍 蠍郁鍵..
企: : るジ讓曙 襦螻豺 企Ν 譯殊語. 襦螻豺
EditText : Print : Mobile : FindPage : DeletePage : LikePages : Powered by MoniWiki : Last modified 2022-08-03 18:35:10

願 蟆 譬 譯殊 語 螳覃 旧願 蟆企. (S.襴曙)