R version 2.15.2 (2012-10-26) -- "Trick or Treat" Copyright (C) 2012 The R Foundation for Statistical Computing ISBN 3-900051-07-0 Platform: i686-pc-linux-gnu (32-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(14,14,15,13,8,7,3,3,4,4,0,-4,-14,-18,-8,-1,1,2,0,1,0,-1,-3,-3,-3,-4,-8,-9,-13,-18,-11,-9,-10,-13,-11,-5,-15,-6,-6,-3,-1,-3,-4,-6,0,-4,-2,-2,-6,-7,-6,-6,-3,-2,-5,-11,-11,-11,-10,-14,-8,-9,-5,-1,-2,-5,-4,-6,-2,-2,-2,-2,2,1,-8,-1,1,-1,2,2,1,-1,-2,-2,-1,-8,-4,-6,-3,-3,-7,-9,-11,-13,-11,-9,-17,-22,-25,-20,-24,-24,-22,-19,-18,-17,-11,-11,-12,-10,-15,-15,-15,-13,-8,-13,-9,-7,-4,-4,-2,0,-2,-3,1,-2,-1,1,-3,-4,-9,-9,-7,-14,-12,-16,-20,-12,-12,-10,-10,-13,-16) > par9 = '1' > par8 = '2' > par7 = '1' > par6 = '3' > par5 = '4' > par4 = '0' > par3 = '1' > par2 = '1' > par1 = 'FALSE' > par9 <- '1' > par8 <- '2' > par7 <- '1' > par6 <- '3' > par5 <- '4' > 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.05221068 -0.06146662 -0.0007764341 -0.05131286 0.7175927 0.07640502 [2,] -0.05493709 -0.06170608 0.0000000000 -0.04847526 0.7174729 0.07646314 [3,] -0.10315525 -0.06624733 0.0000000000 0.00000000 0.7169596 0.07672905 [4,] -0.09649914 0.00000000 0.0000000000 0.00000000 0.7264099 0.07917769 [5,] -0.09540111 0.00000000 0.0000000000 0.00000000 0.1463967 0.00000000 [6,] -0.09571984 0.00000000 0.0000000000 0.00000000 0.0000000 0.00000000 [7,] 0.00000000 0.00000000 0.0000000000 0.00000000 0.0000000 0.00000000 [8,] 0.00000000 0.00000000 0.0000000000 0.00000000 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.8570783 [2,] -0.8569724 [3,] -0.8566307 [4,] -0.8592307 [5,] -0.2747468 [6,] -0.1302496 [7,] -0.1331647 [8,] 0.0000000 [9,] NA [10,] NA [11,] NA [12,] NA [13,] NA [14,] NA [[2]] [,1] [,2] [,3] [,4] [,5] [,6] [,7] [1,] 0.99600 0.95492 0.99915 0.99607 0.00286 0.46017 0.00011 [2,] 0.96338 0.67105 NA 0.96777 0.00243 0.44058 0.00011 [3,] 0.22020 0.43898 NA NA 0.00259 0.43616 0.00012 [4,] 0.24966 NA NA NA 0.00443 0.42022 0.00037 [5,] 0.25509 NA NA NA 0.82637 NA 0.67284 [6,] 0.25349 NA NA NA NA NA 0.12683 [7,] NA NA NA NA NA NA 0.11851 [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.0522 -0.0615 -0.0008 -0.0513 0.7176 0.0764 -0.8571 s.e. 10.3968 1.0853 0.7308 10.3938 0.2362 0.1032 0.2150 sigma^2 estimated as 12.39: log likelihood = -380.26, aic = 776.52 [[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.0522 -0.0615 -0.0008 -0.0513 0.7176 0.0764 -0.8571 s.e. 10.3968 1.0853 0.7308 10.3938 0.2362 0.1032 0.2150 sigma^2 estimated as 12.39: log likelihood = -380.26, aic = 776.52 [[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.0549 -0.0617 0 -0.0485 0.7175 0.0765 -0.8570 s.e. 1.1945 0.1450 0 1.1974 0.2323 0.0989 0.2152 sigma^2 estimated as 12.39: log likelihood = -380.26, aic = 774.52 [[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.1032 -0.0662 0 0 0.7170 0.0767 -0.8566 s.e. 0.0838 0.0854 0 0 0.2336 0.0982 0.2168 sigma^2 estimated as 12.39: log likelihood = -380.26, aic = 772.52 [[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.0965 0 0 0 0.7264 0.0792 -0.8592 s.e. 0.0835 0 0 0 0.2510 0.0979 0.2355 sigma^2 estimated as 12.44: log likelihood = -380.56, aic = 771.13 [[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.0954 0 0 0 0.1464 0 -0.2747 s.e. 0.0835 0 0 0 0.6661 0 0.6493 sigma^2 estimated as 12.47: log likelihood = -380.71, aic = 769.42 [[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.0957 0 0 0 0 0 -0.1302 s.e. 0.0835 0 0 0 0 0 0.0848 sigma^2 estimated as 12.48: log likelihood = -380.73, aic = 767.46 [[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 0 0 0 0 0 -0.1332 s.e. 0 0 0 0 0 0 0.0848 sigma^2 estimated as 12.59: log likelihood = -381.38, aic = 766.77 $aic [1] 776.5204 774.5206 772.5229 771.1252 769.4167 767.4579 766.7665 767.1871 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/fisher/rcomp/tmp/1zf991353511760.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 = 143 Frequency = 1 [1] 0.01399999 0.00000000 0.99124978 -1.98249956 -4.95624710 [6] -0.99984555 -3.86855791 -0.26164857 0.34572435 -0.13312324 [11] -4.51506358 -4.03482593 -9.95394156 -4.01772708 9.39875392 [16] 6.46270461 0.67448956 0.46498044 -0.74841744 1.86060434 [21] -0.91018178 -0.93808100 -2.09966281 0.24776689 -0.12120412 [26] -1.12491931 -4.27960105 -0.96700619 -4.01614012 -5.14979959 [31] 6.43010804 1.87122887 -1.53480825 -3.68577172 2.85626366 [36] 6.24918171 -10.20438234 8.50918517 0.38035361 3.83217066 [41] 0.64113608 -0.86687657 -0.94935031 -1.48968999 6.08537672 [46] -4.11543739 1.87358001 -0.19837418 -3.18964239 -1.54803115 [51] 1.24949480 -0.02641645 2.57525210 0.79385683 -2.83361135 [56] -6.00351774 0.34293278 0.10571374 0.62266288 -4.79945688 [61] 6.04566655 -0.98592266 4.08291674 3.36088157 -0.19493039 [66] -3.13129013 1.54370055 -1.55244908 3.97404215 -0.41697744 [71] 0.20556648 -0.20673148 4.52920229 -1.05552669 -8.97262579 [76] 6.97247066 2.60313004 -2.14055894 1.80516262 0.92848724 [81] -0.65335486 -2.28504697 -0.75961599 0.12364176 0.91299617 [86] -7.30428769 3.89884593 -1.98353528 3.12157890 -0.97267357 [91] -3.48081120 -2.26413696 -1.58431576 -2.12952582 1.53647868 [96] 1.69849679 -8.21097500 -5.28357775 -2.79539522 5.22617988 [101] -5.09341235 -0.70358626 1.62775192 3.69594288 0.32173707 [106] 0.90630712 6.21675916 0.49216927 -0.95715597 2.12068815 [111] -4.17214688 0.06553959 -0.12745943 2.28240089 4.44441715 [116] -4.99127244 3.98302690 2.30393532 3.59183965 -0.66466150 [121] 2.53039874 2.30680295 -1.52169361 -1.08850948 4.33695989 [126] -2.69281519 0.79736407 1.85504892 -3.42246986 -1.35858803 [131] -4.89381922 0.24702711 1.54424769 -7.18091602 1.34831584 [136] -3.96710470 -3.79436066 7.04375519 0.17954813 1.47172153 [141] -0.50527505 -2.06202017 -2.97609052 > postscript(file="/var/fisher/rcomp/tmp/2dhpw1353511760.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/fisher/rcomp/tmp/3ftxy1353511760.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/fisher/rcomp/tmp/4w2wv1353511760.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/fisher/rcomp/tmp/52lmg1353511760.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/fisher/rcomp/tmp/609zy1353511760.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/fisher/rcomp/tmp/7aql61353511760.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/fisher/rcomp/createtable file can be downloaded at http://www.wessa.net/cretab > load(file="/var/fisher/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/fisher/rcomp/tmp/8m0mf1353511760.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/fisher/rcomp/tmp/9if0f1353511760.tab") > > try(system("convert tmp/1zf991353511760.ps tmp/1zf991353511760.png",intern=TRUE)) character(0) > try(system("convert tmp/2dhpw1353511760.ps tmp/2dhpw1353511760.png",intern=TRUE)) character(0) > try(system("convert tmp/3ftxy1353511760.ps tmp/3ftxy1353511760.png",intern=TRUE)) character(0) > try(system("convert tmp/4w2wv1353511760.ps tmp/4w2wv1353511760.png",intern=TRUE)) character(0) > try(system("convert tmp/52lmg1353511760.ps tmp/52lmg1353511760.png",intern=TRUE)) character(0) > try(system("convert tmp/609zy1353511760.ps tmp/609zy1353511760.png",intern=TRUE)) character(0) > try(system("convert tmp/7aql61353511760.ps tmp/7aql61353511760.png",intern=TRUE)) character(0) > > > proc.time() user system elapsed 5.066 0.908 6.021