This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.
When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
summary(cars)
## speed dist
## Min. : 4.0 Min. : 2.00
## 1st Qu.:12.0 1st Qu.: 26.00
## Median :15.0 Median : 36.00
## Mean :15.4 Mean : 42.98
## 3rd Qu.:19.0 3rd Qu.: 56.00
## Max. :25.0 Max. :120.00
You can also embed plots, for example:
Note that the echo = FALSE
parameter was added to the code chunk to prevent printing of the R code that generated the plot.
…{r} #download data
install.packages(“Quandl”)
library(“Quandl”) …
…{r} #(1) data identification
hou <- Quandl(“FRED/HOUSTNSA”, type=“zoo”)
summary(hou)
plot(hou)
str(hou)
head(hou)
tail(hou) …
…{r} # split sample into two parts - estimation sample and prediction sample y <- hou y1 <- window(y,end=c(2012,12)) y2 <- window(y,start=c(2013,1)) # first part used to identify and estimate the model y <- y1 # log, log-change, seasonal log change ly <- log(y) dly1 <- diff(ly) dly12 <- diff(ly,12) dly12_1 <- diff(diff(ly),12) …
…{r}
par(mfrow=c(2,3)) plot(y, main=expression(y)) plot(ly, main=expression(log(y))) plot.new
plot(dly,main=expression(paste(Delta,“log(y)”))) plot(dly12,main=expression(paste(Delta[12],“log(y)”))) plot(dly12_1,main=expression(paste(Delta,Delta[12],“log(y)”)))
…
library(zoo)
maxlag <-36
par(mfrow=c(2,2)) …{r}
plot(acf(coredata(ly), type=‘correlation’, lag=maxlag, plot=FALSE), ylab=“”, main=expression(paste(“ACF for log(y)”)))
acf(coredata(dly),type=“correlation”,lag=maxlag,ylab=“”,main=expression(paste(Delta,“log (y)-ACF”)))
acf(coredata(dly12),type=“correlation”,lag=maxlag,ylab=“”,main=expression(paste(Delta[12],“log (y)-ACF”)))
acf(coredata(dly12_1),type=“correlation”,lag=maxlag,ylab=“”,main=expression(paste(Delta, Delta[12],“log (y)-ACF”)))
acf(coredata(ly),type=“partial”,lag=maxlag,ylab=“”,main=“PACF-log y”)
acf(coredata(dly),type=“partial”,lag=maxlag,ylab=“”,main=“PACF-delta,log y”)
acf(coredata(dly12),type=“partial”,lag=maxlag,ylab=“”,main=“PACF-delta[12],log y”)
acf(coredata(dly12_1),type=“partial”,lag=maxlag,ylab=“”,main=“PACF-delta[12],log y”) …
…{r}
m1 <- arima(dly12_1,order=c(2,0,0),seasonal=list(order=c(0,0,1),period=12)) m1
…
…{r} #Check model m1 for adequacy tsdiag(m1,gof.lag=36)
BIC(m1) AIC(m1)
m2<-arima(dly,order=c(0,0,3),seasonal = list(order=c(0,1,1),period=12)) m2 tsdiag(m2,gof.lag=36) BIC(m2) AIC(m2)
```
…{r} m3<-arima(ly,order=c(0,1,3),seasonal =list(order=c(0,1,1),period=12)) m3 tsdiag(m3,gof.lag=36) BIC(m3) AIC(m3)
…