メインコンテンツへスキップ

季節性分析 stl()

    季節性分析を行う。

    オリジナルのデータはこんな感じ。

    > head(residuals(lm(apply.monthly(GASREGW,mean)["2011::"] ~ apply.monthly(UGA[,4],mean)["2011::"])),10)
    2011-01-31 2011-02-28 2011-03-28 2011-04-25 2011-05-30 2011-06-27 2011-07-25 2011-08-29 2011-09-26 2011-10-31
    0.04997214 0.09878477 0.24804900 0.31037087 0.51198263 0.36358058 0.19075916 0.31044009 0.29981563 0.14185942

    vectorに変換した上で、さらにtsに変換する。
    ts()を使用する際に日付データを周期とともに指定する。
    stl()を使用して、その結果をplot()で出力する。

    w <- residuals(lm(apply.monthly(GASREGW,mean)["2011::"] ~ apply.monthly(UGA[,4],mean)["2011::"])) %>% as.vector()
    plot(stl(ts(w,frequency=12,start=c(2011,1)),s.window="per", robust=TRUE)) # parameter "per" means "periodic".

    あなたへのおすすめ