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(9568.3 + ,9920.3 + ,11353.5 + ,9247.5 + ,10114.2 + ,10763.1 + ,8456.1 + ,8071.6 + ,10328 + ,10551.4 + ,10186.1 + ,8821.6 + ,9841.3 + ,10233.6 + ,10794.6 + ,10289.3 + ,10513.4 + ,10607.6 + ,9707.4 + ,8103.5 + ,10982.6 + ,11836.9 + ,10517.5 + ,9810.5 + ,10374.8 + ,10855.3 + ,11671.3 + ,11901.2 + ,10846.4 + ,11917.5 + ,11362.8 + ,9314.5 + ,12605.9 + ,12815.1 + ,11254.5 + ,11111.8 + ,11282.9 + ,11554.5 + ,12935.6 + ,12146.3 + ,11615.3 + ,13214.8 + ,11735.5 + ,9522.3 + ,12694.8 + ,12317.6 + ,11450 + ,11380.9 + ,10604.6 + ,10972.2 + ,13331.5 + ,11733.1 + ,11284.7 + ,13295.8 + ,11881.4 + ,10374.2 + ,13828 + ,13490.5 + ,13092.2 + ,13184.4 + ,12398.4 + ,13882.3 + ,15861.5 + ,13286.1 + ,15634.9 + ,14211 + ,13646.8 + ,12224.6 + ,15916.4 + ,16535.9 + ,15796 + ,14418.6 + ,15044.5 + ,14944.2 + ,16754.8 + ,14254 + ,15454.9 + ,15644.8 + ,14568.3 + ,12520.2 + ,14803 + ,15873.2 + ,14755.3 + ,12875.1 + ,14291.1 + ,14205.3 + ,15859.4 + ,15258.9 + ,15498.6 + ,15106.5 + ,15023.6 + ,12083 + ,15761.3 + ,16943 + ,15070.3 + ,13659.6 + ,14768.9 + ,14725.1 + ,15998.1 + ,15370.6 + ,14956.9 + ,15469.7 + ,15101.8 + ,11703.7 + ,16283.6 + ,16726.5 + ,14968.9 + ,14861 + ,14583.3 + ,15305.8 + ,17903.9 + ,16379.4 + ,15420.3 + ,17870.5 + ,15912.8 + ,13866.5 + ,17823.2 + ,17872 + ,17420.4 + ,16704.4 + ,15991.2 + ,16583.6 + ,19123.5 + ,17838.7 + ,17209.4 + ,18586.5 + ,16258.1 + ,15141.6 + ,19202.1 + ,17746.5 + ,19090.1 + ,18040.3 + ,17515.5 + ,17751.8 + ,21072.4 + ,17170 + ,19439.5 + ,19795.4 + ,17574.9 + ,16165.4 + ,19464.6 + ,19932.1 + ,19961.2 + ,17343.4 + ,18924.2 + ,18574.1 + ,21350.6 + ,18594.6 + ,19823.1 + ,20844.4 + ,19640.2 + ,17735.4 + ,19813.6 + ,22238.5 + ,20682.2 + ,17818.6 + ,21872.1 + ,22117 + ,21865.9 + ,23451.3 + ,20953.7 + ,22497.3) > par9 = '1' > par8 = '2' > par7 = '1' > par6 = '3' > par5 = '12' > par4 = '1' > par3 = '0' > 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] [,7] [1,] 0.04211056 0.3584354 0.5964025 0.04847581 0.1922005 -0.2212507 -0.8251823 [2,] 0.07389448 0.3455163 0.5779085 0.00000000 0.1889435 -0.2169528 -0.8302502 [3,] 0.00000000 0.3690578 0.6276283 0.00000000 0.1490322 -0.1981882 -0.8071397 [4,] 0.00000000 0.3560512 0.6392226 0.00000000 0.0000000 -0.2331852 -0.7157825 [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.72078 0 0 0.73997 0.14685 0.03981 0 [2,] 0.31594 0 0 NA 0.15472 0.04278 0 [3,] NA 0 0 NA 0.23743 0.05965 0 [4,] NA 0 0 NA NA 0.01699 0 [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.0421 0.3584 0.5964 0.0485 0.1922 -0.2213 -0.8252 s.e. 0.1176 0.0726 0.0911 0.1458 0.1318 0.1067 0.1274 sigma^2 estimated as 408686: log likelihood = -1190.42, aic = 2396.83 [[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.0421 0.3584 0.5964 0.0485 0.1922 -0.2213 -0.8252 s.e. 0.1176 0.0726 0.0911 0.1458 0.1318 0.1067 0.1274 sigma^2 estimated as 408686: log likelihood = -1190.42, aic = 2396.83 [[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.0739 0.3455 0.5779 0 0.1889 -0.2170 -0.8303 s.e. 0.0734 0.0622 0.0764 0 0.1321 0.1062 0.1289 sigma^2 estimated as 408347: log likelihood = -1190.47, aic = 2394.94 [[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 0.3691 0.6276 0 0.1490 -0.1982 -0.8071 s.e. 0 0.0572 0.0569 0 0.1257 0.1045 0.1158 sigma^2 estimated as 413916: log likelihood = -1190.99, aic = 2393.98 [[3]][[5]] NULL [[3]][[6]] NULL [[3]][[7]] NULL $aic [1] 2396.834 2394.942 2393.984 2393.396 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 log(s2) : NaNs produced > postscript(file="/var/www/html/rcomp/tmp/1zho71229261741.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 = 162 Frequency = 1 [1] 9.568278 9.920252 11.353417 9.247383 10.114057 [6] 10.762924 8.455900 8.071379 10.327752 10.551131 [11] 10.185805 8.821282 125.788698 89.376634 -507.613549 [16] 607.387115 355.990459 -141.486098 370.034489 -84.635411 [21] 233.226334 418.013113 129.295207 53.403896 -260.047405 [26] 126.534653 -48.894130 1109.361264 -170.847583 115.761582 [31] 584.479312 465.591300 257.012949 -267.380117 -422.781425 [36] -64.286565 -26.140274 -102.159477 17.134359 165.250822 [41] -104.576863 400.229562 324.623673 -503.292839 -608.128604 [46] -759.766730 -150.438066 354.850670 -516.512538 -771.683146 [51] 476.569761 611.962615 -241.164672 237.918318 838.340859 [56] 820.677986 715.397706 215.701442 422.716840 831.779988 [61] 136.107291 682.732786 1026.383130 -305.541349 1362.426077 [66] -938.363791 -245.096279 -860.253714 1070.130503 1116.324607 [71] 975.427053 -549.602002 -305.225314 -881.628875 -71.087579 [76] -1161.815669 -360.629220 -38.926781 406.974496 -402.791085 [81] -1416.650650 -500.205084 -32.661732 -715.751343 -60.745432 [86] 185.342394 553.733972 851.527877 1030.108661 -694.816891 [91] -86.528645 -800.535166 520.102943 988.149512 478.947247 [96] -916.299099 -410.973932 -108.170403 -309.690895 -175.083871 [101] -451.853130 -165.193608 240.684462 -790.772342 44.702262 [106] 252.293623 128.262401 132.776478 -283.781183 204.366957 [111] 1115.353397 1169.161501 -660.477230 594.052095 130.691382 [116] 323.732819 -45.012207 245.738589 680.558651 377.371489 [121] -501.532397 -797.163115 152.099495 830.096476 -85.309878 [126] -187.463210 -1082.270047 -33.319559 855.888051 -614.504996 [131] 815.091804 939.161717 611.372331 -830.982594 978.625701 [136] -1220.904043 508.124475 333.746479 227.198234 -635.566112 [141] -464.605827 575.198755 836.010542 -897.517707 18.349267 [146] -267.185251 809.714555 -418.858772 164.534444 465.681618 [151] 831.617326 529.814929 -1139.102700 586.316407 331.647495 [156] -965.836927 1485.889829 2543.179067 -139.686449 917.822915 [161] -960.303022 -93.180861 > postscript(file="/var/www/html/rcomp/tmp/26e481229261741.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/3nbsv1229261741.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/4aw061229261741.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/5fjw31229261741.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/63ho91229261741.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/7g1n11229261741.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/89lum1229261741.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/9bg2r1229261741.tab") > > system("convert tmp/1zho71229261741.ps tmp/1zho71229261741.png") > system("convert tmp/26e481229261741.ps tmp/26e481229261741.png") > system("convert tmp/3nbsv1229261741.ps tmp/3nbsv1229261741.png") > system("convert tmp/4aw061229261741.ps tmp/4aw061229261741.png") > system("convert tmp/5fjw31229261741.ps tmp/5fjw31229261741.png") > system("convert tmp/63ho91229261741.ps tmp/63ho91229261741.png") > system("convert tmp/7g1n11229261741.ps tmp/7g1n11229261741.png") > > > proc.time() user system elapsed 12.511 1.719 15.571