R version 2.12.0 (2010-10-15) Copyright (C) 2010 The R Foundation for Statistical Computing ISBN 3-900051-07-0 Platform: i486-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(2.4,2.4,2.5,2.6,2.4,2.6,2.4,2.3,2.4,2.4,2.4,2.4,2.4,2.4,2.4,2.4,2.5,2.1,2.1,2,2,2,1.9,1.9,2,1.8,1.6,1.3,1.4,1.4,1.5,1.7,1.6,1.5,1.6,1.5,1.1,1.1,1.1,1.4,1.3,1.4,1.3,1.1,1,0.9,0.8,0.8,0.8,0.8,1,1.1,1,0.9,1.1,1.2,1.2,1.4,1.5,1.7,1.9,1.9,1.9,1.7,1.7,2.1,2,2,2.5,2.4,2.5,2.5,2,1.9,2.2,2.7,3.1,2.8,2.6,2.3,2.2,2.2,2,2,2.6,2.5,2.5,2.3,2,1.9,2,2.1,2.1,2.3,2.3,2.3,2.1,2.4,2.5,2.1,1.8,1.9,1.9,2.1,2.2,2,2.2,2,1.9,1.6,1.7,2,2.5,2.4,2.3,2.3,2.1,2.4,2.2,2.4,1.9,2.1,2.1,2.1,2,2.1,2.2,2.2,2.6,2.5,2.3,2.2,2.4,2.3,2.2,2.5,2.5,2.5,2.4,2.3,1.7,1.6,1.9,1.9,1.8,1.8,1.9,1.9,1.9,1.9,1.8,1.7,2.1,2.6,3.1,3.1,3.2,3.3,3.6,3.3,3.7,4,4,3.8,3.6,3.2,2.1,1.6,1.1,1.2,0.6,0.6,0,-0.1,-0.6,-0.2,-0.3,-0.1,0.5,0.9) > par9 = '1' > par8 = '2' > par7 = '1' > par6 = '3' > par5 = '12' > 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.4834042 0.1869879 -0.06744162 0.6570870 -0.5158958 -0.2862388 [2,] -0.4814376 0.1940204 -0.06103865 0.6513653 -0.6750886 -0.3684627 [3,] -0.5466909 0.2271881 0.00000000 0.7061494 -0.6690749 -0.3701833 [4,] NA NA NA NA NA NA [5,] NA NA NA NA NA NA [6,] NA NA NA NA NA NA [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.1847725 [2,] 0.0000000 [3,] 0.0000000 [4,] NA [5,] NA [6,] NA [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.01079 0.03190 0.41726 0.00021 0.02288 0.04812 0.4417 [2,] 0.00988 0.02429 0.46148 0.00018 0.00000 0.00000 NA [3,] 0.00074 0.00232 NA 0.00000 0.00000 0.00000 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 -0.4834 0.1870 -0.0674 0.6571 -0.5159 -0.2862 -0.1848 s.e. 0.1875 0.0864 0.0829 0.1735 0.2247 0.1438 0.2396 sigma^2 estimated as 0.03602: log likelihood = 39.99, aic = -63.99 [[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.4834 0.1870 -0.0674 0.6571 -0.5159 -0.2862 -0.1848 s.e. 0.1875 0.0864 0.0829 0.1735 0.2247 0.1438 0.2396 sigma^2 estimated as 0.03602: log likelihood = 39.99, aic = -63.99 [[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.4814 0.1940 -0.0610 0.6514 -0.6751 -0.3685 0 s.e. 0.1845 0.0854 0.0827 0.1699 0.0739 0.0767 0 sigma^2 estimated as 0.03614: log likelihood = 39.74, aic = -65.47 [[3]][[4]] NULL [[3]][[5]] NULL [[3]][[6]] NULL [[3]][[7]] NULL $aic [1] -63.98539 -65.47139 -66.95457 Warning message: In arima(series, order = order, seasonal = seasonal, include.mean = include.mean, : some AR parameters were fixed: setting transform.pars = FALSE > postscript(file="/var/www/rcomp/tmp/12coh1323212113.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 = 180 Frequency = 1 [1] 2.399998e-03 -5.210156e-07 8.026004e-02 6.761125e-02 -1.821776e-01 [6] 1.924727e-01 -1.744227e-01 -8.489806e-02 1.374333e-01 -4.333209e-02 [11] 5.757844e-03 2.054571e-03 -1.113778e-02 5.672418e-04 4.747388e-02 [16] 3.664119e-02 -9.742819e-03 -2.791476e-01 -4.232139e-02 -1.007312e-01 [21] 4.514673e-02 1.442979e-02 -1.203987e-01 3.631296e-02 8.268871e-02 [26] -2.156083e-01 -1.343697e-01 -2.106070e-01 1.234634e-01 -1.903929e-01 [31] 2.149445e-02 1.381253e-01 -1.241583e-01 -6.648454e-02 4.574368e-02 [36] -9.860591e-02 -3.288141e-01 -5.952823e-02 -1.028395e-01 1.053583e-01 [41] 6.106701e-04 -7.283926e-02 -2.754474e-03 -1.062173e-01 -1.439351e-01 [46] -1.366260e-01 -3.470436e-02 -5.600967e-02 -2.259794e-01 -2.989762e-02 [51] 1.514262e-01 1.542275e-01 -1.676952e-01 -1.570608e-02 2.009952e-01 [56] -1.239264e-02 -1.125016e-01 1.215165e-01 5.884052e-02 1.332819e-01 [61] 3.673318e-02 -2.601880e-02 1.517158e-01 -5.256057e-02 -1.068839e-01 [66] 4.012179e-01 -6.644795e-02 -4.181079e-02 5.103094e-01 -1.101586e-01 [71] 1.112971e-01 1.540536e-01 -4.257877e-01 -1.659359e-02 4.154126e-01 [76] 3.082769e-01 2.772004e-01 -1.276869e-01 -1.887429e-01 -1.983946e-01 [81] 2.736058e-01 -1.844401e-02 -1.428050e-01 1.339634e-01 3.033020e-01 [86] -2.233708e-01 2.066560e-01 7.976531e-02 -1.006990e-01 -1.040023e-01 [91] -6.910031e-02 -6.384347e-02 1.134212e-01 1.609754e-01 -1.533816e-01 [96] 2.811344e-02 3.151565e-02 1.791488e-01 1.839984e-01 -4.059634e-01 [101] -2.884997e-01 1.980324e-02 -9.164753e-03 1.534281e-01 3.522312e-02 [106] -8.835364e-02 1.499012e-01 -2.203686e-01 4.840184e-03 -9.766998e-02 [111] 1.569581e-01 -4.011013e-02 1.513098e-01 -5.918940e-02 -9.691965e-02 [116] 2.294526e-01 -1.911860e-01 2.622206e-01 -8.468032e-02 3.446033e-02 [121] -6.051865e-01 1.769369e-01 1.694782e-01 -6.510490e-02 1.823057e-01 [126] 7.406166e-03 3.977276e-02 5.772778e-02 2.976334e-01 -3.203703e-02 [131] -2.806384e-01 3.114033e-02 -1.608314e-01 -6.316649e-02 -2.689329e-02 [136] 4.016597e-01 6.038755e-02 -3.598487e-02 -2.872380e-02 -1.134965e-01 [141] -3.625487e-01 1.566419e-05 1.360658e-01 -5.207991e-02 -1.335030e-01 [146] 2.567828e-02 4.807018e-02 1.765502e-01 -6.026756e-02 2.105222e-02 [151] -1.071252e-01 -1.700351e-01 2.000420e-01 3.583930e-01 5.480278e-01 [156] -1.591436e-01 9.424816e-02 9.841667e-02 2.741111e-01 -2.145861e-01 [161] 3.882597e-01 2.966186e-01 -2.423035e-01 -2.305581e-01 -1.088340e-01 [166] -4.844725e-02 -6.574399e-01 -3.755766e-01 -3.449948e-01 2.234879e-01 [171] -3.650126e-01 -1.995373e-01 -2.173032e-01 1.024951e-01 -5.025900e-01 [176] 2.570149e-01 -3.479279e-02 1.763768e-02 1.160511e-01 -2.059719e-02 > postscript(file="/var/www/rcomp/tmp/2k7b61323212113.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/www/rcomp/tmp/3l2qz1323212113.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/www/rcomp/tmp/44xu91323212113.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/www/rcomp/tmp/5f2031323212113.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/www/rcomp/tmp/63q3d1323212113.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/www/rcomp/tmp/7qpce1323212113.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/www/rcomp/createtable file can be downloaded at http://www.wessa.net/cretab > load(file="/var/www/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/rcomp/tmp/8ng0q1323212114.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/rcomp/tmp/9sp7d1323212114.tab") > > try(system("convert tmp/12coh1323212113.ps tmp/12coh1323212113.png",intern=TRUE)) character(0) > try(system("convert tmp/2k7b61323212113.ps tmp/2k7b61323212113.png",intern=TRUE)) character(0) > try(system("convert tmp/3l2qz1323212113.ps tmp/3l2qz1323212113.png",intern=TRUE)) character(0) > try(system("convert tmp/44xu91323212113.ps tmp/44xu91323212113.png",intern=TRUE)) character(0) > try(system("convert tmp/5f2031323212113.ps tmp/5f2031323212113.png",intern=TRUE)) character(0) > try(system("convert tmp/63q3d1323212113.ps tmp/63q3d1323212113.png",intern=TRUE)) character(0) > try(system("convert tmp/7qpce1323212113.ps tmp/7qpce1323212113.png",intern=TRUE)) character(0) > > > proc.time() user system elapsed 5.340 0.510 5.871