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(276986 + ,260633 + ,291551 + ,275383 + ,275302 + ,231693 + ,238829 + ,274215 + ,277808 + ,299060 + ,286629 + ,232313 + ,294053 + ,267510 + ,309739 + ,280733 + ,287298 + ,235672 + ,256449 + ,288997 + ,290789 + ,321898 + ,291834 + ,241380 + ,295469 + ,258200 + ,306102 + ,281480 + ,283101 + ,237414 + ,274834 + ,299340 + ,300383 + ,340862 + ,318794 + ,265740 + ,322656 + ,281563 + ,323461 + ,312579 + ,310784 + ,262785 + ,273754 + ,320036 + ,310336 + ,342206 + ,320052 + ,265582 + ,326988 + ,300713 + ,346414 + ,317325 + ,326208 + ,270657 + ,278158 + ,324584 + ,321801 + ,343542 + ,354040 + ,278179 + ,330246 + ,307344 + ,375874 + ,335309 + ,339271 + ,280264 + ,293689 + ,341161 + ,345097 + ,368712 + ,369403 + ,288384 + ,340981 + ,319072 + ,374214 + ,344529 + ,337271 + ,281016 + ,282224 + ,320984 + ,325426 + ,366276 + ,380296 + ,300727 + ,359326 + ,327610 + ,383563 + ,352405 + ,329351 + ,294486 + ,333454 + ,334339 + ,358000 + ,396057 + ,386976 + ,307155 + ,363909 + ,344700 + ,397561 + ,376791 + ,337085 + ,299252 + ,323136 + ,329091 + ,346991 + ,461999 + ,436533 + ,360372 + ,415467 + ,382110 + ,432197 + ,424254 + ,386728 + ,354508 + ,375765 + ,367986 + ,402378 + ,426516 + ,433313 + ,338461 + ,416834 + ,381099 + ,445673 + ,412408 + ,393997 + ,348241 + ,380134 + ,373688 + ,393588 + ,434192 + ,430731 + ,344468 + ,411891 + ,370497 + ,437305 + ,411270 + ,385495 + ,341273 + ,384217 + ,373223 + ,415771 + ,448634 + ,454341 + ,350297 + ,419104 + ,398027 + ,456059 + ,430052 + ,399757 + ,362731 + ,384896 + ,385349 + ,432289 + ,468891 + ,442702 + ,370178 + ,439400 + ,393900 + ,468700 + ,438800 + ,430100 + ,366300 + ,391000 + ,380900 + ,431400 + ,465400 + ,471500 + ,387500 + ,446400 + ,421500 + ,504800 + ,492071 + ,421253 + ,396682 + ,428000 + ,421900 + ,465600 + ,525793 + ,499855 + ,435287 + ,479499 + ,473027 + ,554410 + ,489574 + ,462157 + ,420331) > 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 39589293 0 61625915 9504314 > m$fitted level slope sea Jan 1 276986.0 0.000000 0.0000 Feb 1 268907.0 -230.474650 -7548.4699 Mar 1 277947.1 378.739939 13053.7672 Apr 1 278431.7 384.754227 -3056.8101 May 1 277248.7 323.833021 -1805.3714 Jun 1 258542.2 -164.178785 -25041.7533 Jul 1 245805.2 -403.381156 -5765.4797 Aug 1 254051.3 -259.441453 19328.4178 Sep 1 265824.3 -64.905267 10822.2399 Oct 1 282342.4 204.530618 15118.5329 Nov 1 288325.0 298.831091 -2252.8380 Dec 1 267125.7 -50.560822 -32741.5284 Jan 2 271270.2 -155.056581 22364.6469 Feb 2 275886.5 -175.743156 -8836.8260 Mar 2 285177.8 7.144803 23756.4657 Apr 2 284448.3 -13.753604 -3654.7650 May 2 280755.5 -114.681115 6856.6634 Jun 2 270094.2 -352.305800 -33486.5431 Jul 2 267770.0 -387.246288 -11142.3329 Aug 2 271984.8 -320.645767 16591.5931 Sep 2 279652.3 -220.351379 10404.1580 Oct 2 291381.3 -89.428742 29419.3754 Nov 2 290909.0 -92.662930 960.2429 Dec 2 286160.3 -112.119899 -44350.8872 Jan 3 282238.5 -108.457099 13585.1141 Feb 3 277385.1 -122.283973 -18749.2328 Mar 3 277059.4 -124.544004 29060.6400 Apr 3 277855.6 -108.710486 3544.9710 May 3 274609.2 -169.168013 8763.6935 Jun 3 272597.2 -202.848016 -35020.6769 Jul 3 279407.7 -91.478335 -5202.1117 Aug 3 285056.5 -15.296111 13764.0795 Sep 3 290693.4 46.129007 9175.4326 Oct 3 299237.3 118.879945 40849.9403 Nov 3 306752.2 164.721912 11366.6473 Dec 3 308516.9 171.242406 -42923.1693 Jan 4 308244.4 169.790476 14452.1748 Feb 4 305240.4 153.277453 -23389.8446 Mar 4 300325.4 107.925016 23587.2438 Apr 4 301999.0 127.430806 10442.3176 May 4 302790.0 136.986584 7935.6970 Jun 4 303390.6 143.740833 -40646.6832 Jul 4 296366.8 47.419481 -21972.0632 Aug 4 301150.8 102.496889 18458.3932 Sep 4 304974.3 138.171540 5024.7618 Oct 4 306254.4 146.826173 35847.9464 Nov 4 307677.8 154.269658 12258.2064 Dec 4 307778.9 154.020556 -42192.1173 Jan 5 308519.2 156.725752 18415.5541 Feb 5 313756.5 186.328096 -13501.7441 Mar 5 318821.9 224.928518 27155.8960 Apr 5 315303.1 187.407503 2354.2029 May 5 315362.0 185.939190 10857.3805 Jun 5 312877.9 154.378307 -41983.5739 Jul 5 309055.3 109.536919 -30541.5345 Aug 5 308217.2 99.983780 16452.0336 Sep 5 311767.9 129.574373 9721.4427 Oct 5 311364.4 125.809935 32225.8778 Nov 5 323217.0 194.061871 29760.2521 Dec 5 325457.5 204.531430 -47463.9622 Jan 6 322265.0 187.045684 8288.2523 Feb 6 321823.4 183.319177 -14422.7348 Mar 6 331144.8 249.121132 43910.3927 Apr 6 333383.9 266.093520 1747.6158 May 6 330936.6 240.332091 8576.0886 Jun 6 326303.0 192.308583 -45604.0207 Jul 6 324910.4 177.131689 -31079.4301 Aug 6 325850.8 183.848002 15241.5373 Sep 6 330881.3 221.391390 13778.5909 Oct 6 336901.0 260.042051 31287.0193 Nov 6 339455.9 273.332783 29739.5186 Dec 6 338211.9 265.270905 -49690.6272 Jan 7 336788.3 256.260365 4345.1687 Feb 7 337495.2 258.889387 -18463.7952 Mar 7 334956.9 240.309001 39508.1888 Apr 7 336364.6 249.066206 8059.9426 May 7 332640.9 216.666728 4985.3761 Jun 7 329656.4 189.673583 -48353.8198 Jul 7 323846.7 139.977184 -41084.4212 Aug 7 317650.4 90.705091 3903.5345 Sep 7 315710.0 76.375590 9899.0596 Oct 7 323079.6 122.320627 42537.9559 Nov 7 334596.3 187.089379 44670.2043 Dec 7 342543.4 228.553642 -42517.4388 Jan 8 348700.9 260.226637 10090.0544 Feb 8 348226.7 256.072120 -20550.5019 Mar 8 346201.4 241.978820 37566.7231 Apr 8 343587.3 222.725972 9073.9624 May 8 334178.1 153.544031 -3963.3330 Jun 8 333700.8 148.886072 -39158.1521 Jul 8 348160.7 253.346168 -15992.5903 Aug 8 345291.0 231.595058 -10670.9237 Sep 8 349028.1 254.285049 8655.9079 Oct 8 355240.3 289.721310 40278.9599 Nov 8 353974.7 281.146377 33141.7343 Dec 8 353263.0 275.919379 -46018.3513 Jan 9 352797.2 272.028065 11178.7669 Feb 9 356411.4 290.213947 -12012.6202 Mar 9 357136.7 292.727701 40385.1841 Apr 9 359710.6 306.756469 16875.3428 May 9 354502.2 271.199766 -16921.5662 Jun 9 350578.3 243.562306 -50949.1900 Jul 9 345421.8 208.256785 -21800.0261 Aug 9 343711.6 196.142448 -14447.8334 Sep 9 342626.9 188.485737 4479.5692 Oct 9 372260.7 353.741894 87080.8485 Nov 9 390106.0 446.521270 44847.5928 Dec 9 400086.4 495.337588 -40575.1948 Jan 10 404532.1 515.454983 10578.3843 Feb 10 401583.6 497.404711 -19161.2081 Mar 10 397101.4 470.375777 35544.2796 Apr 10 398401.7 475.084155 25777.5781 May 10 399409.3 478.211125 -12729.1932 Jun 10 401108.5 485.499535 -46710.3614 Jul 10 401198.3 483.150129 -25397.6313 Aug 10 397882.1 461.167434 -29553.6583 Sep 10 406433.7 506.099266 -4785.5903 Oct 10 387938.3 405.434161 40292.9186 Nov 10 386935.9 398.285580 46504.2290 Dec 10 384371.2 383.646967 -45642.5979 Jan 11 391142.7 415.005810 25114.6397 Feb 11 395169.0 432.983640 -14395.7805 Mar 11 402113.9 466.304885 42971.8674 Apr 11 397944.3 441.838071 14881.5334 May 11 400701.9 454.367407 -6913.5994 Jun 11 398837.0 441.668047 -50386.9957 Jul 11 400358.2 447.555618 -20321.5674 Aug 11 401763.7 452.679427 -28162.1012 Sep 11 396409.4 422.558617 -2297.3555 Oct 11 394245.7 409.610862 40179.8198 Nov 11 390414.7 389.053425 40699.2955 Dec 11 391782.2 393.695479 -47402.5695 Jan 12 391699.1 391.448407 20234.9479 Feb 12 390328.9 383.078980 -19672.9102 Mar 12 390839.2 383.694103 46454.3679 Apr 12 393555.6 395.223169 17503.9967 May 12 393354.5 392.223896 -7805.6835 Jun 12 392870.7 387.780851 -51518.6999 Jul 12 396838.0 405.877390 -12943.9971 Aug 12 397775.8 408.526906 -24600.7536 Sep 12 404837.7 440.911726 10332.5734 Oct 12 406891.9 448.556149 41596.4143 Nov 12 410122.7 461.418765 43966.9042 Dec 12 405937.0 440.300849 -55220.1975 Jan 13 402250.2 421.668059 17226.6292 Feb 13 407863.6 445.202756 -10305.5035 Mar 13 410380.9 454.705724 45491.0548 Apr 13 411830.7 459.335761 18131.4808 May 13 410958.1 453.063918 -11080.8815 Jun 13 413395.3 462.459610 -50843.4065 Jul 13 409051.3 439.764560 -23721.3582 Aug 13 410428.0 444.138575 -25163.5972 Sep 13 415757.2 466.544223 16090.4558 Oct 13 421489.2 490.202902 46926.0410 Nov 13 412873.6 450.062744 30651.2924 Dec 13 415747.0 460.598575 -45788.0221 Jan 14 420461.5 478.977979 18554.0458 Feb 14 415940.8 457.345191 -21589.0878 Mar 14 418074.7 464.651203 50473.7979 Apr 14 419457.0 468.687446 19260.1557 May 14 428287.3 505.761670 1057.4461 Jun 14 425245.0 489.975700 -58624.4925 Jul 14 421585.1 471.562185 -30210.1920 Aug 14 416481.6 447.045189 -35077.8762 Sep 14 415629.8 441.410991 15887.6133 Oct 14 415058.6 437.087954 50432.9380 Nov 14 425819.7 480.508080 44747.0311 Dec 14 431610.6 502.591703 -44590.6639 Jan 15 430633.7 496.475242 15900.0438 Feb 15 436084.4 516.951800 -15032.2706 Mar 15 445204.4 552.650079 58818.0501 Apr 15 459050.5 608.131828 31819.1016 May 15 445690.5 549.546758 -23175.1898 Jun 15 445217.3 545.249203 -48442.8499 Jul 15 449084.9 559.172226 -21385.2447 Aug 15 453230.5 574.093298 -31654.7242 Sep 15 454020.9 574.983368 11559.5741 Oct 15 465506.0 619.329788 59300.5111 Nov 15 465526.4 616.924527 34382.7061 Dec 15 471835.1 639.572942 -37062.8102 Jan 16 472599.2 640.065724 6888.5719 Feb 16 481663.0 673.357007 -9397.7207 Mar 16 490672.1 706.359036 62984.1072 Apr 16 477034.8 649.387944 13836.1687 May 16 477955.8 650.469980 -15823.4131 Jun 16 476306.0 641.303433 -55767.0073 > m$resid Jan Feb Mar Apr May 1 0.000000000 -1.117301355 1.032010858 0.014498137 -0.239197341 2 0.712522067 0.776717866 1.393985905 -0.107259699 -0.554992857 3 -0.610110523 -0.750552557 -0.031223764 0.139285460 -0.478626680 4 -0.070279296 -0.498793776 -0.786285806 0.240933668 0.102307941 5 0.092536737 0.797799762 0.760951518 -0.581220471 -0.019950647 6 -0.535547724 -0.098771089 1.429972576 0.310545835 -0.423404589 7 -0.266146016 0.070854247 -0.438737345 0.182790100 -0.621973859 8 0.934406093 -0.115572072 -0.358435500 -0.448237230 -1.511477084 9 -0.116926449 0.526313246 0.068439573 0.358610503 -0.866903136 10 0.622894426 -0.545831700 -0.784128645 0.130632278 0.083803006 11 1.007564468 0.569349060 1.026223914 -0.730353886 0.364810531 12 -0.075227991 -0.277870212 0.020049090 0.367769974 -0.094011039 13 -0.651398734 0.819267709 0.326910628 0.156981849 -0.210104064 14 0.671614509 -0.789255625 0.264629447 0.144818405 1.319679805 15 -0.233647538 0.782351539 1.358431368 2.098951592 -2.205448299 16 0.019669965 1.330640900 1.316686985 -2.265591116 0.042912288 Jun Jul Aug Sep Oct 1 -2.993509380 -1.990594012 1.370290921 1.904834136 2.623127404 2 -1.637643332 -0.310453304 0.728295325 1.266093543 1.893840372 3 -0.285590560 1.100226092 0.906478137 0.894926957 1.346040078 4 0.072054162 -1.123278373 0.746540381 0.588113793 0.180648389 5 -0.416375696 -0.623517433 -0.149192188 0.544646867 -0.084231217 6 -0.762323071 -0.248716594 0.120140698 0.764353465 0.915368660 7 -0.501846994 -0.942479958 -0.997434933 -0.320208573 1.150773601 8 -0.099079250 2.250494192 -0.491804093 0.552632534 0.939894896 9 -0.659720942 -0.849936168 -0.302247240 -0.201953973 4.645075463 10 0.192215636 -0.062327323 -0.598846569 1.275952012 -2.997907104 11 -0.365431334 0.170163250 0.151053731 -0.916086792 -0.408125724 12 -0.138115650 0.564531625 0.083902895 1.049949802 0.254643485 13 0.313015482 -0.758398044 0.147865369 0.771146853 0.831310543 14 -0.560010433 -0.655076283 -0.880184262 -0.205099350 -0.159911912 15 -0.161499430 0.524653645 0.566405869 0.034157737 1.723404636 16 -0.363347026 Nov Dec 1 0.913566265 -3.398488672 2 -0.060652636 -0.738655697 3 1.171375115 0.253535992 4 0.201969807 -0.008395365 5 1.853269208 0.323228694 6 0.362371296 -0.239475093 7 1.798303553 1.224236871 8 -0.245406912 -0.156618491 9 2.759844178 1.503999460 10 -0.222151033 -0.467504813 11 -0.669263363 0.154411124 12 0.439206616 -0.733559642 13 -1.437753745 0.382629853 14 1.630505952 0.838697468 15 -0.094601103 0.899145606 16 > 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/1yagv1322507178.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/2id4n1322507178.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/33hcz1322507178.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/46o5j1322507178.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/50adq1322507178.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/6d03f1322507178.tab") > > try(system("convert tmp/1yagv1322507178.ps tmp/1yagv1322507178.png",intern=TRUE)) character(0) > try(system("convert tmp/2id4n1322507178.ps tmp/2id4n1322507178.png",intern=TRUE)) character(0) > try(system("convert tmp/33hcz1322507178.ps tmp/33hcz1322507178.png",intern=TRUE)) character(0) > try(system("convert tmp/46o5j1322507178.ps tmp/46o5j1322507178.png",intern=TRUE)) character(0) > try(system("convert tmp/50adq1322507178.ps tmp/50adq1322507178.png",intern=TRUE)) character(0) > > > proc.time() user system elapsed 3.601 0.281 3.949