R version 2.6.0 (2007-10-03) Copyright (C) 2007 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(33259,33250,32875,32424,31867,31871,33140,33555,33324,32358,31857,32101,32810,32057,31663,31325,31103,31012,32511,33677,32213,31635,31043,31303,31899,31384,30650,30400,30003,29896,31557,31883,30830,30354,29756,29934,30599,30378,29925,29471,29567,29419,30796,31475,31708,31917,30871,31512,32362,31928,31699,30363,30386,30364,32806,33423,33071,33888,34805,35489,37259,37722,38764,39594,40004,40715,44028,45564,44277,44976,45406,47379,49200,50221,51573,53091,53337,54978,57885,67099,67169,69796,70600,71982,73957,75273,76322,77078,77954,79238,82179,83834,83744,84861,86478,88290,90287,91230,92380,92506,94172,94728,96581,97344,98346,98214,98366,98768) > par9 = '1' > par8 = '2' > par7 = '1' > par6 = '3' > par5 = '1' > 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, ncol=nrc) + pval <- matrix(NA, nrow=nrc, 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) + 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.14706254 0.5552925 0.22984761 -0.4055169 0.8059125 -0.63010859 [2,] 0.06188931 0.6057932 0.27491901 0.0000000 0.7527378 -0.57703539 [3,] 0.00000000 -0.1098541 -0.26618608 0.0000000 0.8997712 0.07672297 [4,] 0.00000000 0.3943383 0.06597701 0.0000000 -0.1872105 0.00000000 [5,] 0.00000000 0.3342227 0.08856074 0.0000000 0.0000000 0.00000000 [6,] 0.00000000 0.3438757 0.00000000 0.0000000 0.0000000 0.00000000 [7,] NA NA NA NA NA NA [,7] [1,] -0.4055169 [2,] -0.6732602 [3,] -0.7618869 [4,] 0.5140782 [5,] 0.3325604 [6,] 0.3539998 [7,] NA [[2]] [,1] [,2] [,3] [,4] [,5] [,6] [,7] [1,] 0.57852 0.00000 0.24758 0.66722 0.00000 0.00000 0.66722 [2,] 0.77116 0.00000 0.10876 NA 0.00000 0.00003 0.00044 [3,] NA 0.34083 0.01409 NA 0.00000 0.60440 0.00000 [4,] NA 0.01193 0.56520 NA 0.60605 NA 0.15766 [5,] NA 0.00068 0.33620 NA NA NA 0.00106 [6,] NA 0.00034 NA NA NA NA 0.00046 [7,] 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.1471 0.5553 0.2298 -0.4055 0.8059 -0.6301 -0.4055 s.e. 0.2638 0.0922 0.1976 0.9404 0.1230 0.1088 0.9404 sigma^2 estimated as 1236749: log likelihood = -902.96, aic = 1821.93 [[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.1471 0.5553 0.2298 -0.4055 0.8059 -0.6301 -0.4055 s.e. 0.2638 0.0922 0.1976 0.9404 0.1230 0.1088 0.9404 sigma^2 estimated as 1236749: log likelihood = -902.96, aic = 1821.93 [[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.0619 0.6058 0.2749 0 0.7527 -0.577 -0.6733 s.e. 0.2122 0.0757 0.1699 0 0.1234 0.131 0.1852 sigma^2 estimated as 1238789: log likelihood = -903.05, aic = 1820.1 [[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.1099 -0.2662 0 0.8998 0.0767 -0.7619 s.e. 0 0.1148 0.1066 0 0.1595 0.1476 0.1272 sigma^2 estimated as 1254638: log likelihood = -903.71, aic = 1819.41 [[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 0.3943 0.0660 0 -0.1872 0 0.5141 s.e. 0 0.1541 0.1143 0 0.3619 0 0.3612 sigma^2 estimated as 1533525: log likelihood = -913.99, aic = 1837.99 [[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 0.3342 0.0886 0 0 0 0.3326 s.e. 0 0.0954 0.0917 0 0 0 0.0987 sigma^2 estimated as 1537439: log likelihood = -914.13, aic = 1836.25 [[3]][[7]] NULL $aic [1] 1821.926 1820.101 1819.412 1837.986 1836.250 1835.183 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 > postscript(file="/var/www/html/rcomp/tmp/1xcf21197029392.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 = 108 Frequency = 1 [1] 33.258978 -7.912077 -361.373926 -323.127353 -323.416963 [6] 295.498891 1396.831608 -1.539420 -654.970843 -999.268593 [11] -128.230079 629.960867 752.495166 -1040.431515 -306.566331 [16] -47.168071 -7.943804 59.501983 1583.342954 689.517532 [21] -2186.246982 -373.396926 -81.782808 610.031341 642.175634 [26] -763.032139 -702.468198 102.955595 -140.310747 88.221048 [31] 1786.487749 -197.194698 -1533.088680 -222.211339 -201.035644 [36] 497.200941 741.670701 -474.182639 -533.327495 -261.666062 [41] 353.994564 -73.869485 1409.687267 251.156918 -297.642462 [46] -40.901214 -1170.404494 939.743035 868.566356 -844.452993 [51] -289.025040 -1170.105702 527.103204 269.508210 2463.002258 [56] -196.781089 -1100.781787 760.595766 727.060345 200.321968 [61] 1324.544542 -287.309596 485.398157 357.078185 -98.013704 [66] 373.910387 2978.115500 271.654417 -2547.587855 739.459190 [71] 478.200400 1694.325501 1051.914685 -26.327618 577.405732 [76] 823.467267 -570.142173 1203.522617 2290.102028 7882.157364 [81] -3668.207076 509.926904 -204.975729 565.964647 1285.418481 [86] 355.422133 148.319977 91.930173 378.282165 812.625779 [91] 2311.021857 379.724480 -1312.942156 740.036984 1254.405001 [96] 1029.478292 1015.275877 -143.454748 369.792672 -489.006167 [101] 1360.755271 -40.490261 1298.491860 -2.196997 334.176282 [106] -662.248741 -30.225218 367.431244 > postscript(file="/var/www/html/rcomp/tmp/2je4m1197029392.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/3ahxg1197029392.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/4yubt1197029392.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/57uth1197029392.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/659mi1197029392.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/7imsj1197029392.ps",horizontal=F,pagecentre=F,paper="special",width=8.3333333333333,height=5.5555555555556) > qqnorm(resid, main='Residual Normal Q-Q Plot') > dev.off() null device 1 > ncols <- length(selection[[1]][1,]) > nrows <- length(selection[[2]][,1])-1 > 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/85h611197029392.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/91w651197029392.tab") > > system("convert tmp/1xcf21197029392.ps tmp/1xcf21197029392.png") > system("convert tmp/2je4m1197029392.ps tmp/2je4m1197029392.png") > system("convert tmp/3ahxg1197029392.ps tmp/3ahxg1197029392.png") > system("convert tmp/4yubt1197029392.ps tmp/4yubt1197029392.png") > system("convert tmp/57uth1197029392.ps tmp/57uth1197029392.png") > system("convert tmp/659mi1197029392.ps tmp/659mi1197029392.png") > system("convert tmp/7imsj1197029392.ps tmp/7imsj1197029392.png") > > > proc.time() user system elapsed 2.534 1.063 2.840