データサイエンティスト上がりのDX参謀・起業家

データサイエンティスト上がりのDX参謀・起業家のブログ。データ分析や事業について。自身はアーティスト、経営者、事業家。

時系列分析に関するメモ

TokyoRの大仏様の発表資料より

http://www.slideshare.net/teramonagi/tokyo-r17-20110924ppt

  • frequency()関数で時系列の頻度を取得
  • window()関数で部分抽出
  • 時系列では共分散→自己共分散、相関係数→自己相関
    • 自己共分散は同一時系列のラグとの相関
    • ラグ(k)を固定して窓を動かしながら計算するイメージ
  • 相互共分散:「他の時系列」との共分散を計算する
# 相互共分散
ts.plot(mdeaths, fdeaths)
ccf(mdeaths, fdeaths)

# ピリオドグラム
rep<-5
t<-5
n<-100
x<-(rep*t)*(1:n)/n
y<-ts(cos(2*pi*x/t), start=1, frequency=(n/(rep*t)))
plot(y)
spec.pgram(y, log="no")

# ARIMAの探索
lh.ari.all <- apply(expand.grid(1:4, 0:1, 0:4), 1, function(x) arima(lh, order=x))
Reduce(function(x, y) if(x$aic < y$aic){x} else{y}, lh.ari.all)