library(astsa) library(TSA) #1 data(deere3) m1.deere3=arima(deere3,order=c(1,0,0)) #AR(1) plot(m1.deere3, n.ahead=10,type='b',xlab='Time',ylab='Deere3') abline(h=coef(m1.deere3)[names(coef(m1.deere3))=='intercept']) predict(m1.deere3, n.ahead=10) #2 data(days) m1.days=arima(days,order=c(0,0,2)) #MA(2) plot(m1.days, n.ahead=10,type='b',xlab='Time',ylab='Duration') abline(h=coef(m1.days)[names(coef(m1.days))=='intercept']) predict(m1.days, n.ahead=10) days.adj=days; days.adj[c(63,106,129)]=35; m2.days=arima(days.adj,order=c(0,0,2)) plot(m2.days, n.ahead=10,type='b',xlab='Time',ylab='Duration') abline(h=coef(m2.days)[names(coef(m2.days))=='intercept']) predict(m2.days, n.ahead=10) #3 data(robot) m1.robot=arima(robot,order=c(0,1,1)) #IMA(1,1) plot(m1.robot, n1=315, n.ahead=5,type='b',xlab='Time',ylab='Robot') abline(h=coef(m1.robot)[names(coef(m1.robot))=='intercept']) predict(m1.robot, n.ahead=5) ### Note: the 'sarima.for' function will produce results like: sarima.for(robot, 5, 0,1,1) x11() m1.robot=arima(robot,order=c(1,0,1)) #ARMA(1,1) plot(m1.robot, n1=315, n.ahead=5,type='b',xlab='Time',ylab='Robot') abline(h=coef(m1.robot)[names(coef(m1.robot))=='intercept']) predict(m1.robot, n.ahead=5) #4 data(electricity) month.=season(electricity) # the period sign is included to make the printout from # the commands two lines below clearer model.s=lm(log(electricity)~time(electricity) + month.-1) # -1 removes the intercept term summary(model.s) #Predicted January 2006 logged value: 2.526e-02*2006-3.783e+01 #or equivalently: future.time<-2006 as.numeric( coef(model.s) %*% c(future.time,1,0,0,0,0,0,0,0,0,0,0,0) ) #Predicted Feb. 2006 logged value: 2.526e-02*2006.083-3.795e+01 #or equivalently: future.time<-2006.083 as.numeric( coef(model.s) %*% c(future.time,0,1,0,0,0,0,0,0,0,0,0,0) ) #Predicted March 2006 logged value: 2.526e-02*2006.167-3.792e+01 #or equivalently: future.time<-2006.167 as.numeric( coef(model.s) %*% c(future.time,0,0,1,0,0,0,0,0,0,0,0,0) ) #Predicted January 2006 value: exp(2.526e-02*2006-3.783e+01) #or equivalently: future.time<-2006 exp(as.numeric( coef(model.s) %*% c(future.time,1,0,0,0,0,0,0,0,0,0,0,0) )) #Predicted Feb. 2006 value: exp(2.526e-02*2006.083-3.795e+01) #or equivalently: future.time<-2006.083 exp(as.numeric( coef(model.s) %*% c(future.time,0,1,0,0,0,0,0,0,0,0,0,0) )) #Predicted March 2006 value: exp(2.526e-02*2006.167-3.792e+01) #or equivalently: future.time<-2006.167 exp(as.numeric( coef(model.s) %*% c(future.time,0,0,1,0,0,0,0,0,0,0,0,0) ))