2013-07-23 118 views
0

我會擬合一個SARIMAX模型,溫度作爲R中的外生變量。我可以使用功能嗎package TSA? 我想,以適應模型:R中的SARIMAX模型

fit1 = arima(x, order=c(p,d,q), seasonal=list(order=c(P,D,Q), period=S), xreg=temp)

是正確的還是我必須使用的R其他功能? 如果它不正確:我應該使用哪些步驟?

謝謝。

回答

1

時退房預測包,這是偉大的:

# some random data 
    x <- ts(rnorm(120,0,3) + 1:120 + 20*sin(2*pi*(1:120)/12), frequency=12) 
    temp = rnorm(length(x), 20, 30) 

    require(forecast) 
    # build the model (check ?auto.arima) 
    model = auto.arima(x, xreg = data.frame(temp = temp)) 

    # some random predictors 
    temp.reg = data.frame(temp = rnorm(10, 20, 30)) 

    # forecasting 
    forec = forecast(model, xreg = temp.reg) 

    # quick way to visualize things 
    plot(forec) 

    # model diagnosis 
    tsdiag(model) 

    # model info 
    summary(forec) 
+0

謝謝你的回答費爾南多。我會知道如果用'xreg'在'R'中適合一個外生變量是可能的,那麼我的「x」數據就是價格,並且我會將它與溫度相匹配。這種方法有可能嗎? – enk

0

我不會建議你使用auto.arima()。根據你想要的模型,它可能會返回不良結果,例如,當處理一些複雜的SARIMA模型時,手動完成的模型與auto.arima()之間的差異很明顯,auto.arima()甚至不會返回白噪聲創新(如預期的那樣),而手動配合當然也是如此。