R version 2.13.0 (2011-04-13) Copyright (C) 2011 The R Foundation for Statistical Computing ISBN 3-900051-07-0 Platform: i486-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(39923931,35810356.5,35492936.3,38937434.1,40059102.8,37708710.2,41570965.7,36333563,34181220.1,42593543.9,43119727.6,38497690.9,45473273.4,38399780.4,38882302.6,44051120.6,41677559.9,40699203.5,44150027.6,38225518.7,35447405.7,43075518.3,42302792,39743541.7,44670641.2,37123384,37668266.4,46117528.8,42273156.4,39404153.2,45799994.5,38602505.2,39454830.1,47427901.4,46497980.9,45057149.4,50615569.2,43033396.2,46013056.5,54222266.3,46417306.4,51046271.8,51201279.6,43475288.7,44968981.1,53939345.4,54549319.7,54072107.3,58434230.1,51158751,50039368,57872617.4,51642978.8,54534465.9,56094697.8,48189983.1,47492381,52987449.1,55719803.5,53922860.5,54931231.9) > par1 = '12' > par1 <- as.numeric(par1) > nx <- length(x) > x <- ts(x,frequency=par1) > m <- StructTS(x,type='BSM') > m$coef level slope seas epsilon 9.755648e+11 3.001023e+09 1.461748e+12 0.000000e+00 > m$fitted level slope sea Jan 1 39923931 0.000 0.0 Feb 1 37764212 -57894.848 -1953855.7 Mar 1 35948410 -172407.792 -455473.5 Apr 1 36954122 -103298.421 1983312.1 May 1 38500316 -32194.504 1558787.0 Jun 1 38574541 -28714.440 -865830.5 Jul 1 39875013 9922.541 1695952.9 Aug 1 38728523 -24227.046 -2394960.0 Sep 1 36485098 -94335.026 -2303878.2 Oct 1 38496706 -23001.831 4096838.1 Nov 1 41029752 68695.621 2089975.5 Dec 1 40645361 51685.549 -2147670.3 Jan 2 41907485 65708.674 3565788.3 Feb 2 41375904 50557.788 -2976123.4 Mar 2 40875492 26412.674 -1993188.9 Apr 2 41746438 70016.148 2304682.8 May 2 41375062 47151.552 302498.3 Jun 2 41504898 51207.517 -805694.1 Jul 2 41461469 46804.243 2688558.8 Aug 2 40795893 14570.116 -2570374.7 Sep 2 40087681 -17903.978 -4640275.0 Oct 2 40047161 -18917.846 3028357.7 Nov 2 40093502 -16030.007 2209290.4 Dec 2 41071010 26670.882 -1327467.9 Jan 3 41138557 28385.730 3532084.5 Feb 3 40682536 6949.131 -3559152.0 Mar 3 40333540 -10210.432 -2665273.7 Apr 3 41642662 57248.554 4474866.5 May 3 42071291 76639.940 201865.1 Jun 3 41279122 31499.287 -1874968.7 Jul 3 41627487 47706.084 4172507.4 Aug 3 41357457 31716.462 -2754951.5 Sep 3 42481001 85939.051 -3026171.1 Oct 3 43673801 140313.331 3754100.6 Nov 3 44462872 171887.065 2035109.3 Dec 3 45456213 211643.252 -399063.6 Jan 4 46326515 243635.436 4289054.6 Feb 4 46779164 253952.453 -3745767.9 Mar 4 48097868 307687.395 -2084811.2 Apr 4 49180243 347508.222 5042022.9 May 4 48082361 272502.878 -1665054.8 Jun 4 50049711 360543.203 996561.1 Jul 4 49411696 308905.367 1789583.7 Aug 4 48454074 243863.043 -4978785.7 Sep 4 48518682 234723.688 -3549700.6 Oct 4 49590911 277156.393 4348434.8 Nov 4 51429845 355937.718 3119475.1 Dec 4 53440229 439273.226 631878.0 Jan 5 54492804 470237.750 3941426.2 Feb 5 55355703 490176.367 -4196951.5 Mar 5 54442362 418397.858 -4402993.6 Apr 5 53498221 348288.551 4374396.4 May 5 53607976 335970.973 -1964997.3 Jun 5 53344504 304991.348 1189961.8 Jul 5 53520184 298317.500 2574513.7 Aug 5 53653034 289800.288 -5463051.0 Sep 5 53156392 249445.323 -5664011.0 Oct 5 51860707 170384.733 1126741.9 Nov 5 52458651 192219.566 3261152.2 Dec 5 53151489 217770.973 771371.6 Jan 6 52360033 166211.716 2571199.1 > m$resid Jan Feb Mar Apr May Jun 1 0.00000000 -1.85324194 -1.24371675 1.03837902 1.60720443 0.10583442 2 1.23962204 -0.60122384 -0.50547316 0.76330023 -0.41186840 0.07895999 3 0.03932940 -0.46400545 -0.33363271 1.22155977 0.34599791 -0.81871451 4 0.62420042 0.19767143 0.99945228 0.72306307 -1.35061081 1.59187291 5 0.57798939 0.36974594 -1.31739574 -1.27544571 -0.22331588 -0.56253138 6 -0.94878884 Jul Aug Sep Oct Nov Dec 1 1.32163571 -1.14559150 -2.18954179 2.07029376 2.50522130 -0.44294935 2 -0.09101229 -0.68504539 -0.69375519 -0.02165528 0.06232337 0.94902914 3 0.30050329 -0.30155906 1.03417650 1.04585903 0.61232651 0.77652621 4 -0.94159981 -1.19500993 -0.16884396 0.78735114 1.46765740 1.55689863 5 -0.12161317 -0.15567598 -0.73906000 -1.45019517 0.40120925 0.47019954 6 > mylevel <- as.numeric(m$fitted[,'level']) > myslope <- as.numeric(m$fitted[,'slope']) > myseas <- as.numeric(m$fitted[,'sea']) > myresid <- as.numeric(m$resid) > myfit <- mylevel+myseas > postscript(file="/var/wessaorg/rcomp/tmp/1kgwr1322388779.ps",horizontal=F,onefile=F,pagecentre=F,paper="special",width=8.3333333333333,height=5.5555555555556) > plot(as.numeric(m$resid),main='Standardized Residuals',ylab='Residuals',xlab='time') > grid() > dev.off() null device 1 > mylagmax <- nx/2 > postscript(file="/var/wessaorg/rcomp/tmp/241gv1322388779.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(mylevel,na.action=na.pass,lag.max = mylagmax,main='Level') > acf(myseas,na.action=na.pass,lag.max = mylagmax,main='Seasonal') > acf(myresid,na.action=na.pass,lag.max = mylagmax,main='Standardized Residals') > par(op) > dev.off() null device 1 > postscript(file="/var/wessaorg/rcomp/tmp/37nk01322388779.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(mylevel,main='Level') > spectrum(myseas,main='Seasonal') > spectrum(myresid,main='Standardized Residals') > par(op) > dev.off() null device 1 > postscript(file="/var/wessaorg/rcomp/tmp/4sbt81322388779.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(mylevel,main='Level') > cpgram(myseas,main='Seasonal') > cpgram(myresid,main='Standardized Residals') > par(op) > dev.off() null device 1 > postscript(file="/var/wessaorg/rcomp/tmp/5qc9r1322388779.ps",horizontal=F,onefile=F,pagecentre=F,paper="special",width=8.3333333333333,height=5.5555555555556) > op <- par(mfrow = c(2,2)) > hist(m$resid,main='Residual Histogram') > plot(density(m$resid),main='Residual Kernel Density') > qqnorm(m$resid,main='Residual Normal QQ Plot') > qqline(m$resid) > plot(m$resid^2, myfit^2,main='Sq.Resid vs. Sq.Fit',xlab='Squared residuals',ylab='Squared Fit') > par(op) > dev.off() null device 1 > > #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,'Structural Time Series Model',6,TRUE) > a<-table.row.end(a) > a<-table.row.start(a) > a<-table.element(a,'t',header=TRUE) > a<-table.element(a,'Observed',header=TRUE) > a<-table.element(a,'Level',header=TRUE) > a<-table.element(a,'Slope',header=TRUE) > a<-table.element(a,'Seasonal',header=TRUE) > a<-table.element(a,'Stand. Residuals',header=TRUE) > a<-table.row.end(a) > for (i in 1:nx) { + a<-table.row.start(a) + a<-table.element(a,i,header=TRUE) + a<-table.element(a,x[i]) + a<-table.element(a,mylevel[i]) + a<-table.element(a,myslope[i]) + a<-table.element(a,myseas[i]) + a<-table.element(a,myresid[i]) + a<-table.row.end(a) + } > a<-table.end(a) > table.save(a,file="/var/wessaorg/rcomp/tmp/6o7jb1322388779.tab") > > try(system("convert tmp/1kgwr1322388779.ps tmp/1kgwr1322388779.png",intern=TRUE)) character(0) > try(system("convert tmp/241gv1322388779.ps tmp/241gv1322388779.png",intern=TRUE)) character(0) > try(system("convert tmp/37nk01322388779.ps tmp/37nk01322388779.png",intern=TRUE)) character(0) > try(system("convert tmp/4sbt81322388779.ps tmp/4sbt81322388779.png",intern=TRUE)) character(0) > try(system("convert tmp/5qc9r1322388779.ps tmp/5qc9r1322388779.png",intern=TRUE)) character(0) > > > proc.time() user system elapsed 1.916 0.275 2.200