根から多項式を作る

  • こちらこちらで、ARIMAをやっている
  • ARIMAモデルでは、再帰フィルタを用いて、autocorrelation integratedを扱うが、その場合は、再帰度が上がるにつれ、数列発散が起きる
  • それを避けるために、再帰フィルタベクトルの値の大まかな制限が以下で与えられる
minroots <- min(Mod(polyroot(c(1, -model$ar))))
        if (minroots <= 1) 
            stop("'ar' part of model is not stationary")
  • なので、適当にARIMA用のフィルタを作りたいが、この条件はクリアして作りたい
  • 実根と複素根とをいくつ作るかを決め、複素根は共役ペアを根とし、そのうえで、最小絶対値を1以下にするように、根のリストを作り、その根リストから多項式係数を計算したい
library(polynom)
n.real.roots <- 10
nhalf.complex.roots <- 5 # conjugate pairs as roots


thetas <- runif(nhalf.complex.roots)*2*pi
# All mods should be more than 1
mods <- runif(n.real.roots+nhalf.complex.roots) * 5 + 1

#ss <- sample(c(-1,1),n.real.roots+nhalf.complex.roots,replace=TRUE)

mods.real <- mods[1:n.real.roots]
mods.complex <- mods[(1+n.real.roots):(n.real.roots+nhalf.complex.roots)]
roots.R <- mods.real
roots.C1 <- mods.complex * exp(1i*thetas)
roots.C2 <- mods.complex * exp(1i*(-thetas))
roots <- c(roots.R,roots.C1,roots.C2)
polynom <- poly.from.roots(roots)
polynom
ar <- (-polynom/polynom[1])[-1]
min(Mod(polyroot(c(1, -ar))))


x <- rnorm(1000)

x.. <- arima.sim(model=list(ar=ar),n=1000)

x. <- filter(x,ar,method="recursive")
par(mfcol=c(1,2))
plot(x.)
plot(x..)
par(mfcol=c(1,1))