R version 2.8.0 (2008-10-20) Copyright (C) 2008 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. Natural language support but running in an English locale 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(9.026,9.787,9.536,9.490,9.736,9.694,9.647,9.753,10.070,10.137,9.984,9.732,9.103,9.155,9.308,9.394,9.948,10.177,10.002,9.728,10.002,10.063,10.018,9.960,10.236,10.893,10.756,10.940,10.997,10.827,10.166,10.186,10.457,10.368,10.244,10.511,10.812,10.738,10.171,9.721,9.897,9.828,9.924,10.371,10.846,10.413,10.709,10.662,10.570,10.297,10.635,10.872,10.296,10.383,10.431,10.574,10.653,10.805,10.872,10.625,10.407,10.463,10.556,10.646,10.702,11.353,11.346,11.451,11.964,12.574,13.031,13.812,14.544,14.931,14.886,16.005,17.064,15.168,16.050,15.839,15.137,14.954,15.648,15.305,15.579,16.348,15.928,16.171,15.937,15.713,15.594,15.683,16.438,17.032,17.696,17.745,19.394,20.148,20.108,18.584,18.441,18.391,19.178,18.079,18.483,19.644,19.195,19.650,20.830,23.595,22.937,21.814,21.928,21.777,21.383,21.467,22.052,22.680,24.320,24.977,25.204,25.739,26.434,27.525,30.695,32.436,30.160,30.236,31.293,31.077,32.226) > par9 = '0' > par8 = '2' > par7 = '1' > par6 = '3' > par5 = '12' > par4 = '0' > par3 = '1' > par2 = '-0.5' > 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.2591359 -0.1459284 0.1846571 -0.1093023 0.001977476 0.02491252 [2,] 0.2594698 -0.1461722 0.1850157 -0.1093212 0.000000000 0.02478249 [3,] 0.2663586 -0.1418971 0.1883454 -0.1159628 0.000000000 0.00000000 [4,] 0.1535647 -0.1263304 0.1750410 0.0000000 0.000000000 0.00000000 [5,] 0.1334803 0.0000000 0.1554598 0.0000000 0.000000000 0.00000000 [6,] 0.0000000 0.0000000 0.1449621 0.0000000 0.000000000 0.00000000 [7,] 0.0000000 0.0000000 0.0000000 0.0000000 0.000000000 0.00000000 [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 [[2]] [,1] [,2] [,3] [,4] [,5] [,6] [1,] 0.40000 0.15114 0.05422 0.71850 0.98355 0.80462 [2,] 0.39840 0.14783 0.04833 0.71824 NA 0.80555 [3,] 0.37902 0.15478 0.04098 0.69786 NA NA [4,] 0.08723 0.16073 0.05055 NA NA NA [5,] 0.13404 NA 0.08051 NA NA NA [6,] NA NA 0.10496 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 [[3]] [[3]][[1]] Call: arima(x = series, order = order, seasonal = seasonal, include.mean = include.mean, method = "ML") Coefficients: ar1 ar2 ar3 ma1 sar1 sar2 0.2591 -0.1459 0.1847 -0.1093 0.0020 0.0249 s.e. 0.3068 0.1010 0.0950 0.3025 0.0957 0.1005 sigma^2 estimated as 2.269e-05: log likelihood = 510.55, aic = -1007.1 [[3]][[2]] Call: arima(x = series, order = order, seasonal = seasonal, include.mean = include.mean, method = "ML") Coefficients: ar1 ar2 ar3 ma1 sar1 sar2 0.2591 -0.1459 0.1847 -0.1093 0.0020 0.0249 s.e. 0.3068 0.1010 0.0950 0.3025 0.0957 0.1005 sigma^2 estimated as 2.269e-05: log likelihood = 510.55, aic = -1007.1 [[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 0.2595 -0.1462 0.1850 -0.1093 0 0.0248 s.e. 0.3062 0.1004 0.0928 0.3023 0 0.1005 sigma^2 estimated as 2.269e-05: log likelihood = 510.55, aic = -1009.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 0.2664 -0.1419 0.1883 -0.116 0 0 s.e. 0.3017 0.0991 0.0912 0.298 0 0 sigma^2 estimated as 2.27e-05: log likelihood = 510.52, aic = -1011.04 [[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 0.1536 -0.1263 0.1750 0 0 0 s.e. 0.0891 0.0895 0.0887 0 0 0 sigma^2 estimated as 2.273e-05: log likelihood = 510.45, aic = -1012.89 [[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 0.1335 0 0.1555 0 0 0 s.e. 0.0885 0 0.0882 0 0 0 sigma^2 estimated as 2.308e-05: log likelihood = 509.46, aic = -1012.92 [[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 0 0 0.1450 0 0 0 s.e. 0 0 0.0888 0 0 0 sigma^2 estimated as 2.349e-05: log likelihood = 508.33, aic = -1012.66 $aic [1] -1007.105 -1009.104 -1011.043 -1012.890 -1012.916 -1012.665 -1012.029 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 max(i) : no non-missing arguments to max; returning -Inf 7: In max(i) : no non-missing arguments to max; returning -Inf 8: In max(try.data.frame[, 4], na.rm = TRUE) : no non-missing arguments to max; returning -Inf > postscript(file="/var/www/html/freestat/rcomp/tmp/1r25d1293293015.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 = 131 Frequency = 1 [1] 3.328527e-04 -1.306307e-02 4.135337e-03 7.755577e-04 -2.213388e-03 [6] 8.764909e-05 6.678070e-04 -1.156096e-03 -5.180836e-03 -1.156413e-03 [11] 2.651760e-03 4.807738e-03 1.104102e-02 -1.290167e-03 -3.317726e-03 [16] -3.082398e-03 -9.078357e-03 -3.192026e-03 2.948378e-03 5.757913e-03 [21] -3.902048e-03 -1.355620e-03 6.617913e-05 1.559616e-03 -4.161935e-03 [26] -9.675000e-03 1.790330e-03 -1.951541e-03 6.030873e-04 2.079357e-03 [31] 1.009793e-02 -1.943281e-04 -4.428540e-03 -8.526478e-05 1.918643e-03 [36] -3.401392e-03 -4.515769e-03 7.744571e-04 8.969644e-03 7.802227e-03 [41] -3.016269e-03 -1.024433e-04 -2.586760e-03 -6.500988e-03 -7.037200e-03 [46] 6.473064e-03 -3.310188e-03 1.669506e-03 4.240592e-04 4.675927e-03 [51] -5.089664e-03 -3.553462e-03 7.780741e-03 -5.847424e-04 -2.276951e-04 [56] -3.313810e-03 -9.527159e-04 -2.059032e-03 -6.343117e-04 3.670546e-03 [61] 3.510041e-03 -6.945594e-04 -1.872935e-03 -1.767135e-03 -6.825005e-04 [66] -8.695633e-03 2.805339e-04 -1.247856e-03 -5.115816e-03 -7.113197e-03 [71] -4.791431e-03 -7.017527e-03 -5.829444e-03 -2.697275e-03 1.542741e-03 [76] -8.230481e-03 -7.384729e-03 1.462798e-02 -5.817486e-03 2.799482e-03 [81] 3.631697e-03 2.605073e-03 -6.039701e-03 1.981968e-03 -2.485093e-03 [86] -5.189911e-03 2.831235e-03 -1.562433e-03 2.693180e-03 1.309546e-03 [91] 1.234674e-03 -9.832458e-04 -6.125077e-03 -4.478407e-03 -4.485162e-03 [96] 5.220791e-04 -9.687337e-03 -3.624106e-03 2.690883e-04 1.045923e-02 [101] 1.519462e-03 2.842294e-04 -6.134046e-03 6.708000e-03 -2.630405e-03 [106] -6.277467e-03 1.632318e-03 -2.283375e-03 -5.471275e-03 -1.361832e-02 [111] 3.317339e-03 6.246923e-03 1.361728e-03 3.140596e-04 1.195886e-03 [116] -3.427308e-04 -2.989191e-03 -3.253818e-03 -7.142093e-03 -2.266925e-03 [121] -4.727204e-04 -1.036767e-03 -2.219249e-03 -3.762716e-03 -9.808815e-03 [126] -4.532722e-03 7.069117e-03 1.236646e-03 -2.385892e-03 -3.227664e-04 [131] -3.193724e-03 > postscript(file="/var/www/html/freestat/rcomp/tmp/2jc4g1293293015.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/freestat/rcomp/tmp/3jc4g1293293015.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/freestat/rcomp/tmp/4jc4g1293293015.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/freestat/rcomp/tmp/5jc4g1293293015.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/freestat/rcomp/tmp/6u3li1293293015.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/freestat/rcomp/tmp/7u3li1293293015.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/freestat/rcomp/createtable file can be downloaded at http://www.wessa.net/cretab > load(file="/var/www/html/freestat/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/freestat/rcomp/tmp/8qv1r1293293015.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/freestat/rcomp/tmp/9j40c1293293015.tab") > > try(system("convert tmp/1r25d1293293015.ps tmp/1r25d1293293015.png",intern=TRUE)) character(0) > try(system("convert tmp/2jc4g1293293015.ps tmp/2jc4g1293293015.png",intern=TRUE)) character(0) > try(system("convert tmp/3jc4g1293293015.ps tmp/3jc4g1293293015.png",intern=TRUE)) character(0) > try(system("convert tmp/4jc4g1293293015.ps tmp/4jc4g1293293015.png",intern=TRUE)) character(0) > try(system("convert tmp/5jc4g1293293015.ps tmp/5jc4g1293293015.png",intern=TRUE)) character(0) > try(system("convert tmp/6u3li1293293015.ps tmp/6u3li1293293015.png",intern=TRUE)) character(0) > try(system("convert tmp/7u3li1293293015.ps tmp/7u3li1293293015.png",intern=TRUE)) character(0) > > > proc.time() user system elapsed 5.210 1.845 5.800