| par(mfrow=c(2,2)) x <- read.table("iipcpimb4.csv",sep=",",skip=6) ts.x <-ts(x, start=c(2003,1),frequency=12) IIP <- ts.x[,10] plot(IIP)#2005.3=100 bunkai1 <- decompose(IIP,type="multiplicative");plot(bunkai1) y <- read.table("IIP78-.csv",sep=",",skip=6) ts.y <- ts(y, start=c(1978,1),frequency=12) plot(ts.y[,-1]) product <- ts.y[,2] ship <- ts.y[,3] stock <- ts.y[,4] n <- length(SHIP) rate_sp <- diff(log(ship),lag=12) rate_st <- diff(log(stock),lag=12) rate_sp;rate_st par(mfrow=c(2,1)) plot(rate_st);plot(rate_sp) a <- rate_sp[1:36] b <- rate_st[1:36] x_lbl <- "出荷指数の前年同月比" y_lbl <- "在庫指数の前年同月比" title <- "在庫循環の図" plot(a,b,type="o",main=title,xlab=x_lbl,ylab=y_lbl) arrows(a[1],b[1],a[2],b[2]) arrows(a[35],b[35],a[36],b[36]) abline(h=0,lty=2) abline(v=0,lty=2) |
・IIP原形の分析
p252,田中孝文[2008]が何故かうまくいかないためすこし改造。
|
x <- read.table("IIP_genkei78-07.csv",sep=",",skip=1) |
(一様上記文献と同じような図は導出・・・。2ヶ月分だけデータは多いので厳密には違うはず・・・。)
・要因の分解
トレンドと季節性を確認する。
| bunkai <- decompose(IIP,type="multiplicative");plot(bunkai) bunkai1 <- decompose(IIP1,type="multiplicative");plot(bunkai1) bunkai2 <- decompose(IIP2,type="multiplicative");plot(bunkai2) par(mfrow=c(2,2)) plot(bunkai1$trend) plot(bunkai2$trend) plot(bunkai1$seasonal) plot(bunkai2$seasonal) |
・3期間の比較
| x <- read.table("IIP_genkei78-07.csv",sep=",",skip=1) par(mfrow=c(2,2)) x1 <- x[1:155,] x2 <- x[156:360,] x3 <- x[156:289,] x4 <- x[290:360,] y <- x[,2] y1 <- x1[,2] y2 <- x2[,2] y3 <- x3[,2] y4 <- x4[,2] IIP1 <-ts(y1, start=c(1978,1),frequency=12) IIP2 <-ts(y2,start=c(1991,1),frequency=12) IIP3 <-ts(y3,start=c(1991,1),frequency=12) IIP4 <-ts(y4,start=c(2002,1),frequency=12) par(mfrow=c(2,2)) acf(IIP1,lag.max=60,main="acf of the IIP in 78-90") acf(IIP2,lag.max=60,main="acf of the IIP in 91-07") acf(IIP3,lag.max=60,main="acf of the IIP in 91-01") acf(IIP4,lag.max=60,main="acf of the IIP in 02-07") bunkai <- decompose(IIP,type="multiplicative");plot(bunkai) bunkai1 <- decompose(IIP1,type="multiplicative");plot(bunkai1) bunkai2 <- decompose(IIP2,type="multiplicative");plot(bunkai2) bunkai3 <- decompose(IIP3,type="multiplicative");plot(bunkai1) bunkai4 <- decompose(IIP4,type="multiplicative");plot(bunkai2) par(mfrow=c(2,2)) plot(bunkai1$trend) plot(bunkai2$trend) plot(bunkai3$trend) plot(bunkai4$trend) par(mfrow=c(2,2)) plot(bunkai1$seasonal) plot(bunkai2$seasonal) plot(bunkai3$seasonal) plot(bunkai4$seasonal) |
・周波数
| spectrum(IIP1) spectrum(IIP2) spectrum(IIP3) spectrum(IIP4) spec.ar(IIP1) spec.ar(IIP2) spec.ar(IIP3) spec.ar(IIP4) |
4章を参照にしトレンドを抽出
| xdata <- read.table("IIP_genkei78-07.csv",sep=",",skip=1) x <- xdata[,2] IIP <- ts(x,start=c(1978,1),frequency=12) IIP1 <- window(IIP, start=c(1978,1),end=c(1990,12),frequency=12) IIP2 <- window(IIP,start=c(1991,1),frequency=12) #setting a time time1 <- seq(1:length(IIP1)) time2 <- seq(1:length(IIP2)) # OLS for each period kaiki1 <- lm(IIP1~time1) kaiki2 <- lm(IIP2~time2) # setting a Trend in each period tr1 <- ts(kaiki1$fitted,start=c(1978,1),frequency=12) tr2 <- ts(kaiki2$fitted,start=c(1991,1),frequency=12) #setting a title or stm alike ttl <- "IIP and its 2 trend" hanrei <- c("1978-1990"," 1991-") # draw a ts.plot ts.plot(IIP,tr1,tr2,type="l",lty=c(1:3),main=ttl) legend(1995,70,legend=hanrei,lty=c(1:3),box.lty=0) |
4章のうちトレンドの後半を二分
| xdata <- read.table("IIP_genkei78-07.csv",sep=",",skip=1) x <- xdata[,2] IIP <- ts(x,start=c(1978,1),frequency=12) IIP1 <- window(IIP, start=c(1978,1),end=c(1990,12),frequency=12) IIP2 <- window(IIP,start=c(1991,1),end=c(2001,12),frequency=12) IIP3 <- window(IIP,start=c(2002,1),frequency=12) #setting a time time1 <- seq(1:length(IIP1)) time2 <- seq(1:length(IIP2)) time3 <- seq(1:length(IIP3)) # OLS for each period kaiki1 <- lm(IIP1~time1) kaiki2 <- lm(IIP2~time2) kaiki3 <- lm(IIP3~time3) # setting a Trend in each period tr1 <- ts(kaiki1$fitted,start=c(1978,1),frequency=12) tr2 <- ts(kaiki2$fitted,start=c(1991,1),frequency=12) tr3 <- ts(kaiki3$fitted,start=c(2002,1),frequency=12) #setting a title or stm alike ttl <- "IIP and its 3 trend" hanrei <- c("1978-1990","1991-2001","2002-") # draw a ts.plot ts.plot(IIP,tr1,tr2,tr3,type="l",lty=c(1:3),main=ttl) #hanreiがうまく反映されないのでコメントアウト #legend(1995,70,legend=hanrei,lty=c(1:3),box.lty=0) |