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(9005.73 + ,9018.68 + ,9349.44 + ,9327.78 + ,9753.63 + ,10443.5 + ,10853.87 + ,10704.02 + ,11052.23 + ,10935.47 + ,10714.03 + ,10394.48 + ,10817.9 + ,11251.2 + ,11281.26 + ,10539.68 + ,10483.39 + ,10947.43 + ,10580.27 + ,10582.92 + ,10654.41 + ,11014.51 + ,10967.87 + ,10433.56 + ,10665.78 + ,10666.71 + ,10682.74 + ,10777.22 + ,10052.6 + ,10213.97 + ,10546.82 + ,10767.2 + ,10444.5 + ,10314.68 + ,9042.56 + ,9220.75 + ,9721.84 + ,9978.53 + ,9923.81 + ,9892.56 + ,10500.98 + ,10179.35 + ,10080.48 + ,9492.44 + ,8616.49 + ,8685.4 + ,8160.67 + ,8048.1 + ,8641.21 + ,8526.63 + ,8474.21 + ,7916.13 + ,7977.64 + ,8334.59 + ,8623.36 + ,9098.03 + ,9154.34 + ,9284.73 + ,9492.49 + ,9682.35 + ,9762.12 + ,10124.63 + ,10540.05 + ,10601.61 + ,10323.73 + ,10418.4 + ,10092.96 + ,10364.91 + ,10152.09 + ,10032.8 + ,10204.59 + ,10001.6 + ,10411.75 + ,10673.38 + ,10539.51 + ,10723.78 + ,10682.06 + ,10283.19 + ,10377.18 + ,10486.64 + ,10545.38 + ,10554.27 + ,10532.54 + ,10324.31 + ,10695.25 + ,10827.81 + ,10872.48 + ,10971.19 + ,11145.65 + ,11234.68 + ,11333.88 + ,10997.97 + ,11036.89 + ,11257.35 + ,11533.59 + ,11963.12 + ,12185.15 + ,12377.62 + ,12512.89 + ,12631.48 + ,12268.53 + ,12754.8 + ,13407.75 + ,13480.21 + ,13673.28 + ,13239.71 + ,13557.69 + ,13901.28 + ,13200.58 + ,13406.97 + ,12538.12 + ,12419.57 + ,12193.88 + ,12656.63 + ,12812.48 + ,12056.67 + ,11322.38 + ,11530.75 + ,11114.08 + ,9181.73 + ,8614.55) > 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.9162276 -0.21393610 0.1496971 -0.7512359 -0.1713651 -0.10273096 [2,] 0.9154817 -0.21349890 0.1505793 -0.7511928 0.0000000 -0.10192493 [3,] 0.9170418 -0.21303014 0.1507668 -0.7544920 0.0000000 -0.09959548 [4,] 0.8992844 -0.18562664 0.1452049 -0.7465213 0.0000000 0.00000000 [5,] -0.7814857 0.09579275 0.0000000 0.9746236 0.0000000 0.00000000 [6,] -0.8467336 0.00000000 0.0000000 0.9636674 0.0000000 0.00000000 [7,] NA NA NA NA NA NA [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.20137466 [2,] 0.03535239 [3,] 0.00000000 [4,] 0.00000000 [5,] 0.00000000 [6,] 0.00000000 [7,] NA [8,] NA [9,] NA [10,] NA [11,] NA [12,] NA [13,] NA [14,] NA [[2]] [,1] [,2] [,3] [,4] [,5] [,6] [,7] [1,] 4e-05 0.11352 0.14315 0.00028 0.71229 0.39409 0.65891 [2,] 4e-05 0.11463 0.14117 0.00025 NA 0.38993 0.74564 [3,] 3e-05 0.11479 0.14038 0.00018 NA 0.40057 NA [4,] 3e-05 0.15415 0.15930 0.00014 NA NA NA [5,] 0e+00 0.31509 NA 0.00000 NA NA NA [6,] 0e+00 NA NA 0.00000 NA NA NA [7,] NA 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.9162 -0.2139 0.1497 -0.7512 -0.1714 -0.1027 0.2014 s.e. 0.2156 0.1341 0.1015 0.2002 0.4635 0.1201 0.4550 sigma^2 estimated as 150894: log likelihood = -885.95, aic = 1787.91 [[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.9162 -0.2139 0.1497 -0.7512 -0.1714 -0.1027 0.2014 s.e. 0.2156 0.1341 0.1015 0.2002 0.4635 0.1201 0.4550 sigma^2 estimated as 150894: log likelihood = -885.95, aic = 1787.91 [[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.9155 -0.2135 0.1506 -0.7512 0 -0.1019 0.0354 s.e. 0.2144 0.1343 0.1016 0.1988 0 0.1181 0.1087 sigma^2 estimated as 151074: log likelihood = -886.01, aic = 1786.01 [[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.9170 -0.2130 0.1508 -0.7545 0 -0.0996 0 s.e. 0.2111 0.1341 0.1016 0.1948 0 0.1180 0 sigma^2 estimated as 151257: log likelihood = -886.06, aic = 1784.12 [[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.8993 -0.1856 0.1452 -0.7465 0 0 0 s.e. 0.2054 0.1294 0.1025 0.1897 0 0 0 sigma^2 estimated as 152426: log likelihood = -886.41, aic = 1782.83 [[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.7815 0.0958 0 0.9746 0 0 0 s.e. 0.0976 0.0949 0 0.0386 0 0 0 sigma^2 estimated as 150423: log likelihood = -885.82, aic = 1779.65 [[3]][[7]] NULL $aic [1] 1787.905 1786.015 1784.120 1782.827 1779.645 1778.662 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 > postscript(file="/var/www/html/rcomp/tmp/1ites1229333318.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] 9.005725 12.589614 323.538390 -73.644977 441.908750 [6] 592.360665 334.666360 -215.276407 395.336233 -209.740847 [11] -142.283163 -341.150869 520.690752 289.120624 48.021431 [16] -801.029156 136.294122 357.049450 -343.397850 4.191725 [21] 104.185398 313.277446 -75.770133 -529.662927 332.160558 [26] -88.663890 80.369942 28.752624 -678.301149 244.559010 [31] 289.920021 182.757524 -359.221764 -53.697023 -1287.789678 [36] 448.142920 325.680822 313.835629 -207.118736 102.767717 [41] 488.513960 -318.132924 -98.744443 -537.708341 -801.663540 [46] 220.838384 -601.316058 56.133179 500.269064 -127.279096 [51] -74.777421 -514.830567 131.652502 330.023887 240.249026 [56] 431.871159 -21.023738 149.313693 158.736102 185.011251 [61] 28.007242 379.195753 321.532984 38.232551 -306.685185 [66] 170.325860 -390.630699 388.993012 -347.990986 27.381003 [71] 72.253654 -127.673587 359.359924 251.391082 -213.595036 [76] 262.652544 -140.788283 -311.874517 90.153578 133.247167 [81] 5.435685 39.005531 -58.409181 -169.119481 375.040303 [86] 76.910938 37.776603 84.097027 165.349032 54.772225 [91] 98.676805 -363.040424 120.688469 165.423515 283.562482 [96] 347.917737 192.163929 137.554380 130.350715 78.825170 [101] -360.028090 542.106045 539.382679 10.484709 176.921262 [106] -462.029432 410.919649 233.136141 -689.830029 298.173564 [111] -930.996777 90.018844 -322.825733 612.335311 -57.673059 [116] -622.117355 -733.541092 421.829033 -594.590604 -1698.403730 [121] -382.096779 > postscript(file="/var/www/html/rcomp/tmp/2vgdj1229333318.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/32z5p1229333318.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/4tvrx1229333318.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/5u7qw1229333318.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/6txzf1229333318.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/7759a1229333318.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/89x3c1229333318.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/9ty4i1229333318.tab") > > system("convert tmp/1ites1229333318.ps tmp/1ites1229333318.png") > system("convert tmp/2vgdj1229333318.ps tmp/2vgdj1229333318.png") > system("convert tmp/32z5p1229333318.ps tmp/32z5p1229333318.png") > system("convert tmp/4tvrx1229333318.ps tmp/4tvrx1229333318.png") > system("convert tmp/5u7qw1229333318.ps tmp/5u7qw1229333318.png") > system("convert tmp/6txzf1229333318.ps tmp/6txzf1229333318.png") > system("convert tmp/7759a1229333318.ps tmp/7759a1229333318.png") > > > proc.time() user system elapsed 7.687 1.947 12.676