R version 2.13.0 (2011-04-13) Copyright (C) 2011 The R Foundation for Statistical Computing ISBN 3-900051-07-0 Platform: i486-pc-linux-gnu (32-bit) 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(413491 + ,399153 + ,385939 + ,373917 + ,364635 + ,364696 + ,418358 + ,428212 + ,423730 + ,420677 + ,417428 + ,423245 + ,423113 + ,418873 + ,405733 + ,397812 + ,389918 + ,391116 + ,443814 + ,460373 + ,455422 + ,456288 + ,452233 + ,459256 + ,461146 + ,451391 + ,443101 + ,438810 + ,430457 + ,435721 + ,488280 + ,505814 + ,502338 + ,500910 + ,501434 + ,515476 + ,520862 + ,519517 + ,511805 + ,508607 + ,505327 + ,511435 + ,570158 + ,591665 + ,593572 + ,586346 + ,586063 + ,591504 + ,594033 + ,585597 + ,572450 + ,562917 + ,554675 + ,553997 + ,601310 + ,622255 + ,616735 + ,606480 + ,595079 + ,598588 + ,599917 + ,591573 + ,575489 + ,567223 + ,555338 + ,555252 + ,608249 + ,630859 + ,628632 + ,624435 + ,609670 + ,615830 + ,621170 + ,604212 + ,584348 + ,573717 + ,555234 + ,544897 + ,598866 + ,620081 + ,607699 + ,589960 + ,578665 + ,580166 + ,579457 + ,571560 + ,560460 + ,551397 + ,536763 + ,540562 + ,588184 + ,607049 + ,598968 + ,577644 + ,562640 + ,565867 + ,561274 + ,554144 + ,539900 + ,526271 + ,511841 + ,505282 + ,554083 + ,584225 + ,568858 + ,539516 + ,521612 + ,525562 + ,526519 + ,515713 + ,503454 + ,489301 + ,479020 + ,475102 + ,523682 + ,551528 + ,531626 + ,511037 + ,492417 + ,492188 + ,492865 + ,480961 + ,461935 + ,456608 + ,441977 + ,439148 + ,488180 + ,520564 + ,501492 + ,485025 + ,464196 + ,460170 + ,467037 + ,460070 + ,447988 + ,442867 + ,436087 + ,431328 + ,484015 + ,509673 + ,512927 + ,502831 + ,470984 + ,471067 + ,476049 + ,474605 + ,470439 + ,461251 + ,454724 + ,455626 + ,516847 + ,525192 + ,522975 + ,518585 + ,509239 + ,512238 + ,519164 + ,517009 + ,509933 + ,509127 + ,500857 + ,506971 + ,569323 + ,579714 + ,577992 + ,565464 + ,547344 + ,554788 + ,562325 + ,560854 + ,555332 + ,543599 + ,536662 + ,542722 + ,593530 + ,610763 + ,612613 + ,611324 + ,594167 + ,595454 + ,590865 + ,589379 + ,584428 + ,573100 + ,567456 + ,569028 + ,620735 + ,628884 + ,628232 + ,612117 + ,595404 + ,597141 + ,593408 + ,590072 + ,579799 + ,574205 + ,572775 + ,572942 + ,619567 + ,625809 + ,619916 + ,587625 + ,565742 + ,557274 + ,560576 + ,548854 + ,531673 + ,525919 + ,511038 + ,498662 + ,555362 + ,564591 + ,541657 + ,527070 + ,509846 + ,514258 + ,516922 + ,507561 + ,492622 + ,490243 + ,469357 + ,477580 + ,528379 + ,533590 + ,517945 + ,506174 + ,501866 + ,516141 + ,528222 + ,532638 + ,536322 + ,536535 + ,523597 + ,536214 + ,586570 + ,596594 + ,580523 + ,564478 + ,557560 + ,575093 + ,580112 + ,574761 + ,563250 + ,551531 + ,537034 + ,544686 + ,600991 + ,604378 + ,586111 + ,563668 + ,548604 + ,551174 + ,555654) > par9 = '1' > par8 = '1' > par7 = '1' > par6 = '1' > par5 = '12' > par4 = '1' > 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] [1,] 0.8935773 -0.7557272 0.4061263 -0.8837251 [2,] 0.9238711 -0.7850270 0.0000000 -0.5337868 [3,] NA NA NA NA [4,] NA NA NA NA [5,] NA NA NA NA [6,] NA NA NA NA [7,] NA NA NA NA [8,] NA NA NA NA [[2]] [,1] [,2] [,3] [,4] [1,] 0 0 0.00025 0 [2,] 0 0 NA 0 [3,] NA NA NA NA [4,] NA NA NA NA [5,] NA NA NA NA [6,] NA NA NA NA [7,] NA NA NA NA [8,] NA NA NA NA [[3]] [[3]][[1]] Call: arima(x = series, order = order, seasonal = seasonal, include.mean = include.mean, method = "ML") Coefficients: ar1 ma1 sar1 sma1 0.8936 -0.7557 0.4061 -0.8837 s.e. 0.0648 0.0888 0.1094 0.0970 sigma^2 estimated as 33311652: log likelihood = -2423.92, aic = 4857.83 [[3]][[2]] Call: arima(x = series, order = order, seasonal = seasonal, include.mean = include.mean, method = "ML") Coefficients: ar1 ma1 sar1 sma1 0.8936 -0.7557 0.4061 -0.8837 s.e. 0.0648 0.0888 0.1094 0.0970 sigma^2 estimated as 33311652: log likelihood = -2423.92, aic = 4857.83 [[3]][[3]] NULL [[3]][[4]] NULL $aic [1] 4857.834 4864.432 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 log(s2) : NaNs produced > postscript(file="/var/wessaorg/rcomp/tmp/1c9tm1323208205.ps",horizontal=F,onefile=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 = 253 Frequency = 1 [1] 238.72909 95.65663 51.45398 27.74901 13.74006 [6] 11.48844 59.79449 61.54459 50.44381 42.48165 [11] 35.50631 -182.24545 -1381.38076 8725.76438 -1449.55961 [16] 2522.52758 -66.39019 -84.78152 -1760.96211 5457.90676 [21] -1504.82412 2807.83760 -1583.09907 629.77117 1457.27902 [26] -3310.33006 4194.99026 3635.32756 -1241.03432 3228.58316 [31] -1521.25568 1947.57978 382.17868 -1820.08589 3702.57695 [36] 6136.16172 2451.30415 6377.90691 -322.37261 942.18436 [41] 2940.71160 243.90651 3709.90908 3347.54078 3211.89406 [46] -7857.21905 -390.51726 -6300.79176 -807.22940 -3433.45087 [51] -3163.78796 -3087.63191 -1471.94545 -3540.70422 -7109.51379 [56] 4925.68064 -3127.77614 -3056.23969 -7660.93029 131.95558 [61] 1894.64486 2040.02195 -2225.53518 2109.18024 -2615.20822 [66] 683.86208 3977.15035 4405.38700 2152.59806 2663.74933 [71] -7625.74185 1482.77742 4000.36113 -8838.18877 -4814.07783 [76] -1004.80472 -6801.12067 -8703.35799 4203.53952 3489.84427 [81] -7808.20014 -10658.86934 2561.69691 -1825.21013 -1472.39676 [86] 7920.73264 6665.71227 711.47300 -406.72212 8934.34780 [91] -6792.87691 -691.51758 441.96949 -9243.19870 -4657.03118 [96] 1343.48279 -3647.79449 3353.10877 -933.68848 -3648.91681 [101] -319.39187 -7007.50830 983.86570 13334.91288 -8821.90062 [106] -13413.81769 -3719.73848 2621.16446 4995.11345 -1199.66315 [111] 2855.19675 -1960.01102 3480.59408 -39.54158 -1351.78074 [116] 3680.45287 -9050.61034 618.97462 -4153.38180 -3279.07021 [121] 1578.70666 -485.06983 -4966.56734 8361.88848 -3379.71924 [126] 494.64105 -252.81206 8850.25794 -5803.11598 293.87792 [131] -6205.73569 -5195.50834 7725.47864 4136.94894 3967.60179 [136] 1599.67611 5312.12261 -4231.04179 1817.49836 -2342.55006 [141] 16814.67689 1922.82997 -18398.46369 272.03313 980.22621 [146] 6673.83367 7724.75891 -4054.37941 1298.22469 2794.28917 [151] 7788.36669 -18161.12819 1040.85845 7388.99869 12298.08513 [156] -1056.67927 1469.76114 958.49997 -397.50459 6479.06628 [161] -2053.27777 4586.84563 3524.56178 -7303.05977 2058.22516 [166] -5494.14610 -6805.04145 4981.77658 2673.02599 3017.19047 [171] 3156.53220 -8391.57778 2361.29058 3194.06598 -7573.96911 [176] 2213.64285 6336.06243 10097.63644 -3148.00128 -5459.39739 [181] -10331.97913 3807.82696 3849.83399 -1685.28528 2814.88388 [186] -1760.30868 -558.05295 -10260.94452 2982.67303 -8902.98225 [191] 1133.74481 1044.31975 -1532.64395 2067.45260 -1481.81561 [196] 5350.11996 6358.04750 -1492.99931 -6259.83767 -6756.35077 [201] -1458.61997 -17298.32064 -2431.05802 -7270.88205 8405.70588 [206] -4398.45167 -3934.09858 4479.72273 -7498.11761 -9643.29805 [211] 10999.70641 -549.84358 -15453.58028 11601.50364 3232.88213 [216] 8626.52415 84.70053 -532.29276 -1045.71885 4712.84179 [221] -9649.15783 15354.67841 -5189.88186 -8043.27291 -473.20998 [226] 3116.87357 12393.42790 9605.44858 7116.74232 9023.22601 [231] 12505.58121 -289.34686 -2585.29451 4783.67893 -5702.89305 [236] -3249.70074 -6648.73222 -4348.94043 2557.62786 8411.74601 [241] -3979.54530 -5422.04950 -8104.70378 -7374.30276 -849.76920 [246] 2833.47497 6070.46610 -8537.33126 -4501.48849 -5658.63484 [251] -2036.82305 -5770.13428 3388.52732 > postscript(file="/var/wessaorg/rcomp/tmp/2jcx91323208205.ps",horizontal=F,onefile=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/wessaorg/rcomp/tmp/3yzxn1323208205.ps",horizontal=F,onefile=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/wessaorg/rcomp/tmp/472f81323208205.ps",horizontal=F,onefile=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/wessaorg/rcomp/tmp/5nw951323208205.ps",horizontal=F,onefile=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/wessaorg/rcomp/tmp/63zya1323208205.ps",horizontal=F,onefile=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/wessaorg/rcomp/tmp/7omof1323208205.ps",horizontal=F,onefile=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/wessaorg/rcomp/createtable file can be downloaded at http://www.wessa.net/cretab > load(file="/var/wessaorg/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/wessaorg/rcomp/tmp/88p3k1323208205.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/wessaorg/rcomp/tmp/9zw7i1323208205.tab") > > try(system("convert tmp/1c9tm1323208205.ps tmp/1c9tm1323208205.png",intern=TRUE)) character(0) > try(system("convert tmp/2jcx91323208205.ps tmp/2jcx91323208205.png",intern=TRUE)) character(0) > try(system("convert tmp/3yzxn1323208205.ps tmp/3yzxn1323208205.png",intern=TRUE)) character(0) > try(system("convert tmp/472f81323208205.ps tmp/472f81323208205.png",intern=TRUE)) character(0) > try(system("convert tmp/5nw951323208205.ps tmp/5nw951323208205.png",intern=TRUE)) character(0) > try(system("convert tmp/63zya1323208205.ps tmp/63zya1323208205.png",intern=TRUE)) character(0) > try(system("convert tmp/7omof1323208205.ps tmp/7omof1323208205.png",intern=TRUE)) character(0) > > > proc.time() user system elapsed 4.161 0.376 4.593