R version 2.9.0 (2009-04-17) Copyright (C) 2009 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(0.8973,0.9383,0.9217,0.9095,0.892,0.8742,0.8532,0.8607,0.9005,0.9111,0.9059,0.8883,0.8924,0.8833,0.87,0.8758,0.8858,0.917,0.9554,0.9922,0.9778,0.9808,0.9811,1.0014,1.0183,1.0622,1.0773,1.0807,1.0848,1.1582,1.1663,1.1372,1.1139,1.1222,1.1692,1.1702,1.2286,1.2613,1.2646,1.2262,1.1985,1.2007,1.2138,1.2266,1.2176,1.2218,1.249,1.2991,1.3408,1.3119,1.3014,1.3201,1.2938,1.2694,1.2165,1.2037,1.2292,1.2256,1.2015,1.1786,1.1856,1.2103,1.1938,1.202,1.2271,1.277,1.265,1.2684,1.2811,1.2727,1.2611,1.2881,1.3213,1.2999,1.3074,1.3242,1.3516,1.3511,1.3419,1.3716,1.3622,1.3896,1.4227,1.4684,1.457,1.4718,1.4748,1.5527,1.575,1.5557,1.5553,1.577,1.4975,1.4369,1.3322,1.2732,1.3449,1.3239,1.2785,1.305,1.319,1.365,1.4016,1.4088,1.4268,1.4562,1.4816,1.4914,1.4614,1.4272,1.3686,1.3569,1.3406,1.2565,1.2208,1.277,1.2894,1.3067,1.3898,1.3661) > par9 = '1' > par8 = '2' > par7 = '1' > par6 = '3' > par5 = '12' > par4 = '0' > par3 = '1' > par2 = '-0.6' > 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.2813737 -0.1616086 0.08818057 0.1355756 0.78094105 0.1849933 [2,] 0.4140411 -0.2140151 0.11022957 0.0000000 0.79261614 0.1836119 [3,] 0.3937828 -0.1638659 0.00000000 0.0000000 0.77070529 0.1608766 [4,] 0.3670182 -0.1471072 0.00000000 0.0000000 -0.18588479 0.0000000 [5,] 0.3649003 -0.1466093 0.00000000 0.0000000 -0.08964754 0.0000000 [6,] 0.3663257 -0.1506197 0.00000000 0.0000000 0.00000000 0.0000000 [7,] 0.3141967 0.0000000 0.00000000 0.0000000 0.00000000 0.0000000 [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.91863664 [2,] -0.93475070 [3,] -0.88144840 [4,] 0.09548215 [5,] 0.00000000 [6,] 0.00000000 [7,] 0.00000000 [8,] NA [9,] NA [10,] NA [11,] NA [12,] NA [13,] NA [14,] NA [[2]] [,1] [,2] [,3] [,4] [,5] [,6] [,7] [1,] 0.64950 0.54427 0.55518 0.82736 0.00615 0.11134 0.01101 [2,] 0.00004 0.04762 0.27063 NA 0.02802 0.11446 0.07245 [3,] 0.00008 0.09267 NA NA 0.05043 0.16049 0.04192 [4,] 0.00017 0.12752 NA NA 0.75907 NA 0.87452 [5,] 0.00016 0.12860 NA NA 0.37949 NA NA [6,] 0.00015 0.11727 NA NA NA NA NA [7,] 0.00055 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.2814 -0.1616 0.0882 0.1356 0.7809 0.1850 -0.9186 s.e. 0.6175 0.2657 0.1490 0.6202 0.2796 0.1153 0.3553 sigma^2 estimated as 0.0001591: log likelihood = 349.94, aic = -683.88 [[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.2814 -0.1616 0.0882 0.1356 0.7809 0.1850 -0.9186 s.e. 0.6175 0.2657 0.1490 0.6202 0.2796 0.1153 0.3553 sigma^2 estimated as 0.0001591: log likelihood = 349.94, aic = -683.88 [[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.4140 -0.2140 0.1102 0 0.7926 0.1836 -0.9348 s.e. 0.0975 0.1069 0.0996 0 0.3561 0.1154 0.5155 sigma^2 estimated as 0.0001586: log likelihood = 349.92, aic = -685.84 [[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.3938 -0.1639 0 0 0.7707 0.1609 -0.8814 s.e. 0.0964 0.0966 0 0 0.3898 0.1139 0.4284 sigma^2 estimated as 0.0001627: log likelihood = 349.3, aic = -686.61 [[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.3670 -0.1471 0 0 -0.1859 0 0.0955 s.e. 0.0946 0.0958 0 0 0.6046 0 0.6033 sigma^2 estimated as 0.0001666: log likelihood = 348.67, aic = -687.34 [[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.3649 -0.1466 0 0 -0.0896 0 0 s.e. 0.0936 0.0958 0 0 0.1016 0 0 sigma^2 estimated as 0.0001666: log likelihood = 348.66, aic = -689.32 [[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.3663 -0.1506 0 0 0 0 0 s.e. 0.0936 0.0955 0 0 0 0 0 sigma^2 estimated as 0.0001678: log likelihood = 348.27, aic = -690.55 $aic [1] -683.8804 -685.8407 -686.6054 -687.3442 -689.3205 -690.5462 -690.0845 Warning messages: 1: In log(s2) : NaNs produced 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 > postscript(file="/var/www/html/rcomp/tmp/10os61293388002.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 = 120 Frequency = 1 [1] 1.067179e-03 -2.645477e-02 1.994413e-02 7.954049e-05 1.100934e-02 [6] 9.753947e-03 1.302653e-02 -9.633945e-03 -2.476822e-02 2.406581e-03 [11] 1.957435e-03 1.010968e-02 -7.017173e-03 9.582426e-03 6.985721e-03 [16] -6.939547e-03 -4.282815e-03 -2.006549e-02 -1.861948e-02 -1.699177e-02 [21] 1.343590e-02 -8.574764e-03 1.829459e-03 -1.256572e-02 -5.485299e-03 [26] -2.293974e-02 -5.759210e-04 -2.552450e-03 -2.729563e-03 -3.616376e-02 [31] 9.291615e-03 9.803137e-03 5.892560e-03 -6.306402e-03 -1.942267e-02 [36] 7.218107e-03 -2.945270e-02 -4.290402e-03 -2.473637e-04 1.463802e-02 [41] 6.067015e-03 -3.017821e-03 -3.613986e-03 -3.604108e-03 5.087993e-03 [46] -4.110450e-03 -1.037571e-02 -1.642138e-02 -1.032660e-02 1.384208e-02 [51] -2.353701e-03 -7.119468e-03 1.356752e-02 4.980760e-03 2.036185e-02 [56] -1.069493e-03 -9.880234e-03 6.505590e-03 8.355233e-03 6.749614e-03 [61] -5.426122e-03 -8.357431e-03 1.095788e-02 -8.059308e-03 -8.574572e-03 [66] -1.741398e-02 1.090034e-02 -6.342780e-03 -3.916678e-03 5.091158e-03 [71] 2.739802e-03 -1.222160e-02 -8.273846e-03 1.144321e-02 -7.956202e-03 [76] -4.164702e-03 -8.382545e-03 2.986876e-03 1.807163e-03 -1.216650e-02 [81] 7.944068e-03 -1.276773e-02 -7.382708e-03 -1.247748e-02 7.559603e-03 [86] -8.477825e-03 1.359343e-03 -2.445985e-02 2.135490e-03 4.422455e-03 [91] -2.938239e-03 -5.543514e-03 2.632901e-02 9.952817e-03 3.375992e-02 [96] 1.247539e-02 -3.084441e-02 2.168363e-02 1.075629e-02 -1.591045e-02 [101] 1.120350e-03 -1.683955e-02 -7.571380e-03 -3.164816e-04 -7.228126e-03 [106] -7.941504e-03 -5.568573e-03 -1.580672e-03 9.552618e-03 7.391276e-03 [111] 1.785762e-02 -1.543656e-03 7.592113e-03 3.166976e-02 3.945374e-03 [116] -2.420206e-02 5.957623e-03 -8.569624e-03 -2.917876e-02 1.881544e-02 > postscript(file="/var/www/html/rcomp/tmp/2tyar1293388002.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/html/rcomp/tmp/3tyar1293388002.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/html/rcomp/tmp/4tyar1293388002.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/html/rcomp/tmp/5l79c1293388002.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/html/rcomp/tmp/6l79c1293388002.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/html/rcomp/tmp/7l79c1293388002.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/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/8iy731293388002.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/9sq6o1293388002.tab") > > try(system("convert tmp/10os61293388002.ps tmp/10os61293388002.png",intern=TRUE)) character(0) > try(system("convert tmp/2tyar1293388002.ps tmp/2tyar1293388002.png",intern=TRUE)) character(0) > try(system("convert tmp/3tyar1293388002.ps tmp/3tyar1293388002.png",intern=TRUE)) character(0) > try(system("convert tmp/4tyar1293388002.ps tmp/4tyar1293388002.png",intern=TRUE)) character(0) > try(system("convert tmp/5l79c1293388002.ps tmp/5l79c1293388002.png",intern=TRUE)) character(0) > try(system("convert tmp/6l79c1293388002.ps tmp/6l79c1293388002.png",intern=TRUE)) character(0) > try(system("convert tmp/7l79c1293388002.ps tmp/7l79c1293388002.png",intern=TRUE)) character(0) > > > proc.time() user system elapsed 10.038 2.149 22.716