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(153.4,145,137.7,148.3,152.2,169.4,168.6,161.1,174.1,179,190.6,190,181.6,174.8,180.5,196.8,193.8,197,216.3,221.4,217.9,229.7,227.4,204.2,196.6,198.8,207.5,190.7,201.6,210.5,223.5,223.8,231.2,244,234.7,250.2,265.7,287.6,283.3,295.4,312.3,333.8,347.7,383.2,407.1,413.6,362.7,321.9,239.4,191,159.7,163.4,157.6,166.2,176.7,198.3,226.2,216.2,235.9,226.9) > 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 0.00000 199.67612 0.00000 22.52957 > m$fitted level slope sea Jan 1 153.4000 0.0000000 0.000000000 Feb 1 145.8762 -7.4413438 -0.041232530 Mar 1 137.7912 -7.9919545 -0.039872907 Apr 1 147.0035 6.8685427 -0.056557445 May 1 152.3736 5.5729684 -0.056394802 Jun 1 168.6208 14.8031709 -0.055956735 Jul 1 169.7278 2.9600452 -0.056216732 Aug 1 161.9930 -6.2877328 -0.056239825 Sep 1 172.8174 8.5089496 -0.056253397 Oct 1 179.2210 6.6884623 -0.056252615 Nov 1 190.3118 10.4951527 -0.056252804 Dec 1 190.8364 1.8736586 -0.056252957 Jan 2 182.9387 -6.4811146 -0.582679721 Feb 2 174.8607 -7.7079295 0.032324002 Mar 2 179.5602 3.0789027 -0.009631642 Apr 2 195.8108 14.4475557 -0.033787122 May 2 195.0217 1.2764642 -0.029947080 Jun 2 196.9768 1.8633542 -0.029902869 Jul 2 215.0602 15.8892025 -0.029320224 Aug 2 222.1202 8.2545990 -0.029364317 Sep 2 218.8324 -1.7259552 -0.029349831 Oct 2 228.8134 8.3969163 -0.029358049 Nov 2 228.1391 0.5531101 -0.029357152 Dec 2 206.0045 -19.0647903 -0.029357700 Jan 3 195.0031 -12.1433737 0.970670268 Feb 3 197.7973 -0.2898752 0.054304444 Mar 3 206.7570 7.7403278 0.031125660 Apr 3 192.3613 -11.3746431 0.061229994 May 3 200.0511 5.1065750 0.057668664 Jun 3 210.0586 9.3445948 0.057905284 Jul 3 223.1489 12.5835580 0.058005007 Aug 3 224.6121 2.9678297 0.057963847 Sep 3 230.8836 5.8244438 0.057960774 Oct 3 243.4171 11.6257534 0.057957283 Nov 3 236.1224 -4.7346217 0.057958670 Dec 3 248.7812 10.3053009 0.057958982 Jan 4 265.4612 15.7876100 -0.257289047 Feb 4 287.1400 20.5494542 0.067938579 Mar 4 284.9434 0.8183260 0.113214930 Apr 4 294.6073 8.4587809 0.103655640 May 4 311.5351 15.7806327 0.102398825 Jun 4 333.2343 20.8985526 0.102625818 Jul 4 348.0717 15.6574577 0.102497632 Aug 4 381.6920 31.1898067 0.102550447 Sep 4 407.4244 26.4708508 0.102554480 Oct 4 414.9776 10.1128704 0.102562299 Nov 4 367.1321 -40.0031875 0.102565674 Dec 4 322.1843 -44.2787806 0.102565604 Jan 5 244.6914 -72.8749402 -2.703855832 Feb 5 189.4358 -58.4622990 0.356139455 Mar 5 157.3462 -35.5976923 0.312599188 Apr 5 160.1296 -2.4394175 0.278187741 May 5 157.3485 -2.7348290 0.278229801 Jun 5 165.1009 6.3336807 0.278563418 Jul 5 176.0595 10.3328855 0.278644548 Aug 5 197.1775 19.6587058 0.278670851 Sep 5 225.2621 26.9444974 0.278665687 Oct 5 218.5543 -2.1543367 0.278677224 Nov 5 234.2266 13.2601649 0.278676363 Dec 5 228.1354 -3.4727710 0.278676134 > m$resid Jan Feb Mar Apr May Jun 1 0.00000000 -0.55795053 -0.03974930 1.05522811 -0.09168814 0.65320789 2 -0.62734126 -0.08404171 0.74905693 0.80214830 -0.93208400 0.04153274 3 0.50947157 0.82143494 0.56038231 -1.34975235 1.16633562 0.29991462 4 0.39956995 0.33184579 -1.38090747 0.53975491 0.51815026 0.36218346 5 -2.07189404 1.00769419 1.60325200 2.34314407 -0.02090560 0.64175810 Jul Aug Sep Oct Nov Dec 1 -0.83811543 -0.65444677 1.04713164 -0.12883225 0.26939188 -0.61012591 2 0.99258012 -0.54028563 -0.70630387 0.71637538 -0.55509048 -1.38831961 3 0.22921476 -0.68048587 0.20215687 0.41054708 -1.15779105 1.06434526 4 -0.37090156 1.09919329 -0.33395108 -1.15762158 -3.54661325 -0.30257517 5 0.28301558 0.65996966 0.51560091 -2.05926633 1.09085347 -1.18415643 > 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/13lun1260375315.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/2d7qr1260375315.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/3tlt91260375315.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/4bfs61260375315.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/5zg5l1260375315.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/64pn01260375315.tab") > system("convert tmp/13lun1260375315.ps tmp/13lun1260375315.png") > system("convert tmp/2d7qr1260375315.ps tmp/2d7qr1260375315.png") > system("convert tmp/3tlt91260375315.ps tmp/3tlt91260375315.png") > system("convert tmp/4bfs61260375315.ps tmp/4bfs61260375315.png") > system("convert tmp/5zg5l1260375315.ps tmp/5zg5l1260375315.png") > > > proc.time() user system elapsed 1.305 0.816 2.295