options(windowsBuffered=FALSE) y=scan('F:/Math355/SPIRITS.txt',skip=2,nline=4) yts=ts(log(y)) plot(yts,main="Log Quarterly Sales of Alcoholic Spirits",type='b',col=2) n=length(y) time=seq(1:n) quarter=c(rep(seq(1:4),10)) quarter fquarter=as.factor(quarter) ymod1=lm(yts~time+fquarter) summary(ymod1) yfit1=ymod1$fitted lines(yfit1,col=3) yres1=ymod1$res plot(yres1) ymod2=lm(y~time+cos(2*pi*time/4)+sin(2*pi*time/4)) summary(ymod2) yfit2=ymod2$fitted plot(yts,main="Quarterly Sales of Alcoholic Spirits in Log Transcations",type='p',col=2) lines(yfit2,col=4) ymod3=lm(y~time+cos(2*pi*time/4)+sin(2*pi*time/4)+cos(2*pi*time/2)+sin(2*pi*time/2)) summary(ymod3) yfit3=ymod3$fitted plot(yts,main="Quarterly Sales of Alcoholic Spirits in Log Transcations",type='p',col=2) lines(yfit2,col=4) ymod3=lm(y~time+cos(2*pi*time/4)+sin(2*pi*time/4)+cos(2*pi*time/1)+sin(2*pi*time/1)) summary(ymod3) yfit3=ymod3$fitted plot(yts,main="Quarterly Sales of Alcoholic Spirits in Log Transcations",type='p',col=2) lines(yfit2,col=4) yspec=spec.pgram(yts,pad=4,detrend=TRUE) plot(yspec$freq,yspec$spec,type='l',col=5) resspec=spec.pgram(ymod3$res,pad=4,detrend=FALSE) plot(resspec$freq,resspec$spec,type='l',col=5) acf(ymod3$res,lag.max=20,col=6) pacf(ymod3$res,lag.max=20,col=6)