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(2756.76,2849.27,2921.44,2981.85,3080.58,3106.22,3119.31,3061.26,3097.31,3161.69,3257.16,3277.01,3295.32,3363.99,3494.17,3667.03,3813.06,3917.96,3895.51,3801.06,3570.12,3701.61,3862.27,3970.1,4138.52,4199.75,4290.89,4443.91,4502.64,4356.98,4591.27,4696.96,4621.4,4562.84,4202.52,4296.49,4435.23,4105.18,4116.68,3844.49,3720.98,3674.4,3857.62,3801.06,3504.37,3032.6,3047.03,2962.34,2197.82,2014.45,1862.83,1905.41,1810.99,1670.07,1864.44,2052.02,2029.6,2070.83,2293.41,2443.27) > 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 24232.055 1533.668 0.000 0.000 > m$fitted level slope sea Jan 1 2756.760 0.000000 0.0000000 Feb 1 2844.556 6.572770 4.7138567 Mar 1 2916.671 13.758946 4.7689211 Apr 1 2977.048 20.633884 4.8023105 May 1 3075.732 34.222955 4.8484799 Jun 1 3101.376 32.576869 4.8443789 Jul 1 3114.473 28.616441 4.8369603 Aug 1 3056.449 10.378440 4.8109097 Sep 1 3092.493 15.895366 4.8169678 Oct 1 3156.864 26.447891 4.8259194 Nov 1 3252.324 41.585950 4.8358677 Dec 1 3272.177 36.796619 4.8334252 Jan 2 3336.962 42.727496 -41.6421759 Feb 2 3360.633 38.661167 3.3570419 Mar 2 3490.892 58.973677 3.2782109 Apr 2 3663.828 84.249049 3.2018838 May 2 3809.890 97.959892 3.1696670 Jun 2 3914.793 99.500052 3.1668510 Jul 2 3892.305 72.437073 3.2053509 Aug 2 3797.814 35.402046 3.2463453 Sep 2 3566.823 -23.703398 3.2972513 Oct 2 3698.336 10.736326 3.2741717 Nov 2 3859.013 44.006558 3.2568235 Dec 2 3966.849 58.169887 3.2510771 Jan 3 4149.967 85.487429 -11.4473847 Feb 3 4199.232 77.657111 0.5175591 Mar 3 4290.381 80.653053 0.5094367 Apr 3 4443.434 96.724960 0.4755167 May 3 4502.151 88.289323 0.4893718 Jun 3 4356.424 36.357710 0.5557458 Jul 3 4590.758 80.289317 0.5120541 Aug 3 4696.452 85.926678 0.5076916 Sep 3 4620.871 50.088249 0.5292716 Oct 3 4562.299 25.976763 0.5405686 Nov 3 4201.948 -59.749849 0.5718212 Dec 3 4295.928 -25.636802 0.5621446 Jan 4 4422.086 7.727539 13.1440201 Feb 4 4109.784 -61.929438 -4.6039423 Mar 4 4121.317 -45.618532 -4.6368196 Apr 4 3849.048 -95.927569 -4.5578935 May 4 3725.530 -102.050681 -4.5504182 Jun 4 3678.962 -89.738305 -4.5621149 Jul 4 3862.227 -29.157145 -4.6068973 Aug 4 3805.663 -35.238700 -4.6033993 Sep 4 3508.947 -93.261146 -4.5774311 Oct 4 3037.148 -177.259938 -4.5481794 Nov 4 3051.590 -134.720541 -4.5597059 Dec 4 2966.902 -123.617954 -4.5620467 Jan 5 2207.763 -263.650756 -9.9434802 Feb 5 2012.965 -248.603686 1.4849859 Mar 5 1861.379 -227.064987 1.4505068 Apr 5 1904.034 -167.198964 1.3759091 May 5 1809.630 -151.043719 1.3602441 Jun 5 1668.711 -148.796739 1.3585487 Jul 5 1863.126 -72.635367 1.3138338 Aug 5 2050.733 -14.886339 1.2874523 Sep 5 2028.312 -16.558226 1.2880466 Oct 5 2069.546 -3.733923 1.2844997 Nov 5 2292.136 46.488969 1.2736915 Dec 5 2442.000 69.428625 1.2698503 > m$resid Jan Feb Mar Apr May Jun 1 0.00000000 0.33485611 0.39764465 0.27672398 0.45595624 -0.04956842 2 0.18509704 -0.09090001 0.51858432 0.64533372 0.35008195 0.03932627 3 0.76665883 -0.18527820 0.07638724 0.41002474 -0.21528567 -1.32563083 4 0.90770483 -1.68562661 0.41603367 -1.28377041 -0.15628925 0.31431768 5 -3.75065327 0.36858795 0.54950211 1.52785457 0.41238893 0.05736515 Jul Aug Sep Oct Nov Dec 1 -0.11174082 -0.49470771 0.14612296 0.27549291 0.39176813 -0.12329223 2 -0.69103397 -0.94567220 -1.50923884 0.87941055 0.84954964 0.36165863 3 1.12156519 0.14393206 -0.91506395 -0.61565732 -2.18896256 0.87105944 4 1.54670297 -0.15527789 -1.48151671 -2.14483044 1.08621789 0.28350013 5 1.94454261 1.47451013 -0.04268963 0.32745879 1.28241660 0.58575641 > 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/19ln31259919471.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/20cuq1259919471.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/399s81259919471.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/4e8bf1259919471.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/5emrq1259919471.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/6ofv91259919471.tab") > > system("convert tmp/19ln31259919471.ps tmp/19ln31259919471.png") > system("convert tmp/20cuq1259919471.ps tmp/20cuq1259919471.png") > system("convert tmp/399s81259919471.ps tmp/399s81259919471.png") > system("convert tmp/4e8bf1259919471.ps tmp/4e8bf1259919471.png") > system("convert tmp/5emrq1259919471.ps tmp/5emrq1259919471.png") > > > proc.time() user system elapsed 1.403 0.827 3.169