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(3.2,1.9,0,0.6,0.2,0.9,2.4,4.7,9.4,12.5,15.8,18.2,16.8,17.3,19.3,17.9,20.2,18.7,20.1,18.2,18.4,18.2,18.9,19.9,21.3,20,19.5,19.6,20.9,21,19.9,19.6,20.9,21.7,22.9,21.5,21.3,23.5,21.6,24.5,22.2,23.5,20.9,20.7,18.1,17.1,14.8,13.8,15.2,16,17.6,15,15,16.3,19.4,21.3,20.5,21.1,21.6,22.6) > 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 1.9042619 0.1475774 0.0000000 0.1624046 > m$fitted level slope sea Jan 1 3.2000000 0.000000000 0.000000000 Feb 1 1.9995047 -0.096405475 -0.065558422 Mar 1 0.1908328 -0.312752838 -0.073128735 Apr 1 0.6240036 -0.187613814 -0.072621444 May 1 0.2823410 -0.217751253 -0.072672784 Jun 1 0.9200610 -0.035453186 -0.072462736 Jul 1 2.3818301 0.299377440 -0.072180703 Aug 1 4.6539133 0.752817338 -0.071896409 Sep 1 9.2432280 1.648576918 -0.071475197 Oct 1 12.4773047 2.022091553 -0.071342939 Nov 1 15.7945783 2.328777289 -0.071260980 Dec 1 18.2629953 2.361939379 -0.071254283 Jan 2 17.5556053 1.662238375 -0.581443129 Feb 2 17.3664365 1.238673911 0.009800977 Mar 2 19.2516378 1.392595164 0.010153297 Apr 2 18.0412349 0.771912673 0.012331687 May 2 20.1119731 1.081555734 0.011389514 Jun 2 18.8269711 0.517430047 0.012705122 Jul 2 20.0461639 0.684705784 0.012409439 Aug 2 18.3286520 0.112098908 0.013175760 Sep 2 18.3898193 0.099958276 0.013188060 Oct 2 18.2036552 0.031753245 0.013240368 Nov 2 18.8505204 0.178385686 0.013155240 Dec 2 19.8390842 0.371523090 0.013070362 Jan 3 21.1804051 0.598864810 0.063483205 Feb 3 20.1102101 0.211804411 -0.030985241 Mar 3 19.5753345 0.033863729 -0.031224250 Apr 3 19.6300082 0.038827229 -0.031236180 May 3 20.8614387 0.323204408 -0.031825309 Jun 3 21.0402920 0.288789392 -0.031770692 Jul 3 20.0093120 -0.025836540 -0.031392255 Aug 3 19.6509543 -0.105105869 -0.031320068 Sep 3 20.8542718 0.206807187 -0.031535095 Oct 3 21.6942243 0.357743102 -0.031613862 Nov 3 22.8826362 0.555769245 -0.031692091 Dec 3 21.6378971 0.126534102 -0.031563732 Jan 4 21.0874129 -0.033110341 0.252036434 Feb 4 23.3795236 0.510000452 0.003133829 Mar 4 21.7252271 -0.005828390 0.002621676 Apr 4 24.3436077 0.620017277 0.001502915 May 4 22.3517192 -0.002767207 0.002462206 Jun 4 23.4337945 0.255871862 0.002157034 Jul 4 21.0529673 -0.372713902 0.002719148 Aug 4 20.6963339 -0.368880398 0.002716552 Sep 4 18.2213964 -0.870952048 0.002973874 Oct 4 17.1111365 -0.928002002 0.002996008 Nov 4 14.8742138 -1.240045971 0.003087652 Dec 4 13.7878446 -1.203409416 0.003079507 Jan 5 14.8621783 -0.664791237 0.204638845 Feb 5 15.9136832 -0.262205279 -0.003326302 Mar 5 17.4941345 0.176993522 -0.002979689 Apr 5 15.1508975 -0.424013709 -0.002125290 May 5 14.9868535 -0.362027982 -0.002201218 Jun 5 16.2090184 0.015661653 -0.002555601 Jul 5 19.2258478 0.731143433 -0.003064393 Aug 5 21.2281614 1.034187416 -0.003227545 Sep 5 20.6011677 0.638166062 -0.003066145 Oct 5 21.1106560 0.607489454 -0.003056681 Nov 5 21.6094689 0.581580907 -0.003050630 Dec 5 22.5800906 0.674329108 -0.003067027 > m$resid Jan Feb Mar Apr May Jun 1 0.000000000 -0.521277101 -1.154024869 0.487860233 -0.098739107 0.541297889 2 -2.223148378 -0.961823883 0.401473176 -1.613844482 0.805372772 -1.467773071 3 0.652737532 -0.930137404 -0.463518496 0.012905258 0.739681298 -0.089544821 4 -0.444018015 1.335533879 -1.343441726 1.627707167 -1.620221873 0.673034076 5 1.474015327 1.002628749 1.143743435 -1.563387951 0.161279918 0.982897285 Jul Aug Sep Oct Nov Dec 1 0.939878725 1.232494506 2.390246524 0.986200255 0.804855845 0.086727621 2 0.435315568 -1.490316658 -0.031600386 -0.177535076 0.381687008 0.502746641 3 -0.818787584 -0.206314774 0.811869916 0.392881326 0.515466486 -1.117322128 4 -1.635950694 0.009977867 -1.306857082 -0.148501055 -0.812263279 0.095367314 5 1.862179511 0.788782569 -1.030829126 -0.079851821 -0.067441303 0.241430135 > 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/10vmd1259947568.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/2w2kl1259947568.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/3zi5h1259947568.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/42b351259947568.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/5flp51259947568.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/6ovqn1259947568.tab") > system("convert tmp/10vmd1259947568.ps tmp/10vmd1259947568.png") > system("convert tmp/2w2kl1259947568.ps tmp/2w2kl1259947568.png") > system("convert tmp/3zi5h1259947568.ps tmp/3zi5h1259947568.png") > system("convert tmp/42b351259947568.ps tmp/42b351259947568.png") > system("convert tmp/5flp51259947568.ps tmp/5flp51259947568.png") > > > proc.time() user system elapsed 1.316 0.795 1.556