R version 2.12.0 (2010-10-15) Copyright (C) 2010 The R Foundation for Statistical Computing ISBN 3-900051-07-0 Platform: x86_64-redhat-linux-gnu (64-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(1567,2237,2598,3729,5715,5776,5852,6878,5488,3583,2054,2282,1552,2261,2446,3519,5161,5085,5711,6057,5224,3363,1899,2115,1491,2061,2419,3430,4778,4862,6176,5664,5529,3418,1941,2402,1579,2146,2462,3695,4831,5134,6250,5760,6249,2917,1741,2359,1511,2059,2635,2867,4403,5720,4502,5749,5627,2846,1762,2429,1169,2154,2249,2687,4359,5382,4459,6398,4596,3024,1887,2070,1351,2218,2461,3028,4784,4975,4607,6249,4809,3157,1910,2228,1673,2589,2332,3785,4916,5207,6055,5751,5247,3387,2091,2401,1664,2205,2295,3762,4890,5117,6099,5865,5594,3229,2106,2410,1583,2092,2612,3665,4880,5875,5892,6078,6515,3164,2028,2677,1580,2196,2838,3087,4726,6521,6739,5943,6265,3323,2098,2544,1442,2307,2811,3461,5451,5481,5114,8381,5215,3700,2122,2311,1515,2351,2289,3380,5398,5242,5162,6391,5958,3727,1883,2191) > par9 = '1' > par8 = '2' > par7 = '1' > par6 = '3' > par5 = '12' > par4 = '1' > par3 = '0' > par2 = '-0.2' > 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] [,7] [1,] 0.4826508 0.1587002 0.2852891 -0.6243580 0.2551004 -0.2351247 -0.9999951 [2,] 0.5940437 0.0000000 0.3351744 -0.6626392 0.2720461 -0.2434904 -0.9999998 [3,] NA NA NA NA NA NA NA [4,] NA NA NA NA NA NA NA [5,] NA NA NA NA NA NA NA [6,] NA NA NA NA 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 [[2]] [,1] [,2] [,3] [,4] [,5] [,6] [,7] [1,] 0.00243 0.07685 0.01271 2e-05 0.00604 0.01649 0 [2,] 0.00002 NA 0.00092 0e+00 0.00274 0.01218 0 [3,] NA NA NA NA NA NA NA [4,] NA NA NA NA NA NA NA [5,] NA NA NA NA NA NA NA [6,] NA NA NA NA 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.4827 0.1587 0.2853 -0.6244 0.2551 -0.2351 -1.000 s.e. 0.1564 0.0891 0.1131 0.1421 0.0916 0.0969 0.087 sigma^2 estimated as 7.812e-06: log likelihood = 626.69, aic = -1237.38 [[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.4827 0.1587 0.2853 -0.6244 0.2551 -0.2351 -1.000 s.e. 0.1564 0.0891 0.1131 0.1421 0.0916 0.0969 0.087 sigma^2 estimated as 7.812e-06: log likelihood = 626.69, aic = -1237.38 [[3]][[3]] NULL [[3]][[4]] NULL [[3]][[5]] NULL [[3]][[6]] NULL [[3]][[7]] NULL $aic [1] -1237.382 -1236.330 Warning message: In arima(series, order = order, seasonal = seasonal, include.mean = include.mean, : some AR parameters were fixed: setting transform.pars = FALSE > postscript(file="/var/www/wessaorg/rcomp/tmp/1uee91293648757.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 = 156 Frequency = 1 [1] 2.296073e-04 2.138289e-04 2.075256e-04 1.930549e-04 1.772539e-04 [6] 1.768779e-04 1.764160e-04 1.708073e-04 1.786964e-04 1.946029e-04 [11] 2.175098e-04 2.129784e-04 3.108315e-04 -3.029526e-04 1.735474e-03 [16] 1.767395e-03 2.889778e-03 3.231547e-03 2.106484e-04 1.944541e-03 [21] 4.109040e-05 6.583038e-04 1.092293e-03 1.579230e-03 2.670023e-04 [26] 1.362761e-03 -6.477832e-04 -3.819257e-04 1.236043e-03 1.277796e-03 [31] -2.912276e-03 8.250894e-04 -2.162547e-03 -5.465098e-04 -8.612046e-04 [36] -3.415952e-03 -2.347547e-03 -7.828339e-04 1.106850e-03 -3.375253e-04 [41] 2.312542e-03 1.145052e-03 -1.437157e-04 1.550166e-03 -3.371886e-03 [46] 5.690013e-03 5.892366e-03 1.850035e-03 -2.320159e-05 2.064253e-04 [51] -3.407135e-03 6.756522e-03 4.741693e-03 -2.542780e-03 5.695108e-03 [56] 1.126991e-04 -4.473839e-04 1.721892e-04 -3.552728e-04 -4.108161e-03 [61] 8.182868e-03 -1.179987e-03 3.299927e-03 3.083487e-03 1.788647e-03 [66] -2.325074e-03 9.835909e-04 -4.706479e-03 2.960292e-03 1.038287e-04 [71] -1.176829e-03 2.375144e-03 -1.087365e-03 -2.593788e-03 -4.307493e-03 [76] 5.288051e-04 7.463744e-05 1.735718e-03 5.089852e-03 2.602025e-04 [81] 1.247713e-03 -9.403760e-04 -1.222352e-03 -2.196273e-03 -5.899721e-03 [86] -8.442623e-03 2.035360e-03 -2.210915e-03 2.525195e-03 1.026515e-03 [91] -2.080392e-03 2.398929e-03 2.537084e-03 4.263530e-05 -3.805646e-03 [96] -1.540565e-03 -2.068645e-03 3.003548e-03 3.866924e-03 -5.333399e-04 [101] 8.152515e-05 1.369265e-03 -7.508244e-04 5.511462e-04 -7.033610e-04 [106] 7.761986e-04 -2.697315e-03 -1.111810e-03 -2.439412e-03 1.250041e-03 [111] -1.762635e-03 -2.289274e-03 2.735590e-04 -2.228462e-03 -9.758184e-04 [116] 1.272236e-03 -3.544751e-03 1.392624e-03 -1.373865e-04 -3.231377e-03 [121] -1.710508e-03 1.144312e-03 -1.426050e-03 5.420477e-03 3.627896e-03 [126] -3.054432e-03 -7.271905e-03 3.685714e-04 -6.724980e-04 1.420038e-03 [131] -1.693917e-03 -2.812656e-04 3.912857e-03 1.322621e-03 -2.247120e-03 [136] -2.550587e-03 -3.541835e-03 1.994309e-03 6.849549e-03 -7.469104e-03 [141] 1.512803e-03 -4.207371e-03 -5.268624e-04 1.801394e-03 1.429377e-03 [146] 2.388804e-04 4.874749e-03 3.008118e-03 -6.950027e-04 -9.118935e-04 [151] -1.190815e-04 2.378176e-03 -3.565236e-03 -4.615274e-03 1.253214e-03 [156] 3.719491e-03 > postscript(file="/var/www/wessaorg/rcomp/tmp/2uee91293648757.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/www/wessaorg/rcomp/tmp/3uee91293648757.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/www/wessaorg/rcomp/tmp/44neu1293648757.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/www/wessaorg/rcomp/tmp/54neu1293648757.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/www/wessaorg/rcomp/tmp/64neu1293648757.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/www/wessaorg/rcomp/tmp/74neu1293648757.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/www/wessaorg/rcomp/createtable file can be downloaded at http://www.wessa.net/cretab > load(file="/var/www/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/www/wessaorg/rcomp/tmp/80xbl1293648757.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/wessaorg/rcomp/tmp/94fsr1293648757.tab") > > try(system("convert tmp/1uee91293648757.ps tmp/1uee91293648757.png",intern=TRUE)) character(0) > try(system("convert tmp/2uee91293648757.ps tmp/2uee91293648757.png",intern=TRUE)) character(0) > try(system("convert tmp/3uee91293648757.ps tmp/3uee91293648757.png",intern=TRUE)) character(0) > try(system("convert tmp/44neu1293648757.ps tmp/44neu1293648757.png",intern=TRUE)) character(0) > try(system("convert tmp/54neu1293648757.ps tmp/54neu1293648757.png",intern=TRUE)) character(0) > try(system("convert tmp/64neu1293648757.ps tmp/64neu1293648757.png",intern=TRUE)) character(0) > try(system("convert tmp/74neu1293648757.ps tmp/74neu1293648757.png",intern=TRUE)) character(0) > > > proc.time() user system elapsed 8.39 0.87 9.45