R version 2.9.0 (2009-04-17) Copyright (C) 2009 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(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,8595.56,8396.20,7690.50,7235.47,7992.12,8398.37,8593,8679.75,9374.63,9634.97,9857.34,10238.83) > 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.6955172 -0.1551009 0.13243329 -0.5012689 -0.1460832 -0.09301764 [2,] 0.6953494 -0.1548429 0.13371163 -0.5015224 0.0000000 -0.09249548 [3,] 0.6923283 -0.1561757 0.13475592 -0.5016036 0.0000000 -0.09230026 [4,] 0.6761636 -0.1412703 0.13937944 -0.4936021 0.0000000 0.00000000 [5,] 0.3967431 0.0000000 0.09765139 -0.2435985 0.0000000 0.00000000 [6,] 0.1828065 0.0000000 0.09446789 0.0000000 0.0000000 0.00000000 [7,] 0.1832738 0.0000000 0.00000000 0.0000000 0.0000000 0.00000000 [8,] 0.0000000 0.0000000 0.00000000 0.0000000 0.0000000 0.00000000 [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.17071872 [2,] 0.02563045 [3,] 0.00000000 [4,] 0.00000000 [5,] 0.00000000 [6,] 0.00000000 [7,] 0.00000000 [8,] 0.00000000 [9,] NA [10,] NA [11,] NA [12,] NA [13,] NA [14,] NA [[2]] [,1] [,2] [,3] [,4] [,5] [,6] [,7] [1,] 0.03598 0.23842 0.17411 0.11874 0.81749 0.51135 0.78719 [2,] 0.03390 0.23807 0.16912 0.11378 NA 0.50738 0.81352 [3,] 0.03652 0.23263 0.16461 0.11806 NA 0.50830 NA [4,] 0.03331 0.26296 0.15141 0.10919 NA NA NA [5,] 0.54807 NA 0.28542 0.75044 NA NA NA [6,] 0.05405 NA 0.31447 NA NA NA NA [7,] 0.05470 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.6955 -0.1551 0.1324 -0.5013 -0.1461 -0.0930 0.1707 s.e. 0.3273 0.1308 0.0968 0.3186 0.6314 0.1411 0.6307 sigma^2 estimated as 159894: log likelihood = -815.28, aic = 1646.56 [[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.6955 -0.1551 0.1324 -0.5013 -0.1461 -0.0930 0.1707 s.e. 0.3273 0.1308 0.0968 0.3186 0.6314 0.1411 0.6307 sigma^2 estimated as 159894: log likelihood = -815.28, aic = 1646.56 [[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.6953 -0.1548 0.1337 -0.5015 0 -0.0925 0.0256 s.e. 0.3235 0.1305 0.0966 0.3145 0 0.1390 0.1084 sigma^2 estimated as 159989: log likelihood = -815.3, aic = 1644.6 [[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.6923 -0.1562 0.1348 -0.5016 0 -0.0923 0 s.e. 0.3268 0.1301 0.0963 0.3183 0 0.1391 0 sigma^2 estimated as 160090: log likelihood = -815.33, aic = 1642.66 [[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.6762 -0.1413 0.1394 -0.4936 0 0 0 s.e. 0.3135 0.1255 0.0965 0.3056 0 0 0 sigma^2 estimated as 161015: log likelihood = -815.55, aic = 1641.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.3967 0 0.0977 -0.2436 0 0 0 s.e. 0.6584 0 0.0910 0.7639 0 0 0 sigma^2 estimated as 162978: log likelihood = -816.2, aic = 1640.39 [[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.1828 0 0.0945 0 0 0 0 s.e. 0.0939 0 0.0935 0 0 0 0 sigma^2 estimated as 163088: log likelihood = -816.23, aic = 1638.45 [[3]][[8]] 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.1833 0 0 0 0 0 0 s.e. 0.0944 0 0 0 0 0 0 sigma^2 estimated as 164644: log likelihood = -816.74, aic = 1637.47 $aic [1] 1646.557 1644.599 1642.655 1641.092 1640.395 1638.455 1637.470 1639.176 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 7: In max(i) : no non-missing arguments to max; returning -Inf 8: In max(i) : no non-missing arguments to max; returning -Inf 9: In max(try.data.frame[, 4], na.rm = TRUE) : no non-missing arguments to max; returning -Inf > postscript(file="/var/www/html/rcomp/tmp/12ija1262179480.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 = 111 Frequency = 1 [1] 10.967864 -525.261862 330.145024 -41.629842 15.859555 [6] 91.542121 -741.935709 294.173861 303.275107 159.377316 [11] -363.089880 -70.677545 -1248.327395 411.336267 468.432442 [16] 164.853331 -101.764552 -21.221258 614.147306 -433.137446 [21] -39.923648 -569.919719 -768.177675 229.448685 -537.359398 [26] -16.400739 613.741132 -223.281524 -31.420488 -548.472787 [31] 163.791442 345.676829 223.350417 421.746025 -30.684575 [36] 120.069852 183.862929 151.783035 44.973636 347.890249 [41] 348.981415 -14.575602 -289.162335 145.598124 -342.790531 [46] 331.594626 -262.661310 -80.285670 193.652732 -234.474606 [51] 447.352749 186.460251 -181.819924 208.804864 -75.491863 [56] -391.223817 167.092421 92.234096 38.678850 -1.875503 [61] -23.359304 -204.247460 409.103103 64.576417 20.375225 [66] 90.523159 156.369043 57.056053 82.883134 -354.090761 [71] 100.483502 213.326984 235.835458 378.902445 143.308405 [76] 151.777718 99.995292 93.798553 -384.684440 552.789226 [81] 563.829449 -47.208628 179.789980 -468.954673 397.442022 [86] 285.312597 -763.671045 334.809952 -906.675880 40.687441 [91] -203.962891 504.113064 71.040049 -784.373222 -595.769829 [96] 342.946119 -454.858762 -1855.985306 -213.030872 84.959234 [101] -195.879631 -669.162535 -325.693679 840.045077 267.575879 [106] 120.175019 51.079420 678.980998 132.986702 174.656499 [111] 340.735405 > postscript(file="/var/www/html/rcomp/tmp/2j1ej1262179480.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/325kf1262179480.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/4xr8t1262179480.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/5votn1262179480.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/6fevn1262179480.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/7lys61262179480.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/8tmgi1262179480.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/9ofo21262179480.tab") > > try(system("convert tmp/12ija1262179480.ps tmp/12ija1262179480.png",intern=TRUE)) character(0) > try(system("convert tmp/2j1ej1262179480.ps tmp/2j1ej1262179480.png",intern=TRUE)) character(0) > try(system("convert tmp/325kf1262179480.ps tmp/325kf1262179480.png",intern=TRUE)) character(0) > try(system("convert tmp/4xr8t1262179480.ps tmp/4xr8t1262179480.png",intern=TRUE)) character(0) > try(system("convert tmp/5votn1262179480.ps tmp/5votn1262179480.png",intern=TRUE)) character(0) > try(system("convert tmp/6fevn1262179480.ps tmp/6fevn1262179480.png",intern=TRUE)) character(0) > try(system("convert tmp/7lys61262179480.ps tmp/7lys61262179480.png",intern=TRUE)) character(0) > > > proc.time() user system elapsed 6.494 1.875 8.190