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(112,118,132,129,121,135,148,148,136,119,104,118,115,126,141,135,125,149,170,170,158,133,114,140,145,150,178,163,172,178,199,199,184,162,146,166,171,180,193,181,183,218,230,242,209,191,172,194,196,196,236,235,229,243,264,272,237,211,180,201,204,188,235,227,234,264,302,293,259,229,203,229,242,233,267,269,270,315,364,347,312,274,237,278,284,277,317,313,318,374,413,405,355,306,271,306,315,301,356,348,355,422,465,467,404,347,305,336,340,318,362,348,363,435,491,505,404,359,310,337,360,342,406,396,420,472,548,559,463,407,362,405,417,391,419,461,472,535,622,606,508,461,390,432) > par9 = '1' > par8 = '2' > par7 = '1' > par6 = '3' > par5 = '12' > par4 = '1' > par3 = '1' > par2 = '0.0' > par1 = 'FALSE' > par9 <- '1' > par8 <- '2' > par7 <- '1' > par6 <- '3' > par5 <- '12' > par4 <- '1' > par3 <- '1' > par2 <- '0.0' > 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.24459764 0.1087535 -0.08699510 -0.6399706 -0.07894928 -0.0177612 [2,] 0.23996903 0.1078988 -0.08810641 -0.6358814 -0.06138125 0.0000000 [3,] 0.24461403 0.1085345 -0.09603517 -0.6342239 0.00000000 0.0000000 [4,] 0.05533228 0.0000000 -0.11985784 -0.4380604 0.00000000 0.0000000 [5,] 0.00000000 0.0000000 -0.12424128 -0.3908355 0.00000000 0.0000000 [6,] 0.00000000 0.0000000 0.00000000 -0.4018280 0.00000000 0.0000000 [7,] NA NA NA NA NA NA [8,] NA NA NA NA NA NA [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.5091497 [2,] -0.5257727 [3,] -0.5666181 [4,] -0.5555164 [5,] -0.5525518 [6,] -0.5569448 [7,] NA [8,] NA [9,] NA [10,] NA [11,] NA [12,] NA [13,] NA [14,] NA [[2]] [,1] [,2] [,3] [,4] [,5] [,6] [,7] [1,] 0.45359 0.47900 0.42342 0.04468 0.71815 0.90546 0.01169 [2,] 0.45494 0.48042 0.41313 0.04302 0.69664 NA 0.00018 [3,] 0.44972 0.47615 0.36384 0.04627 NA NA 0.00000 [4,] 0.80797 NA 0.18546 0.03580 NA NA 0.00000 [5,] NA NA 0.15402 0.00000 NA NA 0.00000 [6,] NA NA NA 0.00002 NA NA 0.00000 [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.2446 0.1088 -0.0870 -0.6400 -0.0789 -0.0178 -0.5091 s.e. 0.3254 0.1532 0.1083 0.3158 0.2183 0.1493 0.1992 sigma^2 estimated as 0.001316: log likelihood = 246.1, aic = -476.19 [[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.2446 0.1088 -0.0870 -0.6400 -0.0789 -0.0178 -0.5091 s.e. 0.3254 0.1532 0.1083 0.3158 0.2183 0.1493 0.1992 sigma^2 estimated as 0.001316: log likelihood = 246.1, aic = -476.19 [[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.2400 0.1079 -0.0881 -0.6359 -0.0614 0 -0.5258 s.e. 0.3202 0.1525 0.1073 0.3113 0.1571 0 0.1365 sigma^2 estimated as 0.001317: log likelihood = 246.09, aic = -478.18 [[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.2446 0.1085 -0.0960 -0.6342 0 0 -0.5666 s.e. 0.3227 0.1519 0.1054 0.3154 0 0 0.0784 sigma^2 estimated as 0.001319: log likelihood = 246.01, aic = -480.03 [[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.0553 0 -0.1199 -0.4381 0 0 -0.5555 s.e. 0.2272 0 0.0901 0.2067 0 0 0.0764 sigma^2 estimated as 0.001326: log likelihood = 245.75, aic = -481.5 [[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 -0.1242 -0.3908 0 0 -0.5526 s.e. 0 0 0.0867 0.0818 0 0 0.0754 sigma^2 estimated as 0.001328: log likelihood = 245.72, aic = -483.44 [[3]][[7]] NULL $aic [1] -476.1941 -478.1793 -480.0266 -481.4961 -483.4354 -483.3991 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 > postscript(file="/var/fisher/rcomp/tmp/1usdb1353762392.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 = 144 Frequency = 1 [1] 2.724226e-03 1.258734e-03 9.187905e-04 6.645510e-04 4.722181e-04 [6] 4.936198e-04 5.082994e-04 4.444945e-04 3.149602e-04 1.563668e-04 [11] 1.337920e-05 -2.609795e-03 -1.678783e-02 3.165145e-02 1.171253e-02 [16] -1.479418e-02 -1.277011e-02 5.293483e-02 5.330943e-02 1.964003e-02 [21] 2.480238e-02 -1.927535e-02 -2.632714e-02 6.029057e-02 6.897997e-02 [26] -1.650822e-02 5.807758e-02 -2.301845e-02 1.070547e-01 -6.062303e-02 [31] -3.342015e-02 2.014464e-03 -1.308652e-02 2.217760e-02 4.880954e-02 [36] -2.371823e-02 1.265883e-02 6.051776e-03 -7.313385e-02 -2.984199e-02 [41] 9.495355e-03 7.640643e-02 -2.969946e-02 4.144827e-02 -4.140278e-02 [46] 2.799052e-02 3.763384e-02 -2.400852e-02 -1.225937e-02 -5.531682e-02 [51] 5.190273e-02 7.696033e-02 -1.485299e-03 -6.188825e-02 -2.003006e-02 [56] -4.406890e-03 -3.861969e-02 -1.343924e-02 -4.720608e-02 -4.852393e-02 [61] -1.922129e-02 -1.236081e-01 2.831459e-02 1.248008e-02 3.355315e-02 [66] 4.524881e-02 6.774471e-02 -2.471549e-02 -7.972366e-03 -2.706807e-03 [71] 6.773407e-03 -1.981311e-03 3.866661e-02 -4.580798e-04 -4.354269e-02 [76] 3.086096e-02 6.671878e-03 4.305823e-02 5.978544e-02 -2.576751e-02 [81] 1.204179e-02 -5.804422e-04 -2.263140e-02 2.975254e-02 -1.298607e-03 [86] 7.887518e-04 -2.012052e-02 -5.784049e-03 8.506967e-03 3.355602e-02 [91] -1.104818e-02 -1.683002e-03 -1.288894e-02 -3.225239e-02 2.130920e-03 [96] -1.909998e-02 -9.289082e-03 -2.048710e-02 8.909029e-03 -4.449903e-03 [101] 5.729229e-03 3.371637e-02 -3.578000e-03 2.441444e-02 -9.033056e-03 [106] -2.239208e-02 -5.192977e-03 -3.934181e-02 -3.397840e-02 -4.496295e-02 [111] -4.951818e-02 -4.258037e-02 7.106793e-03 2.347596e-02 2.190658e-02 [116] 4.941526e-02 -6.817782e-02 -8.073054e-05 -1.284245e-02 -4.864329e-02 [121] 2.912065e-02 7.272112e-03 2.548958e-02 1.836317e-02 3.887761e-02 [126] -3.237535e-02 2.438119e-02 2.592971e-02 -1.146616e-02 2.879349e-03 [131] 2.260403e-02 1.777611e-02 -4.623577e-03 -1.348777e-02 -9.156695e-02 [136] 8.474551e-02 1.375247e-02 -2.506612e-02 2.701064e-02 -3.069604e-02 [141] -1.084460e-02 3.183024e-02 -3.148079e-02 -1.583322e-02 > postscript(file="/var/fisher/rcomp/tmp/2wi1j1353762392.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/3q62h1353762392.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/4ztnx1353762392.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/5r8d31353762392.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/68oin1353762392.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/79o721353762392.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/8t9zg1353762392.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/9w1w71353762392.tab") > > try(system("convert tmp/1usdb1353762392.ps tmp/1usdb1353762392.png",intern=TRUE)) character(0) > try(system("convert tmp/2wi1j1353762392.ps tmp/2wi1j1353762392.png",intern=TRUE)) character(0) > try(system("convert tmp/3q62h1353762392.ps tmp/3q62h1353762392.png",intern=TRUE)) character(0) > try(system("convert tmp/4ztnx1353762392.ps tmp/4ztnx1353762392.png",intern=TRUE)) character(0) > try(system("convert tmp/5r8d31353762392.ps tmp/5r8d31353762392.png",intern=TRUE)) character(0) > try(system("convert tmp/68oin1353762392.ps tmp/68oin1353762392.png",intern=TRUE)) character(0) > try(system("convert tmp/79o721353762392.ps tmp/79o721353762392.png",intern=TRUE)) character(0) > > > proc.time() user system elapsed 11.551 1.740 13.283