x <- c(9676,8642,9402,9610,9294,9448,10319,9548,9801,9596,8923,9746,9829,9125,9782,9441,9162,9915,10444,10209,9985,9842,9429,10132,9849,9172,10313,9819,9955,10048,10082,10541,10208,10233,9439,9963,10158,9225,10474,9757,10490,10281,10444,10640,10695,10786,9832,9747,10411,9511,10402,9701,10540,10112,10915,11183,10384,10834,9886,10216) par2 = '12' par1 = 'additive' par2 <- as.numeric(par2) x <- ts(x,freq=par2) m <- decompose(x,type=par1) m$figure postscript(file="/var/wessaorg/rcomp/tmp/1qtrt1322210397.ps",horizontal=F,onefile=F,pagecentre=F,paper="special",width=8.3333333333333,height=5.5555555555556) plot(m) dev.off() mylagmax <- length(x)/2 postscript(file="/var/wessaorg/rcomp/tmp/2xgq21322210397.ps",horizontal=F,onefile=F,pagecentre=F,paper="special",width=8.3333333333333,height=5.5555555555556) op <- par(mfrow = c(2,2)) acf(as.numeric(x),lag.max = mylagmax,main='Observed') acf(as.numeric(m$trend),na.action=na.pass,lag.max = mylagmax,main='Trend') acf(as.numeric(m$seasonal),na.action=na.pass,lag.max = mylagmax,main='Seasonal') acf(as.numeric(m$random),na.action=na.pass,lag.max = mylagmax,main='Random') par(op) dev.off() postscript(file="/var/wessaorg/rcomp/tmp/3wuk21322210397.ps",horizontal=F,onefile=F,pagecentre=F,paper="special",width=8.3333333333333,height=5.5555555555556) op <- par(mfrow = c(2,2)) spectrum(as.numeric(x),main='Observed') spectrum(as.numeric(m$trend[!is.na(m$trend)]),main='Trend') spectrum(as.numeric(m$seasonal[!is.na(m$seasonal)]),main='Seasonal') spectrum(as.numeric(m$random[!is.na(m$random)]),main='Random') par(op) dev.off() postscript(file="/var/wessaorg/rcomp/tmp/4u1ai1322210397.ps",horizontal=F,onefile=F,pagecentre=F,paper="special",width=8.3333333333333,height=5.5555555555556) op <- par(mfrow = c(2,2)) cpgram(as.numeric(x),main='Observed') cpgram(as.numeric(m$trend[!is.na(m$trend)]),main='Trend') cpgram(as.numeric(m$seasonal[!is.na(m$seasonal)]),main='Seasonal') cpgram(as.numeric(m$random[!is.na(m$random)]),main='Random') par(op) dev.off() #Note: the /var/wessaorg/rcomp/createtable file can be downloaded at http://www.wessa.net/cretab load(file="/var/wessaorg/rcomp/createtable") a<-table.start() a<-table.row.start(a) a<-table.element(a,'Classical Decomposition by Moving Averages',6,TRUE) a<-table.row.end(a) a<-table.row.start(a) a<-table.element(a,'t',header=TRUE) a<-table.element(a,'Observations',header=TRUE) a<-table.element(a,'Fit',header=TRUE) a<-table.element(a,'Trend',header=TRUE) a<-table.element(a,'Seasonal',header=TRUE) a<-table.element(a,'Random',header=TRUE) a<-table.row.end(a) for (i in 1:length(m$trend)) { a<-table.row.start(a) a<-table.element(a,i,header=TRUE) a<-table.element(a,x[i]) a<-table.element(a,m$trend[i]+m$seasonal[i]) a<-table.element(a,m$trend[i]) a<-table.element(a,m$seasonal[i]) a<-table.element(a,m$random[i]) a<-table.row.end(a) } a<-table.end(a) table.save(a,file="/var/wessaorg/rcomp/tmp/54cyt1322210397.tab") try(system("convert tmp/1qtrt1322210397.ps tmp/1qtrt1322210397.png",intern=TRUE)) try(system("convert tmp/2xgq21322210397.ps tmp/2xgq21322210397.png",intern=TRUE)) try(system("convert tmp/3wuk21322210397.ps tmp/3wuk21322210397.png",intern=TRUE)) try(system("convert tmp/4u1ai1322210397.ps tmp/4u1ai1322210397.png",intern=TRUE))