2017-01-12 12 views
1

時系列モデルを実行しているときに問題があり、予測結果(C.I. 95%)は負の値です。それは意味をなさない。どの部分が間違っているのか分かりません。 plot.tsが後方に見えるので ので、私は、データセットの逆を作った:時系列推定が負の値R

week total_amount_by_week 
52  10000 
52  12000 
52  12300 
52  9800 
52  23400 
51 
51... 
. 
. 
. 
00  10000 
00  12930 

データセットは次のようになります。

order_ts1 <- ts(order_sum$Total_Amount_by_week,start = c(00),end =c(52)) 
order_ts1[] <-rev(order_ts1) 
plot.ts(order_ts1,col ='blue') 

次に、差異、ACF、およびPACFを計算しました。

order_tsdiff3 <-diff(order_ts1,differences=3) 
plot.ts(order_tsdiff3) # d=3 

# calcualate ACF 
acf(order_tsdiff3,lag.max=53) 
acf(order_tsdiff3,lag.max=53,plot=FALSE) 

# calculate PACF 
pacf(order_tsdiff3,lag.max=53) 
pacf(order_tsdiff3,lag.max=53,plot=FALSE) 

fit_ma <- arima(order_ts1, order = c(1, 3, 1)) 
fit_ma 

order_arimaforecast1 <- forecast.Arima(fit_ma,h=3,level=c(99.5)) 
order_arimaforecast1           

ので、プロットは次のようになります。 difference

ACF

PACF

だから私はいくつかの推定値を得るが、私はそれが負の値を起こるwrong.Whyそれはだと思いますか?

Call: 
arima(x = order_sumts1, order = c(1, 3, 1)) 

Coefficients: 
      ar1  ma1 
     -0.6673 -1.0000 
s.e. 0.1135 0.0539 

sigma^2 estimated as 84368661: log likelihood = -529.98, aic = 1065.96 

    Point Forecast Lo 99.5 Hi 99.5 
53  -1420.589 -27459.41 24618.23 
54  -7983.391 -51772.69 35805.91 
55  -21921.514 -93114.57 49271.54 

推定量はすべて正の値でなければなりません。

答えて

0

あなたはつまり、単に予想「A」を変換せずにこれらのステップを経る場合は、必ず正の値

## some sample data 
a<-ts(c, frequency = 5) 
## use ar() model with BoxCox() transform on the data & setting lambda = 0 (equivalent to taking the log) 
fit <- ar(BoxCox(a,lambda=0)) 
## compute forecast and set lambda to 0 so that a back-transform is done (since we transformed the original data set we now want to back transform it to the original scale) 
forecast(fit,h=3, lambda=0) 

    Point Forecast  Lo 80 Hi 80  Lo 95 Hi 95 
3.0  2.015135 1.1019547 3.685060 0.8005621 5.072398 
3.2  1.385040 0.6984705 2.746480 0.4861378 3.946073 
3.4  1.692792 0.8355244 3.429637 0.5749517 4.983975 

を取得し、あなたはしかし、変換、また、負の値を取得することを確認することを支援するための変換を使用してみてください上記の場合に役立ちます。あなたはあなたの特定のケースのために、このコードを適応させることができ

a<-ts(c, frequency = 5) 
## lambda = 1 means no transformation 
fit <- ar(BoxCox(a,lambda=1)) 
forecast(fit,h=3, lambda=1) 

    Point Forecast  Lo 80 Hi 80  Lo 95 Hi 95 
3.0   1.8 0.4764192 3.123581 -0.2242421 3.824242 
3.2   1.8 0.4764192 3.123581 -0.2242421 3.824242 
3.4   1.8 0.4764192 3.123581 -0.2242421 3.824242 

arima(x = BoxCox(order_sumts1, lambda=0), order = c(1, 3, 1)) 

は、それが役立つことを願って!

+0

ar()関数を実行しているときにエラーが発生しました:ar.ywのエラー(x、aic = aic、order.max = order.max、na.action = na.action、: が見つかりませんでした関数 "BoxCox" – Rya

+1

install.packages( "hdrcde")を実行してからライブラリ(hdrcde)を実行して再実行しようとするとうまくいけばうまくいきますか? – user3466328

+0

Yep.Itはうまく動作します。 – Rya