R version 2.9.0 (2009-04-17) Copyright (C) 2009 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(423.4,404.1,500,472.6,496.1,562,434.8,538.2,577.6,518.1,625.2,561.2,523.3,536.1,607.3,637.3,606.9,652.9,617.2,670.4,729.9,677.2,710,844.3,748.2,653.9,742.6,854.2,808.4,1819,1936.5,1966.1,2083.1,1620.1,1527.6,1795,1685.1,1851.8,2164.4,1981.8,1726.5,2144.6,1758.2,1672.9,1837.3,1596.1,1446,1898.4,1964.1,1755.9,2255.3,1881.2,2117.9,1656.5,1544.1,2098.9,2133.3,1963.5,1801.2,2365.4,1936.5,1667.6,1983.5,2058.6,2448.3,1858.1,1625.4,2130.6,2515.7,2230.2,2086.9,2235,2100.2,2288.6,2490,2573.7,2543.8,2004.7,2390,2338.4,2724.5,2292.5,2386,2477.9,2337,2605.1,2560.8,2839.3,2407.2,2085.2,2735.6,2798.7,3053.2,2405,2471.9,2727.3,2790.7,2385.4,3206.6,2705.6,3518.4,1954.9,2584.3,2535.8,2685.9,2866,2236.6,2934.9,2668.6,2371.2,3165.9,2887.2,3112.2,2671.2,2432.6,2812.3,3095.7,2862.9,2607.3,2862.5) > par1 = '12' > #'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!) > par1 <- as.numeric(par1) > nx <- length(x) > x <- ts(x,frequency=par1) > m <- StructTS(x,type='BSM') > m$coef level slope seas epsilon 8908.430 0.000 2522.755 29750.902 > m$fitted level slope sea Jan 1 423.4000 0.0000000 0.0000000 Feb 1 414.6816 -0.7970565 -1.9372848 Mar 1 451.4604 1.9630156 10.7048791 Apr 1 461.9204 2.4272404 1.1989490 May 1 476.5851 2.9534039 5.1084252 Jun 1 511.9186 4.1215296 10.8796997 Jul 1 483.3610 3.0799529 -8.3828815 Aug 1 504.4045 3.6047445 11.5128158 Sep 1 534.8797 4.3419840 9.2102893 Oct 1 530.2787 4.1079645 -0.9879497 Nov 1 568.2572 4.9614111 14.4621527 Dec 1 567.9382 4.8325331 -0.1044200 Jan 2 572.1050 4.8949141 -47.8183911 Feb 2 562.1877 4.4331019 -10.9255771 Mar 2 577.3994 4.7997455 18.6389051 Apr 2 603.6723 5.3870634 9.4522329 May 2 608.5028 5.3748347 -0.9508445 Jun 2 622.1191 5.5280733 20.9410222 Jul 2 627.5473 5.5264188 -10.2269553 Aug 2 643.5668 5.6874346 14.1238750 Sep 2 675.8027 6.0745936 21.8533398 Oct 2 683.5209 6.0977256 -8.3203991 Nov 2 691.2736 6.1200866 16.7103912 Dec 2 752.3655 6.6793328 24.6177126 Jan 3 777.5965 6.0312124 -53.9259589 Feb 3 741.1385 5.3467646 -39.9442839 Mar 3 736.5036 5.1193925 16.9095227 Apr 3 779.5469 5.8736632 31.9568568 May 3 797.3890 6.0692366 -2.8476221 Jun 3 1170.1565 11.1366677 217.8728360 Jul 3 1488.2801 14.8987517 84.6909338 Aug 3 1691.3692 17.0298511 51.0021300 Sep 3 1849.5100 18.5486157 65.4715074 Oct 3 1788.4777 17.7261833 -73.4368118 Nov 3 1694.6573 16.6717883 -33.7550595 Dec 3 1726.1920 16.7483788 50.9301593 Jan 4 1760.3408 16.4555387 -97.1265453 Feb 4 1824.1992 16.9218919 -26.5977919 Mar 4 1960.5376 18.9332151 71.8644862 Apr 4 1979.4748 18.9332780 2.3207703 May 4 1939.3789 18.1296235 -144.9500311 Jun 4 1974.7923 18.3302202 149.6649619 Jul 4 1899.1305 17.3659909 -30.6418283 Aug 4 1816.2256 16.4204910 -25.2428047 Sep 4 1792.8065 16.0659005 91.5049021 Oct 4 1743.5280 15.5183945 -70.2108517 Nov 4 1654.7642 14.7711029 -85.2845219 Dec 4 1727.4159 14.9487957 102.0202640 Jan 5 1861.0498 13.9421766 -42.1591938 Feb 5 1862.4841 13.8559091 -92.1321509 Mar 5 1990.1703 15.3475787 137.5123834 Apr 5 1963.1001 14.7804943 -33.9229053 May 5 2080.5098 15.9961107 -80.4661268 Jun 5 1880.2029 13.7773130 27.3902220 Jul 5 1753.9077 12.5059259 -46.1741826 Aug 5 1877.4700 13.4266587 91.2347352 Sep 5 1942.4991 13.8252904 130.1808088 Oct 5 1978.9310 13.9851713 -42.0292613 Nov 5 1966.1032 13.8324159 -133.2890561 Dec 5 2092.7341 14.0860404 138.9587606 Jan 6 2071.7821 14.2272949 -93.1080793 Feb 6 1978.7884 13.6464145 -186.7331527 Mar 6 1927.7831 12.9626505 128.9428333 Apr 6 1995.5739 13.5883505 0.7436903 May 6 2173.0115 15.3095152 87.1190956 Jun 6 2058.6866 14.1068456 -50.3475590 Jul 6 1934.8465 12.9690762 -148.6352924 Aug 6 1976.3929 13.1830799 120.7772038 Sep 6 2133.9452 14.1748974 212.5095849 Oct 6 2202.1783 14.5054764 -35.4542568 Nov 6 2234.0559 14.5876077 -167.5960932 Dec 6 2189.9057 14.4708948 114.5024394 Jan 7 2184.4254 14.5004053 -60.4498539 Feb 7 2292.5036 14.9332628 -112.7579211 Mar 7 2342.7187 15.2437090 107.0249446 Apr 7 2451.9692 16.1732639 14.4897245 May 7 2452.7657 16.0285108 108.7120754 Jun 7 2306.6213 14.6526231 -114.0598697 Jul 7 2394.6419 15.2097975 -90.0876758 Aug 7 2361.4348 14.8775510 33.5444692 Sep 7 2426.8042 15.1907343 238.5632350 Oct 7 2404.3379 14.9876387 -67.6638150 Nov 7 2458.4279 15.1473524 -118.3832749 Dec 7 2438.0905 15.0775961 81.6509690 Jan 8 2443.8768 15.0771170 -95.8742144 Feb 8 2557.2253 15.4870396 -66.5662736 Mar 8 2545.1630 15.2800292 47.2389522 Apr 8 2649.0549 16.0488256 88.7743203 May 8 2523.5770 14.8464124 46.5665050 Jun 8 2415.5917 13.8878115 -188.0833601 Jul 8 2557.6346 14.7900263 28.7696515 Aug 8 2652.6772 15.2989650 52.2883829 Sep 8 2722.6404 15.6085403 266.5732361 Oct 8 2651.8568 15.1902118 -145.5679708 Nov 8 2631.6012 15.0606449 -118.0740902 Dec 8 2645.2980 15.0578659 83.6075756 Jan 9 2750.2584 15.1475446 -65.5897576 Feb 9 2656.9706 14.7259312 -145.2126637 Mar 9 2845.0260 15.8633058 161.9631460 Apr 9 2766.2274 15.1345934 48.1254108 May 9 3014.6661 16.9337009 234.6972910 Jun 9 2745.4515 14.8720389 -458.8776763 Jul 9 2679.9128 14.3452340 -2.0050250 Aug 9 2615.6960 13.8822043 11.8428830 Sep 9 2538.2379 13.4055771 254.5490531 Oct 9 2704.2890 14.0798541 -17.1945059 Nov 9 2599.8967 13.6810622 -224.2395186 Dec 9 2698.6091 13.8626526 136.3106740 Jan 10 2717.6511 13.8709089 -55.1434237 Feb 10 2673.0594 13.6549473 -233.7052561 Mar 10 2790.3597 14.2601598 255.8276149 Apr 10 2839.5748 14.5013425 7.3564923 May 10 2831.3668 14.3415895 307.0617219 Jun 10 2934.6274 14.9346664 -366.5576613 Jul 10 2761.9964 13.7881684 -111.0193327 Aug 10 2766.6174 13.7377416 56.3865451 Sep 10 2813.7912 13.8997539 242.7881941 Oct 10 2837.3254 13.9391152 14.2855328 Nov 10 2854.0099 13.9478119 -249.9310277 Dec 10 2817.9611 13.8363005 103.2676044 > m$resid Jan Feb Mar Apr May 1 0.000000e+00 -7.488490e-02 3.310529e-01 8.067099e-02 1.207874e-01 2 -9.199731e-03 -1.338163e-01 1.001821e-01 2.115327e-01 -5.649452e-03 3 2.192124e-01 -4.179589e-01 -9.693776e-02 3.802851e-01 1.226491e-01 4 1.945892e-01 4.816968e-01 1.187639e+00 3.981898e-05 -6.075637e-01 5 1.292704e+00 -1.289622e-01 1.149504e+00 -4.323882e-01 1.059368e+00 6 -3.762788e-01 -1.113456e+00 -6.597020e-01 5.619603e-01 1.695243e+00 7 -2.125522e-01 9.755405e-01 3.626507e-01 9.678496e-01 -1.594217e-01 8 -9.852110e-02 1.026815e+00 -2.846607e-01 9.156869e-01 -1.470043e+00 9 9.506196e-01 -1.134704e+00 1.797919e+00 -9.812060e-01 2.427451e+00 10 5.467274e-02 -6.124210e-01 1.078237e+00 3.632420e-01 -2.366456e-01 Jun Jul Aug Sep Oct 1 3.261513e-01 -3.328519e-01 1.841404e-01 2.764989e-01 -9.224579e-02 2 8.485307e-02 -1.035297e-03 1.091875e-01 2.768105e-01 1.715782e-02 3 3.800159e+00 3.199291e+00 1.966948e+00 1.477215e+00 -8.338880e-01 4 1.796254e-01 -9.818392e-01 -1.050246e+00 -4.178981e-01 -6.860556e-01 5 -2.251656e+00 -1.465135e+00 1.164683e+00 5.419635e-01 2.376442e-01 6 -1.351051e+00 -1.444174e+00 2.999524e-01 1.517563e+00 5.687488e-01 7 -1.691843e+00 7.686040e-01 -5.085017e-01 5.310745e-01 -3.964239e-01 8 -1.282581e+00 1.343295e+00 8.432432e-01 5.752089e-01 -9.098411e-01 9 -2.990442e+00 -8.432595e-01 -8.257761e-01 -9.614370e-01 1.608048e+00 10 9.300138e-01 -1.967855e+00 -9.638610e-02 3.520257e-01 1.015143e-01 Nov Dec 1 3.499281e-01 -5.461637e-02 2 1.729112e-02 5.756947e-01 3 -1.169846e+00 1.564225e-01 4 -1.095868e+00 6.106236e-01 5 -2.821244e-01 1.191178e+00 6 1.829395e-01 -6.204180e-01 7 4.119925e-01 -3.747462e-01 8 -3.735899e-01 -1.439873e-02 9 -1.248915e+00 8.973979e-01 10 2.894536e-02 -5.274833e-01 > 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 > mylagmax <- nx/2 > postscript(file="/var/www/html/rcomp/tmp/1b5ly1259786589.ps",horizontal=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/www/html/rcomp/tmp/2i6471259786589.ps",horizontal=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/www/html/rcomp/tmp/3qcb21259786589.ps",horizontal=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/www/html/rcomp/tmp/4tcgt1259786589.ps",horizontal=F,pagecentre=F,paper="special",width=8.3333333333333,height=5.5555555555556) > plot(as.numeric(m$resid),main='Standardized Residuals',ylab='Residuals',xlab='time',type='b') > grid() > dev.off() null device 1 > postscript(file="/var/www/html/rcomp/tmp/57tla1259786589.ps",horizontal=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/www/html/rcomp/createtable file can be downloaded at http://www.wessa.net/cretab > load(file="/var/www/html/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/www/html/rcomp/tmp/62rqf1259786589.tab") > system("convert tmp/1b5ly1259786589.ps tmp/1b5ly1259786589.png") > system("convert tmp/2i6471259786589.ps tmp/2i6471259786589.png") > system("convert tmp/3qcb21259786589.ps tmp/3qcb21259786589.png") > system("convert tmp/4tcgt1259786589.ps tmp/4tcgt1259786589.png") > system("convert tmp/57tla1259786589.ps tmp/57tla1259786589.png") > > > proc.time() user system elapsed 1.837 0.871 2.294