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(4.69,4.88,4.84,4.81,5.22,5.16,5.27,5.35,5.33,5.29,5.28,4.94,4.70,4.73,4.57,4.61,4.69,4.53,4.55,4.31,4.03,3.72,3.64,3.81,3.95,4.26,4.55,4.54,4.55,4.39,4.21,4.00,3.67,3.60,3.53,3.35,3.10,2.89,2.97,3.03,2.71,2.44,2.60,2.93,2.86,2.88,3.00,2.90,2.64,2.75,2.70,2.87,3.03,3.14,3.02,2.86,3.07,2.93,2.83,2.72,2.73,2.72,2.77,2.61,2.47,2.30,2.38,2.43,2.39,2.60,2.84,2.87,2.92,3.08,3.33,3.48,3.57,3.66,3.77,3.75,3.75,3.81,3.82,3.89,4.05,4.10,4.07,4.26,4.40,4.61,4.63,4.48,4.46,4.45,4.32,4.52,4.21,3.97,4.12,4.50,4.73,5.26,5.20,4.94,4.95,4.52,3.85,3.41,2.95,2.68,2.53,2.44,2.16,2.20,2.10,2.29,2.03,2.05,1.94,1.87,1.89,1.94,1.79,1.71,1.66,1.74,1.83,1.64,1.69,1.78,1.89,1.95,2.05,2.24,2.38,2.53,2.36,2.22,2.12,1.75,1.76,1.81,1.71,1.74,1.48,1.24,1.16,1.11,0.98,0.94,0.65,0.42,0.41,0.40) > par9 = '1' > par8 = '2' > par7 = '1' > par6 = '3' > par5 = '12' > par4 = '0' > par3 = '1' > par2 = '1' > par1 = 'FALSE' > 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.09169517 0.1344929 0.1503916 0.3083107 0.09276328 -0.04088887 [2,] 0.09212524 0.1345901 0.1500712 0.3082636 0.02021594 -0.03862679 [3,] 0.09137704 0.1363466 0.1502147 0.3084688 0.00000000 -0.03864237 [4,] 0.00000000 0.1735158 0.1510614 0.3943974 0.00000000 -0.03604740 [5,] 0.00000000 0.1752442 0.1509989 0.3958610 0.00000000 0.00000000 [6,] 0.00000000 0.1919343 0.0000000 0.4320276 0.00000000 0.00000000 [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.07278333 [2,] 0.00000000 [3,] 0.00000000 [4,] 0.00000000 [5,] 0.00000000 [6,] 0.00000000 [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.76127 0.36100 0.06323 0.29936 0.90605 0.64005 0.92605 [2,] 0.76054 0.36164 0.06354 0.30024 0.81021 0.65390 NA [3,] 0.76084 0.35200 0.06352 0.29629 NA 0.65374 NA [4,] NA 0.04156 0.06264 0.00000 NA 0.67382 NA [5,] NA 0.03915 0.06218 0.00000 NA NA NA [6,] NA 0.02262 NA 0.00000 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.0917 0.1345 0.1504 0.3083 0.0928 -0.0409 -0.0728 s.e. 0.3012 0.1468 0.0803 0.2960 0.7846 0.0873 0.7828 sigma^2 estimated as 0.02706: log likelihood = 58.9, aic = -101.8 [[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.0917 0.1345 0.1504 0.3083 0.0928 -0.0409 -0.0728 s.e. 0.3012 0.1468 0.0803 0.2960 0.7846 0.0873 0.7828 sigma^2 estimated as 0.02706: log likelihood = 58.9, aic = -101.8 [[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.0921 0.1346 0.1501 0.3083 0.0202 -0.0386 0 s.e. 0.3017 0.1471 0.0803 0.2965 0.0840 0.0860 0 sigma^2 estimated as 0.02706: log likelihood = 58.89, aic = -103.79 [[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.0914 0.1363 0.1502 0.3085 0 -0.0386 0 s.e. 0.2997 0.1460 0.0803 0.2943 0 0.0860 0 sigma^2 estimated as 0.02707: log likelihood = 58.87, aic = -105.73 [[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 0.1735 0.1511 0.3944 0 -0.0360 0 s.e. 0 0.0844 0.0805 0.0781 0 0.0855 0 sigma^2 estimated as 0.02709: log likelihood = 58.82, aic = -107.63 [[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.1752 0.1510 0.3959 0 0 0 s.e. 0 0.0842 0.0804 0.0780 0 0 0 sigma^2 estimated as 0.02712: log likelihood = 58.73, aic = -109.45 [[3]][[7]] NULL $aic [1] -101.7972 -103.7885 -105.7306 -107.6326 -109.4549 -107.9912 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 > postscript(file="/var/fisher/rcomp/tmp/1tfcg1354646731.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 = 154 Frequency = 1 [1] 0.0046899971 0.1698022662 -0.1197823806 -0.0271545469 0.3984066099 [6] -0.2061473020 0.1242630999 -0.0205839982 -0.0220685544 -0.0618933397 [11] 0.0059261271 -0.3323161735 -0.1006565876 0.1309390483 -0.1184354120 [16] 0.1178663749 0.0568504093 -0.1653548021 0.0653980217 -0.2499293618 [21] -0.1604077696 -0.2074621805 0.0874343150 0.2319935768 0.1089919951 [26] 0.2491427126 0.1411701058 -0.1413493029 -0.0316758185 -0.1894980237 [31] -0.1052275756 -0.1418154173 -0.2181570161 0.0803409513 -0.0122634769 [36] -0.1130486268 -0.1824114360 -0.0956765385 0.1888654762 0.0597865440 [41] -0.3259769268 -0.1635530151 0.2717624819 0.3180554312 -0.1831751113 [46] 0.0105214566 0.0782724182 -0.1239199582 -0.2349942083 0.2024295962 [51] -0.0694705884 0.2174835501 0.0660590745 0.0616082139 -0.1980971843 [56] -0.1250177439 0.2639090768 -0.1983123627 -0.0341373321 -0.1036619415 [61] 0.0896999931 -0.0111319706 0.0692641521 -0.1871765235 -0.0731563366 [66] -0.1205511270 0.1764155110 0.0310953487 -0.0406591584 0.2052532495 [71] 0.1582080664 -0.0633897372 0.0013251339 0.1179783628 0.1900047874 [76] 0.0391954900 0.0065131467 0.0233853329 0.0623208389 -0.0740322743 [81] -0.0035602790 0.0483043790 -0.0061018415 0.0619008267 0.1246834990 [86] -0.0131344209 -0.0634095978 0.1821793475 0.0655896820 0.1552691649 [91] -0.0946889959 -0.1704574585 0.0122628020 0.0084122924 -0.1071753755 [96] 0.2471989724 -0.3835646926 -0.1035806844 0.2151294835 0.3837069103 [101] 0.0880585032 0.4058984234 -0.3183651221 -0.2615808626 0.0440348883 [106] -0.3928082574 -0.4769952522 -0.1773311475 -0.2074583373 -0.0095985917 [111] 0.0008515839 0.0264383398 -0.2234095629 0.1668609533 -0.1033954542 [116] 0.2662001566 -0.3538937938 0.1418962386 -0.1492974801 0.0248558850 [121] 0.0264174124 0.0684193548 -0.1700195147 -0.0244780949 -0.0215733870 [126] 0.1252094400 0.0612765913 -0.2207266059 0.1095251602 0.0663497629 [131] 0.1036622995 -0.0043577894 0.0688583096 0.1356171448 0.0597301019 [136] 0.0779588843 -0.2540848708 -0.0868441933 -0.0584800881 -0.2966460035 [141] 0.1660948573 0.0641897841 -0.0712930736 0.0479499464 -0.2690070360 [146] -0.1236680401 0.0099888890 0.0273641255 -0.0905731098 0.0166964877 [151] -0.2662777911 -0.0979513773 0.0856359167 0.0401959426 > postscript(file="/var/fisher/rcomp/tmp/2ii651354646731.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/3ugcd1354646731.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/4o1aa1354646731.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/5a26p1354646731.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/68asw1354646731.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/7d9oc1354646731.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/8r3ii1354646731.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/9wwah1354646731.tab") > > try(system("convert tmp/1tfcg1354646731.ps tmp/1tfcg1354646731.png",intern=TRUE)) character(0) > try(system("convert tmp/2ii651354646731.ps tmp/2ii651354646731.png",intern=TRUE)) character(0) > try(system("convert tmp/3ugcd1354646731.ps tmp/3ugcd1354646731.png",intern=TRUE)) character(0) > try(system("convert tmp/4o1aa1354646731.ps tmp/4o1aa1354646731.png",intern=TRUE)) character(0) > try(system("convert tmp/5a26p1354646731.ps tmp/5a26p1354646731.png",intern=TRUE)) character(0) > try(system("convert tmp/68asw1354646731.ps tmp/68asw1354646731.png",intern=TRUE)) character(0) > try(system("convert tmp/7d9oc1354646731.ps tmp/7d9oc1354646731.png",intern=TRUE)) character(0) > > > proc.time() user system elapsed 9.108 2.486 11.597