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(897262 + ,1133132 + ,1384548 + ,2324057 + ,2502808 + ,2516762 + ,5579822 + ,4945991 + ,2019915 + ,1830905 + ,1251016 + ,949902 + ,923000 + ,1215747 + ,1479112 + ,2371781 + ,2521576 + ,2350559 + ,5673323 + ,4414295 + ,2016902 + ,1958302 + ,1284086 + ,1186305 + ,957833 + ,1255719 + ,1482709 + ,2361136 + ,2508100 + ,2254488 + ,5669953 + ,4227480 + ,2067790 + ,1958419 + ,1318158 + ,1287921 + ,1076982 + ,1293669 + ,1582053 + ,2393005 + ,2310531 + ,2597899 + ,5507587 + ,4194133 + ,2185092 + ,2122018 + ,1413348 + ,1338342 + ,1052655 + ,1370046 + ,1887027 + ,2448017 + ,2550796 + ,2655837 + ,5269499 + ,4247405 + ,2109722 + ,2143145 + ,1582013 + ,1413221 + ,1118520 + ,1478655 + ,2000108 + ,2085234 + ,2651805 + ,2522176 + ,5170142 + ,4150129 + ,2104254 + ,2211398 + ,1505900 + ,1524305 + ,1093144 + ,1449647 + ,1771197 + ,2445932 + ,2678945 + ,2400737 + ,4796880 + ,4118001 + ,2125714 + ,2125515 + ,1508760 + ,1508765 + ,1091075 + ,1514814 + ,1748997 + ,2424406 + ,2747942 + ,2377332 + ,5210706 + ,3882821 + ,2197469 + ,2271155 + ,1618917 + ,1391579 + ,1143249 + ,1445785 + ,1870242 + ,2597788 + ,2436231 + ,2684184 + ,4705109 + ,4331347 + ,2369192 + ,2283947 + ,1749607 + ,1598601 + ,1221234 + ,1497778 + ,1823567 + ,2489908 + ,2532837 + ,2456065 + ,4627018 + ,4276894 + ,2314950 + ,2238987 + ,1652753 + ,1561968 + ,1115878 + ,1596714 + ,1910242 + ,2286450 + ,2772441 + ,2394538 + ,4715128 + ,4402420 + ,2325392 + ,2306683 + ,1725282 + ,1541370 + ,1168142 + ,1457835 + ,1816380 + ,2446552 + ,2575774 + ,2537852 + ,4728097 + ,4372685 + ,2302672 + ,2346402 + ,1689915 + ,1576183) > par20 = '' > par19 = '' > par18 = '' > par17 = '' > par16 = '' > par15 = '' > par14 = '' > par13 = '' > par12 = '' > par11 = '' > par10 = '' > par9 = '1' > par8 = '2' > par7 = '1' > par6 = '3' > par5 = '12' > par4 = '1' > par3 = '0' > par2 = '1' > par1 = 'FALSE' > ylab = '' > xlab = '' > main = '' > #'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,] -1.135655 -0.07193681 0.1936614 0.9578723 0.6100906 0.2193399 -0.7596005 [2,] -1.096012 0.00000000 0.2300070 0.9556873 0.6038523 0.2199620 -0.7615069 [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 0.5934 0.02862 0 0.00622 0.01847 0.00079 [2,] 0 NA 0.00006 0 0.01002 0.01856 0.00140 [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 -1.1357 -0.0719 0.1937 0.9579 0.6101 0.2193 -0.7596 s.e. 0.0938 0.1344 0.0875 0.0338 0.2195 0.0920 0.2212 sigma^2 estimated as 1.912e+10: log likelihood = -1750.94, aic = 3517.88 [[3]][[2]] Call: arima(x = series, order = order, seasonal = seasonal, include.mean = include.mean, method = "ML") Coefficients: ar1 ar2 ar3 ma1 sar1 sar2 sma1 -1.1357 -0.0719 0.1937 0.9579 0.6101 0.2193 -0.7596 s.e. 0.0938 0.1344 0.0875 0.0338 0.2195 0.0920 0.2212 sigma^2 estimated as 1.912e+10: log likelihood = -1750.94, aic = 3517.88 [[3]][[3]] NULL [[3]][[4]] NULL [[3]][[5]] NULL [[3]][[6]] NULL [[3]][[7]] NULL $aic [1] 3517.878 3516.166 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/www/html/rcomp/tmp/1cpv91261229507.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 = 144 Frequency = 1 [1] 897.2614 1133.1316 1384.5473 2324.0558 2502.8070 [6] 2516.7607 5579.8189 4945.9892 2019.9142 1830.9035 [11] 1251.0157 949.9013 23214.0772 83626.8514 104338.5905 [16] 53988.6239 11734.2060 -162420.0932 49492.3388 -465045.3693 [21] -117015.7103 173220.8271 109272.1049 173136.4136 117803.9836 [26] -6151.0227 38065.0482 -24429.2262 117.5568 -133717.4904 [31] 3821.2424 -258285.9501 26530.4529 27494.1408 85720.9283 [36] 84980.3773 182692.5771 -4826.3279 115331.6512 -6297.3274 [41] -164819.3312 261853.4736 -46857.0777 -84415.4403 128822.9322 [46] 196958.0702 82371.0258 50716.1301 -48066.9039 81721.9766 [51] 302125.0803 125010.9752 165741.3722 156493.6410 -263567.0566 [56] 33905.7403 -9190.3576 26836.4629 157825.7899 109164.5844 [61] -2428.8873 126435.6511 131701.6446 -329987.3025 55106.0020 [66] -71932.3251 -134462.9425 -82924.8393 26093.1195 246.0758 [71] -14495.9422 36608.1992 25373.7276 -68031.1429 -249652.3320 [76] 243976.9901 123594.1065 -172755.3967 -424443.6105 -20297.2867 [81] 29442.4548 -42738.9697 -107431.9697 16940.1588 -58233.1109 [86] 70874.3071 -127639.3356 73635.9189 41865.8315 3406.9335 [91] 336741.6958 -87474.2529 -37027.5182 132953.7638 134798.6752 [96] -182640.7902 25783.5896 -82315.8922 131919.3522 135314.5593 [101] -248867.1911 182498.0482 -244609.5294 338387.6546 271451.8313 [106] 70593.4965 22024.6970 263410.1125 16737.9835 81025.6154 [111] -113635.0227 -36155.5029 -45323.8737 -93252.5559 -229820.1836 [116] 99119.8665 -42067.0577 -38785.7074 -150698.6340 22926.6342 [121] -135949.8836 128589.2944 46278.1472 -191741.9949 162889.9369 [126] 3541.0117 64567.7161 139225.4866 -3064.7113 -1552.1401 [131] 55343.9938 -66430.2180 16458.0505 -137769.2974 -99442.1289 [136] 101741.2731 -96615.8368 79772.8991 127917.2424 -3955.9558 [141] -68035.5076 48304.9925 -37292.0508 18572.9981 > postscript(file="/var/www/html/rcomp/tmp/2c4vz1261229507.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/3o0td1261229507.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/4rsqk1261229507.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/5fnvm1261229507.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/6bnq21261229507.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/75gtf1261229507.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/8wrtq1261229507.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/9nvp71261229507.tab") > try(system("convert tmp/1cpv91261229507.ps tmp/1cpv91261229507.png",intern=TRUE)) character(0) > try(system("convert tmp/2c4vz1261229507.ps tmp/2c4vz1261229507.png",intern=TRUE)) character(0) > try(system("convert tmp/3o0td1261229507.ps tmp/3o0td1261229507.png",intern=TRUE)) character(0) > try(system("convert tmp/4rsqk1261229507.ps tmp/4rsqk1261229507.png",intern=TRUE)) character(0) > try(system("convert tmp/5fnvm1261229507.ps tmp/5fnvm1261229507.png",intern=TRUE)) character(0) > try(system("convert tmp/6bnq21261229507.ps tmp/6bnq21261229507.png",intern=TRUE)) character(0) > try(system("convert tmp/75gtf1261229507.ps tmp/75gtf1261229507.png",intern=TRUE)) character(0) > > > proc.time() user system elapsed 9.054 1.533 11.319