R version 2.15.2 (2012-10-26) -- "Trick or Treat" Copyright (C) 2012 The R Foundation for Statistical Computing ISBN 3-900051-07-0 Platform: i686-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(46,62,66,59,58,61,41,27,58,70,49,59,44,36,72,45,56,54,53,35,61,52,47,51,52,63,74,45,51,64,36,30,55,64,39,40,63,45,59,55,40,64,27,28,45,57,45,69,60,56,58,50,51,53,37,22,55,70,62,58,39,49,58,47,42,62,39,40,72,70,54,65) > 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 1.489593 0.000000 12.250964 73.216610 > m$fitted level slope sea Jan 1 46.00000 0.00000000 0.0000000 Feb 1 47.91108 0.45772406 3.2729431 Mar 1 52.21815 1.23550515 3.1103923 Apr 1 54.80852 1.45917164 0.8854140 May 1 56.45329 1.48495789 1.0975000 Jun 1 58.30254 1.52861925 1.7877365 Jul 1 55.50976 1.07340991 -3.2048306 Aug 1 49.86601 0.44240453 -4.3679817 Sep 1 51.13490 0.51245455 4.4694784 Oct 1 55.14969 0.78286216 4.1917807 Nov 1 54.83126 0.70478025 -2.3247826 Dec 1 55.92697 0.73040832 1.7757929 Jan 2 56.33223 0.73655616 -10.1265569 Feb 2 53.31611 0.55136779 -4.8504936 Mar 2 56.14621 0.67845888 9.1817277 Apr 2 55.05810 0.58285246 -4.7436035 May 2 55.42482 0.57181165 1.2602135 Jun 2 55.12172 0.52978632 1.7912389 Jul 2 55.20652 0.50964904 -0.6614253 Aug 2 53.29288 0.40599357 -9.5756859 Sep 2 54.04462 0.42001787 5.6738770 Oct 2 53.51617 0.38345050 2.0913550 Nov 2 53.18381 0.35732989 -3.3930765 Dec 2 52.75764 0.33182114 1.4235162 Jan 3 53.39369 0.33446682 -2.9124829 Feb 3 55.75063 0.38638317 -1.0805012 Mar 3 57.49724 0.42979444 11.3354837 Apr 3 57.00921 0.39955525 -8.5554331 May 3 56.16349 0.35939414 -0.4099527 Jun 3 57.00852 0.37447902 5.1008697 Jul 3 54.46466 0.28752175 -6.8832293 Aug 3 52.37783 0.21965629 -12.7911150 Sep 3 51.68268 0.19456135 7.0681779 Oct 3 52.89498 0.22128093 6.8713067 Nov 3 51.85391 0.19013468 -7.5133996 Dec 3 50.31703 0.15340041 -2.7811444 Jan 4 52.13367 0.17285145 2.9916185 Feb 4 51.87769 0.16516410 -4.9898494 Mar 4 51.30819 0.14894084 10.7700741 Apr 4 52.71549 0.17850630 -2.9123357 May 4 51.46081 0.14474089 -5.5262808 Jun 4 51.91140 0.15179678 10.8107602 Jul 4 49.56963 0.09598691 -12.0404445 Aug 4 48.13984 0.06298116 -13.6291438 Sep 4 46.77356 0.03319338 4.3873025 Oct 4 46.77650 0.03259078 10.3552839 Nov 4 47.29314 0.04157414 -4.4294779 Dec 4 50.41295 0.09094614 4.7042797 Jan 5 51.59054 0.10364592 3.3274222 Feb 5 52.92268 0.12120217 -2.4892211 Mar 5 52.66961 0.11488016 6.9761001 Apr 5 52.58734 0.11130456 -1.7314572 May 5 53.05285 0.11784195 -3.5885917 Jun 5 51.55487 0.08828470 8.4802755 Jul 5 50.88449 0.07470688 -10.5601552 Aug 5 48.87964 0.03855472 -17.7022885 Sep 5 48.85522 0.03749824 6.4247831 Oct 5 50.27520 0.05962355 13.5276374 Nov 5 52.78821 0.09614114 -1.8991991 Dec 5 53.47354 0.10387366 1.8186635 Jan 6 51.83046 0.08474324 -4.6598879 Feb 6 51.56944 0.08054891 -0.9766265 Mar 6 51.45750 0.07790217 7.4130045 Apr 6 51.12403 0.07184414 -2.2821231 May 6 50.23679 0.05736287 -3.9530552 Jun 6 50.36814 0.05847914 11.3007753 Jul 6 50.11049 0.05378350 -9.6901483 Aug 6 51.05559 0.06669323 -15.0807023 Sep 6 53.13715 0.09489685 9.7118707 Oct 6 54.17714 0.10752073 11.5025732 Nov 6 54.63671 0.11191017 -2.2587760 Dec 6 55.54991 0.12092731 5.7212848 > m$resid Jan Feb Mar Apr May Jun 1 0.00000000 1.53740451 1.66338386 0.52467341 0.07120277 0.14326850 2 -0.32951888 -1.97251267 1.08290458 -0.86275851 -0.11064540 -0.46807717 3 0.23801240 1.33111768 0.83617466 -0.56070375 -0.77134109 0.30631990 4 1.25745344 -0.30371123 -0.49870628 0.84437967 -0.96476055 0.20764619 5 0.81793913 0.89873111 -0.26678153 -0.13905229 0.24969376 -1.14380920 6 -1.31979261 -0.25765731 -0.14115327 -0.29914876 -0.69622575 0.05381792 Jul Aug Sep Oct Nov Dec 1 -1.76638756 -2.86761758 0.36866959 1.62955341 -0.53300378 0.19619183 2 -0.24720098 -1.38968831 0.20369162 -0.57195297 -0.44129416 -0.50031233 3 -1.87338611 -1.54838802 -0.60498508 0.68191892 -0.85853993 -1.20701560 4 -1.70966313 -1.05627182 -0.99862596 -0.02133906 0.34539382 2.23926443 5 -0.54028242 -1.49072514 -0.04545185 1.00512116 1.80000346 0.43800169 6 -0.23083307 0.65391133 1.48588762 0.70103346 0.26297524 0.60390689 > 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/fisher/rcomp/tmp/1ufo11353760598.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/fisher/rcomp/tmp/2q2nm1353760598.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/fisher/rcomp/tmp/3vawp1353760598.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/fisher/rcomp/tmp/4h1ps1353760598.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',type='b') > grid() > dev.off() null device 1 > postscript(file="/var/fisher/rcomp/tmp/5y1c51353760598.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/fisher/rcomp/createtable file can be downloaded at http://www.wessa.net/cretab > load(file="/var/fisher/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/fisher/rcomp/tmp/60gbv1353760598.tab") > > try(system("convert tmp/1ufo11353760598.ps tmp/1ufo11353760598.png",intern=TRUE)) character(0) > try(system("convert tmp/2q2nm1353760598.ps tmp/2q2nm1353760598.png",intern=TRUE)) character(0) > try(system("convert tmp/3vawp1353760598.ps tmp/3vawp1353760598.png",intern=TRUE)) character(0) > try(system("convert tmp/4h1ps1353760598.ps tmp/4h1ps1353760598.png",intern=TRUE)) character(0) > try(system("convert tmp/5y1c51353760598.ps tmp/5y1c51353760598.png",intern=TRUE)) character(0) > > > proc.time() user system elapsed 3.564 0.688 4.261