R version 2.8.0 (2008-10-20) Copyright (C) 2008 The R Foundation for Statistical Computing ISBN 3-900051-07-0 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. > x <- c(14525.87 + ,14295.79 + ,13830.14 + ,14153.22 + ,15418.03 + ,16666.97 + ,16505.21 + ,17135.96 + ,18033.25 + ,17671 + ,17544.22 + ,17677.9 + ,18470.97 + ,18409.96 + ,18941.6 + ,19685.53 + ,19834.71 + ,19598.93 + ,17039.97 + ,16969.28 + ,16973.38 + ,16329.89 + ,16153.34 + ,15311.7 + ,14760.87 + ,14452.93 + ,13720.95 + ,13266.27 + ,12708.47 + ,13411.84 + ,13975.55 + ,12974.89 + ,12151.11 + ,11576.21 + ,9996.83 + ,10438.9 + ,10511.22 + ,10496.2 + ,10300.79 + ,9981.65 + ,11448.79 + ,11384.49 + ,11717.46 + ,10965.88 + ,10352.27 + ,9751.2 + ,9354.01 + ,8792.5 + ,8721.14 + ,8692.94 + ,8570.73 + ,8538.47 + ,8169.75 + ,7905.84 + ,8145.82 + ,8895.71 + ,9676.31 + ,9884.59 + ,10637.44 + ,10717.13 + ,10205.29 + ,10295.98 + ,10892.76 + ,10631.92 + ,11441.08 + ,11950.95 + ,11037.54 + ,11527.72 + ,11383.89 + ,10989.34 + ,11079.42 + ,11028.93 + ,10973 + ,11068.05 + ,11394.84 + ,11545.71 + ,11809.38 + ,11395.64 + ,11082.38 + ,11402.75 + ,11716.87 + ,12204.98 + ,12986.62 + ,13392.79 + ,14368.05 + ,15650.83 + ,16102.64 + ,16187.64 + ,16311.54 + ,17232.97 + ,16397.83 + ,14990.31 + ,15147.55 + ,15786.78 + ,15934.09 + ,16519.44 + ,16101.07 + ,16775.08 + ,17286.32 + ,17741.23 + ,17128.37 + ,17460.53 + ,17611.14 + ,18001.37 + ,17974.77 + ,16460.95 + ,16235.39 + ,16903.36 + ,15543.76 + ,15532.18 + ,13731.31 + ,13547.84 + ,12602.93 + ,13357.7 + ,13995.33 + ,14084.6 + ,13168.91 + ,12989.35 + ,12123.53 + ,9117.03 + ,8531.45) > par9 = '1' > par8 = '2' > par7 = '1' > par6 = '3' > par5 = '12' > par4 = '0' > par3 = '1' > par2 = '1' > par1 = 'FALSE' > #'GNU S' R Code compiled by R2WASP v. 1.0.44 () > #Author: Prof. Dr. P. Wessa > #To cite this work: AUTHOR(S), (YEAR), YOUR SOFTWARE TITLE (vNUMBER) in Free Statistics Software (v$_version), Office for Research Development and Education, URL http://www.wessa.net/rwasp_YOURPAGE.wasp/ > #Source of accompanying publication: Office for Research, Development, and Education > #Technical description: Write here your technical program description (don't use hard returns!) > library(lattice) > if (par1 == 'TRUE') par1 <- TRUE > if (par1 == 'FALSE') par1 <- FALSE > par2 <- as.numeric(par2) #Box-Cox lambda transformation parameter > par3 <- as.numeric(par3) #degree of non-seasonal differencing > par4 <- as.numeric(par4) #degree of seasonal differencing > par5 <- as.numeric(par5) #seasonal period > par6 <- as.numeric(par6) #degree (p) of the non-seasonal AR(p) polynomial > par7 <- as.numeric(par7) #degree (q) of the non-seasonal MA(q) polynomial > par8 <- as.numeric(par8) #degree (P) of the seasonal AR(P) polynomial > par9 <- as.numeric(par9) #degree (Q) of the seasonal MA(Q) polynomial > armaGR <- function(arima.out, names, n){ + try1 <- arima.out$coef + try2 <- sqrt(diag(arima.out$var.coef)) + try.data.frame <- data.frame(matrix(NA,ncol=4,nrow=length(names))) + dimnames(try.data.frame) <- list(names,c('coef','std','tstat','pv')) + try.data.frame[,1] <- try1 + for(i in 1:length(try2)) try.data.frame[which(rownames(try.data.frame)==names(try2)[i]),2] <- try2[i] + try.data.frame[,3] <- try.data.frame[,1] / try.data.frame[,2] + try.data.frame[,4] <- round((1-pt(abs(try.data.frame[,3]),df=n-(length(try2)+1)))*2,5) + vector <- rep(NA,length(names)) + vector[is.na(try.data.frame[,4])] <- 0 + maxi <- which.max(try.data.frame[,4]) + continue <- max(try.data.frame[,4],na.rm=TRUE) > .05 + vector[maxi] <- 0 + list(summary=try.data.frame,next.vector=vector,continue=continue) + } > arimaSelect <- function(series, order=c(13,0,0), seasonal=list(order=c(2,0,0),period=12), include.mean=F){ + nrc <- order[1]+order[3]+seasonal$order[1]+seasonal$order[3] + coeff <- matrix(NA, nrow=nrc*2, ncol=nrc) + pval <- matrix(NA, nrow=nrc*2, ncol=nrc) + mylist <- rep(list(NULL), nrc) + names <- NULL + if(order[1] > 0) names <- paste('ar',1:order[1],sep='') + if(order[3] > 0) names <- c( names , paste('ma',1:order[3],sep='') ) + if(seasonal$order[1] > 0) names <- c(names, paste('sar',1:seasonal$order[1],sep='')) + if(seasonal$order[3] > 0) names <- c(names, paste('sma',1:seasonal$order[3],sep='')) + arima.out <- arima(series, order=order, seasonal=seasonal, include.mean=include.mean, method='ML') + mylist[[1]] <- arima.out + last.arma <- armaGR(arima.out, names, length(series)) + mystop <- FALSE + i <- 1 + coeff[i,] <- last.arma[[1]][,1] + pval [i,] <- last.arma[[1]][,4] + i <- 2 + aic <- arima.out$aic + while(!mystop){ + mylist[[i]] <- arima.out + arima.out <- arima(series, order=order, seasonal=seasonal, include.mean=include.mean, method='ML', fixed=last.arma$next.vector) + aic <- c(aic, arima.out$aic) + last.arma <- armaGR(arima.out, names, length(series)) + mystop <- !last.arma$continue + coeff[i,] <- last.arma[[1]][,1] + pval [i,] <- last.arma[[1]][,4] + i <- i+1 + } + list(coeff, pval, mylist, aic=aic) + } > arimaSelectplot <- function(arimaSelect.out,noms,choix){ + noms <- names(arimaSelect.out[[3]][[1]]$coef) + coeff <- arimaSelect.out[[1]] + k <- min(which(is.na(coeff[,1])))-1 + coeff <- coeff[1:k,] + pval <- arimaSelect.out[[2]][1:k,] + aic <- arimaSelect.out$aic[1:k] + coeff[coeff==0] <- NA + n <- ncol(coeff) + if(missing(choix)) choix <- k + layout(matrix(c(1,1,1,2, + 3,3,3,2, + 3,3,3,4, + 5,6,7,7),nr=4), + widths=c(10,35,45,15), + heights=c(30,30,15,15)) + couleurs <- rainbow(75)[1:50]#(50) + ticks <- pretty(coeff) + par(mar=c(1,1,3,1)) + plot(aic,k:1-.5,type='o',pch=21,bg='blue',cex=2,axes=F,lty=2,xpd=NA) + points(aic[choix],k-choix+.5,pch=21,cex=4,bg=2,xpd=NA) + title('aic',line=2) + par(mar=c(3,0,0,0)) + plot(0,axes=F,xlab='',ylab='',xlim=range(ticks),ylim=c(.1,1)) + rect(xleft = min(ticks) + (0:49)/50*(max(ticks)-min(ticks)), + xright = min(ticks) + (1:50)/50*(max(ticks)-min(ticks)), + ytop = rep(1,50), + ybottom= rep(0,50),col=couleurs,border=NA) + axis(1,ticks) + rect(xleft=min(ticks),xright=max(ticks),ytop=1,ybottom=0) + text(mean(coeff,na.rm=T),.5,'coefficients',cex=2,font=2) + par(mar=c(1,1,3,1)) + image(1:n,1:k,t(coeff[k:1,]),axes=F,col=couleurs,zlim=range(ticks)) + for(i in 1:n) for(j in 1:k) if(!is.na(coeff[j,i])) { + if(pval[j,i]<.01) symb = 'green' + else if( (pval[j,i]<.05) & (pval[j,i]>=.01)) symb = 'orange' + else if( (pval[j,i]<.1) & (pval[j,i]>=.05)) symb = 'red' + else symb = 'black' + polygon(c(i+.5 ,i+.2 ,i+.5 ,i+.5), + c(k-j+0.5,k-j+0.5,k-j+0.8,k-j+0.5), + col=symb) + if(j==choix) { + rect(xleft=i-.5, + xright=i+.5, + ybottom=k-j+1.5, + ytop=k-j+.5, + lwd=4) + text(i, + k-j+1, + round(coeff[j,i],2), + cex=1.2, + font=2) + } + else{ + rect(xleft=i-.5,xright=i+.5,ybottom=k-j+1.5,ytop=k-j+.5) + text(i,k-j+1,round(coeff[j,i],2),cex=1.2,font=1) + } + } + axis(3,1:n,noms) + par(mar=c(0.5,0,0,0.5)) + plot(0,axes=F,xlab='',ylab='',type='n',xlim=c(0,8),ylim=c(-.2,.8)) + cols <- c('green','orange','red','black') + niv <- c('0','0.01','0.05','0.1') + for(i in 0:3){ + polygon(c(1+2*i ,1+2*i ,1+2*i-.5 ,1+2*i), + c(.4 ,.7 , .4 , .4), + col=cols[i+1]) + text(2*i,0.5,niv[i+1],cex=1.5) + } + text(8,.5,1,cex=1.5) + text(4,0,'p-value',cex=2) + box() + residus <- arimaSelect.out[[3]][[choix]]$res + par(mar=c(1,2,4,1)) + acf(residus,main='') + title('acf',line=.5) + par(mar=c(1,2,4,1)) + pacf(residus,main='') + title('pacf',line=.5) + par(mar=c(2,2,4,1)) + qqnorm(residus,main='') + title('qq-norm',line=.5) + qqline(residus) + residus + } > if (par2 == 0) x <- log(x) > if (par2 != 0) x <- x^par2 > (selection <- arimaSelect(x, order=c(par6,par3,par7), seasonal=list(order=c(par8,par4,par9), period=par5))) [[1]] [,1] [,2] [,3] [,4] [,5] [,6] [1,] 0.3216265 0.007472718 0.08578692 -0.1097228 0.3806248 -0.1520522 [2,] 0.3487185 0.000000000 0.08468200 -0.1365282 0.3798789 -0.1526795 [3,] 0.2176810 0.000000000 0.09553495 0.0000000 0.3986979 -0.1610027 [4,] 0.2247878 0.000000000 0.00000000 0.0000000 0.4000854 -0.1605904 [5,] 0.2296326 0.000000000 0.00000000 0.0000000 0.5454208 0.0000000 [6,] 0.2367714 0.000000000 0.00000000 0.0000000 0.0000000 0.0000000 [7,] 0.2344143 0.000000000 0.00000000 0.0000000 0.0000000 0.0000000 [8,] NA NA NA NA NA NA [9,] NA NA NA NA NA NA [10,] NA NA NA NA NA NA [11,] NA NA NA NA NA NA [12,] NA NA NA NA NA NA [13,] NA NA NA NA NA NA [14,] NA NA NA NA NA NA [,7] [1,] -0.49303804 [2,] -0.49196712 [3,] -0.50363582 [4,] -0.49651687 [5,] -0.68529262 [6,] -0.08746244 [7,] 0.00000000 [8,] NA [9,] NA [10,] NA [11,] NA [12,] NA [13,] NA [14,] NA [[2]] [,1] [,2] [,3] [,4] [,5] [,6] [,7] [1,] 0.71228 0.97227 0.43235 0.89999 0.22901 0.23772 0.10733 [2,] 0.40567 NA 0.42761 0.75354 0.22988 0.23019 0.10750 [3,] 0.01658 NA 0.32045 NA 0.18403 0.19381 0.08506 [4,] 0.01379 NA NA NA 0.18402 0.19319 0.08972 [5,] 0.01123 NA NA NA 0.05853 NA 0.00778 [6,] 0.00868 NA NA NA NA NA 0.48815 [7,] 0.00924 NA NA NA NA NA NA [8,] NA NA NA NA NA NA NA [9,] NA NA NA NA NA NA NA [10,] NA NA NA NA NA NA NA [11,] NA NA NA NA NA NA NA [12,] NA NA NA NA NA NA NA [13,] NA NA NA NA NA NA NA [14,] NA NA NA NA NA NA NA [[3]] [[3]][[1]] Call: arima(x = series, order = order, seasonal = seasonal, include.mean = include.mean, method = "ML") Coefficients: ar1 ar2 ar3 ma1 sar1 sar2 sma1 0.3216 0.0075 0.0858 -0.1097 0.3806 -0.1521 -0.4930 s.e. 0.8699 0.2145 0.1089 0.8711 0.3147 0.1281 0.3037 sigma^2 estimated as 461231: log likelihood = -953.5, aic = 1923 [[3]][[2]] Call: arima(x = series, order = order, seasonal = seasonal, include.mean = include.mean, method = "ML") Coefficients: ar1 ar2 ar3 ma1 sar1 sar2 sma1 0.3216 0.0075 0.0858 -0.1097 0.3806 -0.1521 -0.4930 s.e. 0.8699 0.2145 0.1089 0.8711 0.3147 0.1281 0.3037 sigma^2 estimated as 461231: log likelihood = -953.5, aic = 1923 [[3]][[3]] Call: arima(x = series, order = order, seasonal = seasonal, include.mean = include.mean, fixed = last.arma$next.vector, method = "ML") Coefficients: ar1 ar2 ar3 ma1 sar1 sar2 sma1 0.3487 0 0.0847 -0.1365 0.3799 -0.1527 -0.4920 s.e. 0.4178 0 0.1064 0.4338 0.3147 0.1266 0.3032 sigma^2 estimated as 461227: log likelihood = -953.5, aic = 1921 [[3]][[4]] Call: arima(x = series, order = order, seasonal = seasonal, include.mean = include.mean, fixed = last.arma$next.vector, method = "ML") Coefficients: ar1 ar2 ar3 ma1 sar1 sar2 sma1 0.2177 0 0.0955 0 0.3987 -0.1610 -0.5036 s.e. 0.0895 0 0.0957 0 0.2983 0.1232 0.2899 sigma^2 estimated as 461287: log likelihood = -953.55, aic = 1919.1 [[3]][[5]] Call: arima(x = series, order = order, seasonal = seasonal, include.mean = include.mean, fixed = last.arma$next.vector, method = "ML") Coefficients: ar1 ar2 ar3 ma1 sar1 sar2 sma1 0.2248 0 0 0 0.4001 -0.1606 -0.4965 s.e. 0.0899 0 0 0 0.2994 0.1227 0.2902 sigma^2 estimated as 465529: log likelihood = -954.05, aic = 1918.09 [[3]][[6]] Call: arima(x = series, order = order, seasonal = seasonal, include.mean = include.mean, fixed = last.arma$next.vector, method = "ML") Coefficients: ar1 ar2 ar3 ma1 sar1 sar2 sma1 0.2296 0 0 0 0.5454 0 -0.6853 s.e. 0.0891 0 0 0 0.2855 0 0.2530 sigma^2 estimated as 474294: log likelihood = -954.78, aic = 1917.56 [[3]][[7]] Call: arima(x = series, order = order, seasonal = seasonal, include.mean = include.mean, fixed = last.arma$next.vector, method = "ML") Coefficients: ar1 ar2 ar3 ma1 sar1 sar2 sma1 0.2368 0 0 0 0 0 -0.0875 s.e. 0.0887 0 0 0 0 0 0.1258 sigma^2 estimated as 483063: log likelihood = -955.62, aic = 1917.24 $aic [1] 1922.998 1921.000 1919.102 1918.093 1917.563 1917.243 1915.739 Warning messages: 1: In arima(series, order = order, seasonal = seasonal, include.mean = include.mean, : some AR parameters were fixed: setting transform.pars = FALSE 2: In arima(series, order = order, seasonal = seasonal, include.mean = include.mean, : some AR parameters were fixed: setting transform.pars = FALSE 3: In arima(series, order = order, seasonal = seasonal, include.mean = include.mean, : some AR parameters were fixed: setting transform.pars = FALSE 4: In arima(series, order = order, seasonal = seasonal, include.mean = include.mean, : some AR parameters were fixed: setting transform.pars = FALSE 5: In arima(series, order = order, seasonal = seasonal, include.mean = include.mean, : some AR parameters were fixed: setting transform.pars = FALSE 6: In arima(series, order = order, seasonal = seasonal, include.mean = include.mean, : some AR parameters were fixed: setting transform.pars = FALSE > postscript(file="/var/www/html/rcomp/tmp/1u2jq1229609210.ps",horizontal=F,pagecentre=F,paper="special",width=8.3333333333333,height=5.5555555555556) > resid <- arimaSelectplot(selection) > dev.off() null device 1 > resid Time Series: Start = 1 End = 121 Frequency = 1 [1] 14.52586 -222.69120 -409.60993 431.68461 1183.79466 945.85812 [7] -455.73426 666.50241 745.08801 -572.57600 -41.10294 162.02397 [13] 754.24033 -266.24565 510.38136 655.64642 76.18026 -188.68363 [19] -2542.76825 593.25353 85.75423 -694.32920 -27.77112 -785.70107 [25] -285.85575 -200.80596 -614.43058 -224.02525 -443.48197 818.93865 [31] 174.78180 -1082.24427 -579.35215 -440.57833 -1445.68868 747.30442 [37] -57.35070 -49.70625 -245.59328 -292.46629 1503.91521 -340.05042 [43] 363.48124 -925.07348 -486.32890 -494.31875 -381.31725 -402.10571 [49] 56.57347 -15.65142 -137.01324 -28.90398 -229.54566 -206.34929 [55] 334.25730 612.16041 560.51199 -19.77808 670.18432 -133.73249 [61] -525.76026 210.51016 563.32369 -404.66845 850.84283 300.23625 [67] -1004.89767 759.99040 -210.86685 -362.22501 242.11411 -83.51494 [73] -89.95969 126.70436 353.55455 38.10219 302.36509 -449.91012 [79] -303.18901 461.01162 219.82262 382.05429 687.24541 213.79559 [85] 871.22247 1062.94820 179.00714 -18.64317 130.22002 852.74379 [91] -1079.82592 -1169.46154 509.72670 635.41547 56.06678 569.17029 [97] -480.76489 866.03609 367.31011 332.23242 -709.18031 551.85077 [103] -22.48020 252.28590 -74.41336 -1451.94689 137.77301 771.15718 [109] -1559.80506 386.08002 -1766.00235 271.98236 -963.49620 1026.76387 [115] 456.95588 -39.63700 -943.33496 -89.74163 -811.25536 -2734.05130 [121] -10.15117 > postscript(file="/var/www/html/rcomp/tmp/2hduk1229609210.ps",horizontal=F,pagecentre=F,paper="special",width=8.3333333333333,height=5.5555555555556) > acf(resid,length(resid)/2, main='Residual Autocorrelation Function') > dev.off() null device 1 > postscript(file="/var/www/html/rcomp/tmp/3s0s11229609210.ps",horizontal=F,pagecentre=F,paper="special",width=8.3333333333333,height=5.5555555555556) > pacf(resid,length(resid)/2, main='Residual Partial Autocorrelation Function') > dev.off() null device 1 > postscript(file="/var/www/html/rcomp/tmp/41f141229609210.ps",horizontal=F,pagecentre=F,paper="special",width=8.3333333333333,height=5.5555555555556) > cpgram(resid, main='Residual Cumulative Periodogram') > dev.off() null device 1 > postscript(file="/var/www/html/rcomp/tmp/593pn1229609210.ps",horizontal=F,pagecentre=F,paper="special",width=8.3333333333333,height=5.5555555555556) > hist(resid, main='Residual Histogram', xlab='values of Residuals') > dev.off() null device 1 > postscript(file="/var/www/html/rcomp/tmp/6vw841229609210.ps",horizontal=F,pagecentre=F,paper="special",width=8.3333333333333,height=5.5555555555556) > densityplot(~resid,col='black',main='Residual Density Plot', xlab='values of Residuals') > dev.off() null device 1 > postscript(file="/var/www/html/rcomp/tmp/7dlxt1229609210.ps",horizontal=F,pagecentre=F,paper="special",width=8.3333333333333,height=5.5555555555556) > qqnorm(resid, main='Residual Normal Q-Q Plot') > qqline(resid) > dev.off() null device 1 > ncols <- length(selection[[1]][1,]) > nrows <- length(selection[[2]][,1])-1 > > #Note: the /var/www/html/rcomp/createtable file can be downloaded at http://www.wessa.net/cretab > load(file="/var/www/html/rcomp/createtable") > > a<-table.start() > a<-table.row.start(a) > a<-table.element(a,'ARIMA Parameter Estimation and Backward Selection', ncols+1,TRUE) > a<-table.row.end(a) > a<-table.row.start(a) > a<-table.element(a,'Iteration', header=TRUE) > for (i in 1:ncols) { + a<-table.element(a,names(selection[[3]][[1]]$coef)[i],header=TRUE) + } > a<-table.row.end(a) > for (j in 1:nrows) { + a<-table.row.start(a) + mydum <- 'Estimates (' + mydum <- paste(mydum,j) + mydum <- paste(mydum,')') + a<-table.element(a,mydum, header=TRUE) + for (i in 1:ncols) { + a<-table.element(a,round(selection[[1]][j,i],4)) + } + a<-table.row.end(a) + a<-table.row.start(a) + a<-table.element(a,'(p-val)', header=TRUE) + for (i in 1:ncols) { + mydum <- '(' + mydum <- paste(mydum,round(selection[[2]][j,i],4),sep='') + mydum <- paste(mydum,')') + a<-table.element(a,mydum) + } + a<-table.row.end(a) + } > a<-table.end(a) > table.save(a,file="/var/www/html/rcomp/tmp/8ytov1229609210.tab") > a<-table.start() > a<-table.row.start(a) > a<-table.element(a,'Estimated ARIMA Residuals', 1,TRUE) > a<-table.row.end(a) > a<-table.row.start(a) > a<-table.element(a,'Value', 1,TRUE) > a<-table.row.end(a) > for (i in (par4*par5+par3):length(resid)) { + a<-table.row.start(a) + a<-table.element(a,resid[i]) + a<-table.row.end(a) + } > a<-table.end(a) > table.save(a,file="/var/www/html/rcomp/tmp/9g60p1229609210.tab") > > system("convert tmp/1u2jq1229609210.ps tmp/1u2jq1229609210.png") > system("convert tmp/2hduk1229609210.ps tmp/2hduk1229609210.png") > system("convert tmp/3s0s11229609210.ps tmp/3s0s11229609210.png") > system("convert tmp/41f141229609210.ps tmp/41f141229609210.png") > system("convert tmp/593pn1229609210.ps tmp/593pn1229609210.png") > system("convert tmp/6vw841229609210.ps tmp/6vw841229609210.png") > system("convert tmp/7dlxt1229609210.ps tmp/7dlxt1229609210.png") > > > proc.time() user system elapsed 7.447 2.007 9.934