R Program Knowledge NEEDED!!! Sample Reports In Files!! The data can be downloaded from FRED. Consider whether there exist trend, seasonality, and cycles. You can also consider the piecewise estimation and forecast. Give a detailed discussion of your model and implementation. Form both the point forecasts and interval forecasts. Keep some observations as a holdout sample to examine the out of sample forecasting performance. Write a comprehensive report.
##Packages
library(forecast)
library(plotrix)
##Liquor Salesliquor=read.csv(“DataLiquor.csv”,header=TRUE)liquor=na.omit(liquor)names(liquor)[1] <- “liquor”lsts=ts(data=liquor,start=c(1987,1),frequency=12) #pdf(file=”Liquor Sales.pdf”,height=6,width=7.5)plot(lsts,axes=FALSE,xlim=c(1988-1/12,2014),ylim=c(0,3000),xlab=”Time”,ylab=”Liquor Sales”,col=”blue”)box()axis(side=1,at=1987:2014,lab=c(1987:2014),cex.axis=0.7)axis(side=2,at=c(0,500,1000,1500,2000,2500,3000),lab=c(0,500,1000,1500,2000,2500,3000),cex.axis=0.75)#dev.off() ##Log Liquor Saleslogliquor=log(liquor)names(logliquor)[1] <- “logliquor”loglsts=ts(data=logliquor,start=c(1987,1),frequency=12) #pdf(file=”Log Liquor Sales.pdf”,height=6,width=7.5)plot(loglsts,axes=FALSE,xlim=c(1988-1/12,2014),ylim=c(6.0,8.0),xlab=”Time”,ylab=”Log Liquor Sales”,col=”blue”)box()axis(side=1,at=1987:2014,lab=c(1987:2014),cex.axis=0.7)axis(side=2,at=c(6.0,6.4,6.8,7.2,7.6,8.0),lab=c(6.0,6.4,6.8,7.2,7.6,8.0),cex.axis=0.9)#dev.off() ##Linear Trend Estimationtime=data.frame(c(1:336))names(time)[1] <- “time”logls=data.frame(time,logliquor)linear.mod=lm(logliquor~time,data=logls) print(summary(linear.mod)) ##Residual Plot, Linear Trend Estimationlogls.act=logls$logliquorlogls.pred=predict(linear.mod,logls)logls.resid=logls.act-logls.predlogls.resid.plot=1.5*logls.resid+5.8 #pdf(file=”Residual Plot, Linear Trend Estimation.pdf”,height=6,width=7.5)plot(logls.act,type=”l”,axes=FALSE,ylim=c(5.2,8.0),xlab=””,ylab=””)lines(logls.pred,col=”red”,lty=2)lines(logls.resid.plot,col=”blue”)abline(h=5.8,col=”black”)abline(h=6.0,col=”black”,lty=”dashed”)abline(h=5.6,col=”black”,lty=”dashed”) box()axis(side=1,at=c(seq(1,336,by=12)),lab=c(1987:2014),cex.axis=0.7)axis(side=2,at=c(5.2,5.5,5.8,6.1,6.4,6.7),lab=c(-0.4,-0.2,0,0.2,0.4,0.6),cex.axis=0.7)axis(side=4,at=c(6.0,6.5,7.0,7.5,8.0),lab=c(6.0,6.5,7.0,7.5,8.0),cex.axis=0.9)axis.break(axis=4,breakpos=5.91) legend(1,7.99,c(“Residual”,”Actual”,”Fitted”),lty=c(1,1),col=c(“blue”,”black”,”red”),cex=0.75)#dev.off() ##Linear Trend Estimation with Seasonal Dummiesmond=seasonaldummy(loglsts)Dec=matrix(data=rep(c(rep(0,11),1),28),nrow=336,ncol=1)logls.seas=data.frame(cbind(logliquor,time,mond,Dec))linear.seas.mod=lm(logliquor~.-1,data=logls.seas) print(summary(linear.seas.mod)) ##Residual Plot, Linear Trend Estimation with Seasonal Dummieslogls.seas.act=logls.seas$logliquorlogls.seas.pred=predict(linear.seas.mod,logls.seas)logls.seas.resid=logls.seas.act-logls.seas.predlogls.seas.resid.plot=6.0*logls.seas.resid+5.8 #pdf(file=”Residual Plot, Linear Trend Estimation with Seasonal Dummies.pdf”,height=6,width=7.5)plot(logls.seas.act,type=”l”,axes=FALSE,ylim=c(4.9,8.0),xlab=””,ylab=””)lines(logls.seas.pred,col=”red”,lty=2)lines(logls.seas.resid.plot,col=”blue”)abline(h=5.8,col=”black”)abline(h=6.45,col=”black”,lty=”dashed”)abline(h=5.15,col=”black”,lty=”dashed”) box()axis(side=1,at=c(seq(1,336,by=12)),lab=c(1987:2014),cex.axis=0.7)axis(side=2,at=c(4.9,5.2,5.5,5.8,6.1,6.4,6.7),lab=c(-0.15,-0.10,-0.05,0,0.05,0.10,0.15),cex.axis=0.7)axis(side=4,at=c(6.0,6.5,7.0,7.5,8.0),lab=c(6.0,6.5,7.0,7.5,8.0),cex.axis=0.9)axis.break(axis=4,breakpos=5.91) legend(1,7.99,c(“Residual”,”Actual”,”Fitted”),lty=c(1,1),col=c(“blue”,”black”,”red”),cex=0.75)#dev.off() ##Seasonal Patternmoncoef=data.frame(coef(linear.seas.mod))moncoef <- moncoef[-1,] #pdf(file=”Seasonal Pattern.pdf”,height=6,width=7.5)plot(moncoef,type=”l”,axes=FALSE,xlab=”Estimated Seasonal Factors”,ylab=”Factor”,col=”blue”)box()axis(side=1,at=c(1:12),lab=c(paste(“M”,1:12)),cex.axis=0.75)axis(side=2,at=c(6.3,6.4,6.5,6.6,6.7,6.8,6.9),lab=c(6.3,6.4,6.5,6.6,6.7,6.8,6.9),cex.axis=1)#dev.off() ##Log-Quadratic Trend Estimationquad.mod=lm(logliquor~time+I(time^2),data=logls) print(summary(quad.mod)) ##Residual Plot, Log-Quadratic Trend Estimationlogqls.act=logls$logliquorlogqls.pred=predict(quad.mod,logls)logqls.resid=logqls.act-logqls.predlogqls.resid.plot=1.5*logqls.resid+5.5 #pdf(file=”Residual Plot, Log-Quadratic Trend Estimation.pdf”,height=6,width=7.5)plot(logqls.act,type=”l”,axes=FALSE,ylim=c(4.9,8.0),xlab=””,ylab=””)lines(logqls.pred,col=”red”,lty=2)lines(logqls.resid.plot,col=”blue”)abline(h=5.5,col=”black”)abline(h=5.7,col=”black”,lty=”dashed”)abline(h=5.3,col=”black”,lty=”dashed”) box()axis(side=1,at=c(seq(1,336,by=12)),lab=c(1987:2014),cex.axis=0.7)axis(side=2,at=c(4.9,5.2,5.5,5.8,6.1,6.4),lab=c(-0.4,-0.2,0,0.2,0.4,0.6),cex.axis=0.7)axis(side=4,at=c(6.0,6.5,7.0,7.5,8.0),lab=c(6.0,6.5,7.0,7.5,8.0),cex.axis=0.9)axis.break(axis=4,breakpos=5.85) legend(1,7.99,c(“Residual”,”Actual”,”Fitted”),lty=c(1,1),col=c(“blue”,”black”,”red”),cex=0.75)#dev.off() ##Log-Quadratic Trend Estimation with Seasonal Dummieslogqls.seas=data.frame(cbind(logliquor,time,I(time^2),mond,Dec))quad.seas.mod=lm(logliquor~.-1,data=logqls.seas) print(summary(quad.seas.mod)) ##Residual Plot, Log-Quadratic Trend Estimation with Seasonal Dummieslogqls.seas.act=logls.seas$logliquorlogqls.seas.pred=predict(quad.seas.mod,logqls.seas)logqls.seas.resid=logqls.seas.act-logqls.seas.predlogqls.seas.resid.plot=7*logqls.seas.resid+5.55 #pdf(file=”Residual Plot, Log-Quadratic Trend Estimation with Seasonal Dummies.pdf”,height=6,width=7.5)plot(logqls.seas.act,type=”l”,axes=FALSE,ylim=c(4.5,8.0),xlab=””,ylab=””)lines(logqls.seas.pred,col=”red”,lty=2)lines(logqls.seas.resid.plot,col=”blue”)abline(h=5.55,col=”black”)abline(h=5.9,col=”black”,lty=”dashed”)abline(h=5.2,col=”black”,lty=”dashed”) box()axis(side=1,at=c(seq(1,336,by=12)),lab=c(1987:2014),cex.axis=0.7)axis(side=2,at=c(4.5,4.85,5.2,5.55,5.9,6.25,6.6),lab=c(-0.15,-0.10,-0.05,0,0.05,0.10,0.15),cex.axis=0.7)axis(side=4,at=c(6.0,6.5,7.0,7.5,8.0),lab=c(6.0,6.5,7.0,7.5,8.0),cex.axis=0.9)axis.break(axis=4,breakpos=5.8) legend(1,7.99,c(“Residual”,”Actual”,”Fitted”),lty=c(1,1),col=c(“blue”,”black”,”red”),cex=0.75)#dev.off() ##Scatterplot of e_t against e_t-1logqls.seas.resid.l1 <- as.vector(NULL)logqls.seas.resid.l1[1] <- 0obs <- length(logqls.seas.resid)i=0for (i in 2:obs) { logqls.seas.resid.l1[i] <- logqls.seas.resid[i-1]} #pdf(file=”Scatterplot of e_t against e_t-1.pdf”)plot(logqls.seas.resid.l1,logqls.seas.resid,axes=FALSE,cex=0.8,xlim=c(-0.12,0.16),ylim=c(-0.12,0.16),col=”blue”,xlab=”RESIDL1″,ylab=”RESID”)box()axis(side=1,at=c(seq(-0.12,0.16,by=0.04)),lab=c(seq(-0.12,0.16,by=0.04)))axis(side=2,at=c(seq(-0.12,0.16,by=0.04)),lab=c(seq(-0.12,0.16,by=0.04)))#dev.off() ##The Durbin-Watson Test – AR(1) Disturbancelogqls.seas.ar1=data.frame(cbind(logqls.seas[,-1],logqls.seas.resid.l1))names(logqls.seas.ar1) <- c(“TIME”,”TIME2″,names(logqls.seas.ar1)[3:14],”RESID(-1)”)quad.seas.ar1.mod=lm(logqls.seas.resid~.-1,data=logqls.seas.ar1) print(summary(quad.seas.ar1.mod)) ##The Breusch-Godfrey Test – AR(4) Disturbancelogqls.seas.resid.l <- matrix(NA,nrow=obs,ncol=8)l=0for (l in 1:8) { for (i in 1:l) { logqls.seas.resid.l[i,l] <- 0 }}l=0for (l in 1:8) { for (i in (1+l):obs) { logqls.seas.resid.l[i,l] <- logqls.seas.resid[i-l] }} names.resid <- as.vector(NULL)i=0for (i in 1:8) { names.resid[i] <- paste(“RESID(-“,toString(i),”)”,sep=””)} logqls.seas.ar4=data.frame(cbind(logqls.seas[,-1],logqls.seas.resid.l[,1:4]))names(logqls.seas.ar4) <- c(“TIME”,”TIME2″,names(logqls.seas.ar4)[3:14],names.resid[1:4])quad.seas.ar4.mod=lm(logqls.seas.resid~.-1,data=logqls.seas.ar4) print(summary(quad.seas.ar4.mod)) ##The Breusch-Godfrey Test – AR(8) Disturbancelogqls.seas.ar8=data.frame(cbind(logqls.seas[,-1],logqls.seas.resid.l))names(logqls.seas.ar8) <- c(“TIME”,”TIME2″,names(logqls.seas.ar8)[3:14],names.resid)quad.seas.ar8.mod=lm(logqls.seas.resid~.-1,data=logqls.seas.ar8) print(summary(quad.seas.ar8.mod)) ##Regression with Serially-Correlated Disturbanceslogqls.seas.resid.acf <- acf(logqls.seas.resid,type=”correlation”,plot=FALSE)[1:obs]logqls.seas.resid.pacf <- pacf(logqls.seas.resid,plot=FALSE) #pdf(file=”Correlogram of Residuals_Autocorrelation.pdf”,height=6,width=7.5)plot(logqls.seas.resid.acf,col=”blue”,xlab=”Lag”,ylab=”Autocorrelation”,main=””)
Science is the pursuit and application of knowledge and understanding of the natural and social…
Clearly stating the definition, the values, the meaning of such values and the type of…
All answered must be typed using Times New Roman (size 12, double-spaced) font. No pictures…
All answered must be typed using Times New Roman (size 12, double-spaced) font. No pictures…
https://www.npr.org/sections/ed/2018/04/25/605092520/high-paying-trade-jobs-sit-empty-while-high-school-grads-line-up-for-university Click on the link above. Read the entire link and answer the questions below…
All answered must be typed using Times New Roman (size 12, double-spaced) font. No pictures…