トレンド抽出 直線トレンド

Equation y_{t}=\alpha+\beta tR サンプルデータ:2003年4月から2014年2月までの日本のマネーストック(M3) m3japanm3japanfit m3japanresid
> library(tseries)

> ts.m3 <- ts(dataset$m3,start=c(2003,4),frequency=12)

> plot(ts.m3,main="M3.Japan.2003/4-2014/2",ylab="Trillion JPY")

> adf.test(ts.m3)

        Augmented Dickey-Fuller Test

data:  ts.m3
Dickey-Fuller = 0.2348, Lag order = 5, p-value = 0.99
alternative hypothesis: stationary

 警告メッセージ: 
In adf.test(ts.m3) : p-value greater than printed p-value

> adf.test(diff(ts.m3))

        Augmented Dickey-Fuller Test

data:  diff(ts.m3)
Dickey-Fuller = -5.1926, Lag order = 5, p-value = 0.01
alternative hypothesis: stationary

 警告メッセージ: 
In adf.test(diff(ts.m3)) : p-value smaller than printed p-value

> time <- seq(1,length(ts.m3))

> kaiki <- lm(ts.m3~time)

> summary(kaiki)

Call:
lm(formula = ts.m3 ~ time)

Residuals:
    Min      1Q  Median      3Q     Max 
-32.951 -17.148  -0.005  14.673  41.992 

Coefficients:
             Estimate Std. Error t value Pr(>|t|)    
(Intercept) 986.95369    3.25064  303.62   <2e-16 ***
time          1.14722    0.04273   26.84   <2e-16 ***
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 18.5 on 129 degrees of freedom
Multiple R-squared:  0.8482,    Adjusted R-squared:  0.847 
F-statistic: 720.7 on 1 and 129 DF,  p-value: < 2.2e-16

> m3.trend <- ts(kaiki$fitted,start=c(2003,4),frequency=12)

> summary(kaiki$fitted)
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
  988.1  1025.0  1063.0  1063.0  1100.0  1137.0 

> plot(ts.m3,main="M3.Japan.2003/4-2014/2",ylab="Trillion JPY",ylim=c(950,1200))

> par(new=T)

> plot(m3.trend,main="",ylab="",xlab="",ylim=c(950,1200),col=2)

> m3.resid <- ts(kaiki$resid,start=c(2003,4),frequency=12)

> plot(m3.resid,main="M3.Japan.Residuals.2003/4-2014/2",ylab="Trillion JPY",col=4)
> 

参考文献 田中孝文(2008).『Rによる時系列分析入門』.シーエーピー出版.393pp.アプリケーション R Core Team (2013). R: A language and environment for statistical computing. R Foundation for Statistical Computing, Vienna, Austria. URL http://www.R-project.org/.