R version 2.6.0 (2007-10-03) Copyright (C) 2007 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(153.4,159.5,157.4,169.1,172.6,161.7,159.2,157.4,153.9,144.8,142.2,140.1,143.4,153.3,166.9,170.6,182.8,170.3,156.6,155.2,154.7,151.6,152.1,153.2,149.5,149.7,144.3,140,137.8,132.2,128.9,123.1,120.4,122.8,126,124.5,120.6,114.7,111.7,109.1,108,107.7,99.9,103.7,103.4,103.4,104.7,105.8,105.3,103,103.8,103.4,105.8,101.4,97,94.3,96.6,97.1,95.7,96.9,97.4,95.3,93.6,91.5,93.1,91.7,94.3,93.9,90.9,88.3,91.3,91.7,92.4,92,95.6,95.8,96.4,99,107,109.7,116.2,115.9,113.8,112.6,113.7,115.9,110.3,111.3,113.4,108.2,104.8,106,110.9,115,118.4,121.4,128.8,131.7,141.7,142.9,139.4,134.7,125,113.6,111.5,108.5,112.3,116.6,115.5,120.1,132.9,128.1,129.3,132.5,131,124.9,120.8,122,122.1,127.4,135.2,137.3,135,136,138.4,134.7,138.4,133.9,133.6,141.2,151.8,155.4,156.6,161.6,160.7,156,159.5,168.7,169.9,169.9,185.9) > 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, ncol=nrc) + pval <- matrix(NA, nrow=nrc, 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) + 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.01975709 0.04062651 0.1763802 0.3406274 -0.06662278 -0.1789019 [2,] 0.00000000 0.03459925 0.1775867 0.3219430 -0.06586959 -0.1779879 [3,] 0.00000000 0.00000000 0.1824687 0.3111055 -0.05096046 -0.1769570 [4,] 0.00000000 0.00000000 0.1887297 0.3051424 0.00000000 -0.1593134 [5,] 0.00000000 0.00000000 0.1577001 0.3288644 0.00000000 0.0000000 [6,] 0.00000000 0.00000000 0.0000000 0.3440405 0.00000000 0.0000000 [7,] NA NA NA NA NA NA [,7] [1,] -0.7514961 [2,] -0.7529574 [3,] -0.7627006 [4,] -1.2575470 [5,] -1.1792707 [6,] -1.2057097 [7,] NA [[2]] [,1] [,2] [,3] [,4] [,5] [,6] [,7] [1,] 0.95266 0.77605 0.07807 0.30103 0.63981 0.14122 0 [2,] NA 0.72739 0.06890 0.00086 0.64203 0.14005 0 [3,] NA NA 0.05898 0.00048 0.70336 0.14026 0 [4,] NA NA 0.04740 0.00055 NA 0.15512 0 [5,] NA NA 0.09103 0.00012 NA NA 0 [6,] NA NA NA 0.00022 NA NA 0 [7,] 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.0198 0.0406 0.1764 0.3406 -0.0666 -0.1789 -0.7515 s.e. 0.3322 0.1425 0.0993 0.3281 0.1420 0.1209 0.1374 sigma^2 estimated as 0.001205: log likelihood = 241.34, aic = -466.68 [[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.0198 0.0406 0.1764 0.3406 -0.0666 -0.1789 -0.7515 s.e. 0.3322 0.1425 0.0993 0.3281 0.1420 0.1209 0.1374 sigma^2 estimated as 0.001205: log likelihood = 241.34, aic = -466.68 [[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 0.0346 0.1776 0.3219 -0.0659 -0.1780 -0.7530 s.e. 0 0.0990 0.0968 0.0944 0.1414 0.1199 0.1353 sigma^2 estimated as 0.001205: log likelihood = 241.34, aic = -468.67 [[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 0 0.1825 0.3111 -0.0510 -0.1770 -0.7627 s.e. 0 0 0.0958 0.0869 0.1335 0.1193 0.1328 sigma^2 estimated as 0.001204: log likelihood = 241.28, aic = -470.55 [[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 0.1887 0.3051 0 -0.1593 -1.2575 s.e. 0 0 0.0943 0.0862 0 0.1114 0.1632 sigma^2 estimated as 0.0007596: log likelihood = 241.21, aic = -472.41 [[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.1577 0.3289 0 0 -1.1793 s.e. 0 0 0.0927 0.0829 0 0 0.1506 sigma^2 estimated as 0.0008762: log likelihood = 240.24, aic = -472.48 [[3]][[7]] NULL $aic [1] -466.6770 -468.6735 -470.5506 -472.4111 -472.4777 -471.6128 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/www/html/rcomp/tmp/1qlhr1197042734.ps",horizontal=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 = 141 Frequency = 1 [1] 0.0029058308 0.0013297294 0.0008593075 0.0007037190 0.0005798993 [6] 0.0004224940 0.0003472921 0.0002930125 0.0002390736 0.0001571254 [11] 0.0001254947 -0.0027738646 -0.0178806160 0.0168906521 0.0571921577 [16] -0.0502636270 0.0447607333 -0.0282632928 -0.0299622043 0.0065906329 [21] 0.0115458360 0.0287458230 0.0055063581 0.0153090189 -0.0450357030 [26] -0.0269895881 -0.0481218086 -0.0359302039 -0.0274958401 0.0373969934 [31] 0.0150632466 -0.0245501835 -0.0018906497 0.0415722807 0.0148962644 [36] -0.0086027671 -0.0320368232 -0.0601274420 -0.0090415357 -0.0265549286 [41] -0.0074839919 0.0511012302 -0.0380214147 0.0636493732 -0.0174989756 [46] 0.0243707160 -0.0098458596 0.0155846362 -0.0070246175 -0.0258881321 [51] 0.0119498152 -0.0134631298 0.0154395372 -0.0051201311 0.0081866615 [56] -0.0216336806 0.0365439928 0.0020659796 -0.0157125865 0.0126206233 [61] 0.0012473065 -0.0187667791 -0.0124522485 -0.0200113528 0.0105459119 [66] 0.0222623540 0.0595691815 -0.0140002627 -0.0223751714 -0.0190934084 [71] 0.0306996289 -0.0036572067 0.0116872710 -0.0102702914 0.0362548895 [76] -0.0109993931 -0.0046807328 0.0494736076 0.0754733061 0.0053162446 [81] 0.0458182249 -0.0208986574 -0.0202265605 -0.0122895851 0.0106773951 [86] 0.0175997819 -0.0503808803 0.0228255915 -0.0069811271 -0.0083966110 [91] -0.0147622952 0.0165356453 0.0327613111 0.0313994387 0.0089580005 [96] 0.0128844356 0.0375197176 0.0014965907 0.0609195208 -0.0218336568 [101] -0.0292835063 -0.0048308056 -0.0487261423 -0.0583492267 -0.0044763285 [106] -0.0113563415 0.0382796171 0.0195448210 -0.0211249773 0.0318465805 [111] 0.0626519203 -0.0510648614 0.0129198663 0.0294237722 0.0077462843 [116] -0.0286474756 -0.0304572958 0.0221968750 -0.0131586514 0.0372360437 [121] 0.0285589611 -0.0039866444 -0.0377806786 0.0150390882 0.0018482606 [126] -0.0001792582 0.0412280723 -0.0241540755 0.0076742508 0.0408855181 [131] 0.0400716814 -0.0058618068 -0.0135697115 0.0130014461 -0.0250242346 [136] -0.0139971916 0.0121436378 0.0651225812 0.0012094363 0.0179981022 [141] 0.0606944431 > postscript(file="/var/www/html/rcomp/tmp/24kyo1197042734.ps",horizontal=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/3svvu1197042734.ps",horizontal=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/4tpy41197042734.ps",horizontal=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/5609m1197042734.ps",horizontal=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/6wbw81197042734.ps",horizontal=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/7bspb1197042734.ps",horizontal=F,pagecentre=F,paper="special",width=8.3333333333333,height=5.5555555555556) > qqnorm(resid, main='Residual Normal Q-Q Plot') > dev.off() null device 1 > ncols <- length(selection[[1]][1,]) > nrows <- length(selection[[2]][,1])-1 > 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/8evr71197042734.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/9d7r51197042734.tab") > > system("convert tmp/1qlhr1197042734.ps tmp/1qlhr1197042734.png") > system("convert tmp/24kyo1197042734.ps tmp/24kyo1197042734.png") > system("convert tmp/3svvu1197042734.ps tmp/3svvu1197042734.png") > system("convert tmp/4tpy41197042734.ps tmp/4tpy41197042734.png") > system("convert tmp/5609m1197042734.ps tmp/5609m1197042734.png") > system("convert tmp/6wbw81197042734.ps tmp/6wbw81197042734.png") > system("convert tmp/7bspb1197042734.ps tmp/7bspb1197042734.png") > > > proc.time() user system elapsed 9.673 1.212 10.181