This illustration examines monthly Shipments and New Orders from the Manufacturing, Shipments, and Inventories survey. (This is seasonally adjusted monthly data covering the sample period January 1992 to April 2020, downloaded July 21, 2020 (4:45 PM), U.S. Census Bureau, obtained from https://www.census.gov/mtis/index.html by selecting Non-Defense Capital Goods, and either Value of Shipments or New Orders.) Call this ndc for short. The data for New Orders is not available at January 1992, since this series starts at February 1992; so this value is entered as an NA. This is an example of ragged edge data.
This code installs and loads the packages, and loads the data into a variable named ndc.
library(devtools) library(Rcpp) devtools::install_github("tuckermcelroy/sigex") library(sigex)
start.date <- c(1992,1) end.date <- c(2020,5) period <- 12
dataALL.ts <- sigex.load(ndc,start.date,period, c("Shipments","NewOrders"),TRUE)
transform <- "none" aggregate <- FALSE subseries <- c(1,2) begin.date <- start(dataALL.ts) end.date <- end(dataALL.ts) range <- NULL data.ts <- sigex.prep(dataALL.ts,transform,aggregate,subseries,range,TRUE)
N <- dim(data.ts)[2] T <- dim(data.ts)[1]
ar.fit <- ar.yw(diff(ts(ndc[2:T,]))) p.order <- ar.fit$order
par.yw <- aperm(ar.fit$ar,c(2,3,1)) covmat.yw <- getGCD(ar.fit$var.pred,2)
var.out <- var2.par2pre(par.yw) psi.init <- as.vector(c(covmat.yw[[1]][2,1],log(covmat.yw[[2]]), var.out,colMeans(diff(ts(ndc[2:T,])))))
mdl <- NULL mdl <- sigex.add(mdl,seq(1,N),"varma",c(p.order,0),NULL,"process",c(1,-1))
mdl <- sigex.meaninit(mdl,data.ts,0)
constraint <- NULL psi.mle <- psi.init par.mle <- sigex.psi2par(psi.mle,mdl,data.ts)
fit.mle <- sigex.mlefit(data.ts,par.mle,constraint,mdl,"bfgs",debug=FALSE) psi.mle <- sigex.eta2psi(fit.mle[[1]]$par,constraint) hess <- fit.mle[[1]]$hessian par.mle <- fit.mle[[2]]
r sigex.lik(psi.mle,mdl,data.ts)
.print(round(psi.mle,digits=4))
resid.mle <- sigex.resid(psi.mle,mdl,data.ts)[[1]] resid.mle <- sigex.load(t(resid.mle),start(data.ts),frequency(data.ts), colnames(data.ts),TRUE) resid.acf <- acf(resid.mle,lag.max=4*period,plot=TRUE)$acf
log(sigex.conditions(data.ts,psi.mle,mdl))
sigex.portmanteau(resid.mle,4*period,length(psi.mle))
sigex.gausscheck(resid.mle)
print(eigen(hess)$values)
tstats <- sigex.tstats(mdl,psi.mle,hess,constraint) print(tstats)
analysis.mle <- sigex.bundle(data.ts,transform,mdl,psi.mle)
data.ts <- analysis.mle[[1]] mdl <- analysis.mle[[3]] psi <- analysis.mle[[4]] param <- sigex.psi2par(psi,mdl,data.ts)
window <- 50 data.casts <- sigex.midcast(psi,mdl,data.ts,window) extract.casts <- sigex.castextract(data.ts,data.casts,mdl,window,param)
castcol <- "black" fade <- 60 dataPad.ts <- rbind(matrix(NA,nrow=window,ncol=N),data.ts, matrix(NA,nrow=window,ncol=N)) par(mfrow=c(2,1)) for(i in 1:N) { plot(ts(dataPad.ts[,i],start=start.date,frequency=period), xlab="Year",ylab="",lwd=1,col=1, ylim=c(min(extract.casts[[3]][,i]),max(extract.casts[[2]][,i]))) sigex.graph(extract.casts,NULL,start.date,period,i,0,castcol,fade) }
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.