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(14,14,15,13,8,7,3,3,4,4,0,-4,-14,-18,-8,-1,1,2,0,1,0,-1,-3,-3,-3,-4,-8,-9,-13,-18,-11,-9,-10,-13,-11,-5,-15,-6,-6,-3,-1,-3,-4,-6,0,-4,-2,-2,-6,-7,-6,-6,-3,-2,-5,-11,-11,-11,-10,-14,-8,-9,-5,-1,-2,-5,-4,-6,-2,-2,-2,-2,2,1,-8,-1,1,-1,2,2,1,-1,-2,-2,-1,-8,-4,-6,-3,-3,-7,-9,-11,-13,-11,-9,-17,-22,-25,-20,-24,-24,-22,-19,-18,-17,-11,-11,-12,-10,-15,-15,-15,-13,-8,-13,-9,-7,-4,-4,-2,0,-2,-3,1,-2,-1,1,-3,-4,-9,-9,-7,-14,-12,-16,-20,-12,-12,-10,-10,-13,-16) > 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 9.912185 0.000000 0.000000 1.467719 > m$fitted level slope sea Jan 1 14.000000000 0.0000000000 0.0000000000 Feb 1 14.000000000 0.0000000000 0.0000000000 Mar 1 14.876941307 0.0100435993 0.0100435993 Apr 1 13.218244176 -0.0001220537 -0.0001220537 May 1 8.625927439 -0.0251565998 -0.0251565998 Jun 1 7.214017270 -0.0325791928 -0.0325791928 Jul 1 3.529769839 -0.0519914511 -0.0519914511 Aug 1 3.103007508 -0.0539728517 -0.0539728517 Sep 1 3.933586596 -0.0493209452 -0.0493209452 Oct 1 4.029551657 -0.0485608772 -0.0485608772 Nov 1 0.519481126 -0.0665756158 -0.0665756158 Dec 1 -3.408238262 -0.0865661335 -0.0865661335 Jan 2 -10.313764960 0.2534184134 -2.7876025468 Feb 2 -17.373462693 0.0626025265 0.0626025258 Mar 2 -9.164404152 0.1054102252 0.1054102252 Apr 2 -2.043094455 0.1252132409 0.1252132409 May 2 0.546054691 0.1314636066 0.1314636066 Jun 2 1.728369220 0.1340888705 0.1340888705 Jul 2 0.100864146 0.1297055057 0.1297055057 Aug 2 0.795015078 0.1311062845 0.1311062845 Sep 2 -0.006702362 0.1287970817 0.1287970817 Oct 2 -0.981610564 0.1260716154 0.1260716154 Nov 2 -2.858919353 0.1211366979 0.1211366979 Dec 2 -3.076032802 0.1203055353 0.1203055353 Jan 3 -2.036418557 0.0985744330 -1.0843187597 Feb 3 -3.860147231 0.0659484135 0.0659484106 Mar 3 -7.562046954 0.0530797145 0.0530797145 Apr 3 -8.872179441 0.0505747865 0.0505747865 May 3 -12.555627115 0.0444023391 0.0444023391 Jun 3 -17.396900331 0.0364417858 0.0364417858 Jul 3 -11.776466367 0.0455118401 0.0455118401 Aug 3 -9.359751398 0.0493564660 0.0493564660 Sep 3 -9.962887701 0.0483002596 0.0483002596 Oct 3 -12.681618616 0.0438284462 0.0438284462 Nov 3 -11.230337726 0.0460993667 0.0460993667 Dec 3 -5.764310087 0.0548303181 0.0548303181 Jan 4 -12.383853810 0.1582272806 -1.7405000840 Feb 4 -6.836303919 0.2260062958 0.2260062939 Mar 4 -6.271120055 0.2268643653 0.2268643653 Apr 4 -3.555928466 0.2302538112 0.2302538112 May 4 -1.474811940 0.2325228776 0.2325228776 Jun 4 -3.000263568 0.2303976344 0.2303976344 Jul 4 -4.059957645 0.2288422225 0.2288422225 Aug 4 -5.949037163 0.2262922439 0.2262922439 Sep 4 -0.867699942 0.2321305738 0.2321305738 Oct 4 -3.812434408 0.2283149004 0.2283149004 Nov 4 -2.386527308 0.2297515801 0.2297515801 Dec 4 -2.221235916 0.2296743437 0.2296743437 Jan 5 -3.169771357 0.2432484842 -2.6757333241 Feb 5 -6.757244847 0.2049821946 0.2049821920 Mar 5 -6.245635196 0.2055981994 0.2055981994 Apr 5 -6.186295946 0.2054399220 0.2054399220 May 5 -3.528826165 0.2078287975 0.2078287975 Jun 5 -2.337523359 0.2087738647 0.2087738647 Jul 5 -4.849927230 0.2061653515 0.2061653515 Aug 5 -10.441599976 0.2006138406 0.2006138406 Sep 5 -11.088811265 0.1998028289 0.1998028289 Oct 5 -11.163593574 0.1995404182 0.1995404182 Nov 5 -10.288609818 0.2001852976 0.2001852976 Dec 5 -13.721148321 0.1967202635 0.1967202635 Jan 6 -7.283693119 0.1394895776 -1.5343853513 Feb 6 -8.913760245 0.1248288875 0.1248288853 Mar 6 -5.552946805 0.1302198933 0.1302198933 Apr 6 -1.630073554 0.1336244440 0.1336244440 May 6 -2.059462932 0.1331693658 0.1331693658 Jun 6 -4.759940653 0.1309098429 0.1309098429 Jul 6 -4.188882476 0.1312600116 0.1312600116 Aug 6 -5.889925790 0.1298036966 0.1298036966 Sep 6 -2.552305855 0.1323511938 0.1323511938 Oct 6 -2.165822798 0.1325528528 0.1325528528 Nov 6 -2.120998248 0.1324832938 0.1324832938 Dec 6 -2.115728241 0.1323825074 0.1323825074 Jan 7 2.494232576 0.0982786431 -1.0810650711 Feb 7 1.093654983 0.0876706207 0.0876706177 Mar 7 -7.006114655 0.0760199538 0.0760199538 Apr 7 -1.757138736 0.0799871790 0.0799871790 May 7 0.617960087 0.0815722844 0.0815722844 Jun 7 -0.874438875 0.0804997627 0.0804997627 Jul 7 1.603943804 0.0821301652 0.0821301652 Aug 7 1.890913490 0.0822693240 0.0822693240 Sep 7 1.040472479 0.0816361254 0.0816361254 Oct 7 -0.825356595 0.0803149299 0.0803149299 Nov 7 -1.925032805 0.0795149455 0.0795149455 Dec 7 -2.052302947 0.0793748489 0.0793748489 Jan 8 -0.437985189 0.0693777965 -0.7631557606 Feb 8 -7.192994852 0.0272229114 0.0272229092 Mar 8 -4.393080937 0.0306662535 0.0306662535 Apr 8 -5.836688467 0.0296793585 0.0296793585 May 8 -3.352498838 0.0311591674 0.0311591674 Jun 8 -3.064886416 0.0313117278 0.0313117278 Jul 8 -6.566664090 0.0292143171 0.0292143171 Aug 8 -8.739603185 0.0279080145 0.0279080145 Sep 8 -10.758701430 0.0266944883 0.0266944883 Oct 8 -12.759990347 0.0254929545 0.0254929545 Nov 8 -11.224124575 0.0263872858 0.0263872858 Dec 8 -9.278755133 0.0275228928 0.0275228928 Jan 9 -15.489500523 0.0630106089 -0.6931166953 Feb 9 -21.306267945 0.0307895098 0.0307895063 Mar 9 -24.593373896 0.0271343154 0.0271343154 Apr 9 -20.554665659 0.0295167988 0.0295167988 May 9 -23.622373384 0.0278600066 0.0278600066 Jun 9 -23.977515066 0.0276578358 0.0276578358 Jul 9 -22.250971931 0.0285528008 0.0285528008 Aug 9 -19.399603640 0.0300388076 0.0300388076 Sep 9 -18.185659383 0.0306617072 0.0306617072 Oct 9 -17.161282155 0.0311842643 0.0311842643 Nov 9 -11.739728148 0.0340173633 0.0340173633 Dec 9 -11.112051490 0.0343292180 0.0343292180 Jan 10 -11.536742699 0.0366471068 -0.4031181717 Feb 10 -10.203779156 0.0430305107 0.0430305076 Mar 10 -14.474696420 0.0387601583 0.0387601583 Apr 10 -14.968727759 0.0384758066 0.0384758066 May 10 -15.025906669 0.0384298221 0.0384298221 Jun 10 -13.264784421 0.0392470782 0.0392470782 Jul 10 -8.641559001 0.0414174814 0.0414174814 Aug 10 -12.525629097 0.0395600578 0.0395600578 Sep 10 -9.439820386 0.0410007413 0.0410007413 Oct 10 -7.314825638 0.0419858708 0.0419858708 Nov 10 -4.417199984 0.0433351286 0.0433351286 Dec 10 -4.081721029 0.0434730981 0.0434730981 Jan 11 -1.907365678 0.0337996246 -0.3717958687 Feb 11 -0.244174729 0.0410844295 0.0410844274 Mar 11 -1.827235737 0.0396247820 0.0396247820 Apr 11 -2.894219784 0.0390885392 0.0390885392 May 11 0.517844874 0.0405608776 0.0405608776 Jun 11 -1.738814222 0.0395712723 0.0395712723 Jul 11 -1.116160467 0.0398219731 0.0398219731 Aug 11 0.723734792 0.0405954625 0.0405954625 Sep 11 -2.598837296 0.0391509629 0.0391509629 Oct 11 -3.867382884 0.0385895422 0.0385895422 Nov 11 -8.433725068 0.0366134004 0.0366134004 Dec 11 -8.962366464 0.0363709333 0.0363709333 Jan 12 -6.948638376 0.0282178289 -0.3103961163 Feb 12 -13.214595706 0.0024498756 0.0024498734 Mar 12 -12.143137876 0.0033295834 0.0033295834 Apr 12 -15.554751079 0.0018142297 0.0018142297 May 12 -19.485396902 0.0002422773 0.0002422773 Jun 12 -12.869051246 0.0028523845 0.0028523845 Jul 12 -12.103064636 0.0031528808 0.0031528808 Aug 12 -10.246532147 0.0038822655 0.0038822655 Sep 12 -10.031596957 0.0039652896 0.0039652896 Oct 12 -12.658490957 0.0029307705 0.0029307705 Nov 12 -15.614389168 0.0017677432 0.0017677432 > m$resid Jan Feb Mar Apr May Jun 1 0.00000000 0.00000000 0.27748959 -0.53096422 -1.46145326 -0.44133425 2 -2.64857943 -1.96135193 2.58318294 2.23024789 0.78332261 0.33408361 3 0.32437656 -0.55043074 -1.19546426 -0.43322119 -1.18672576 -1.55274494 4 -2.27660328 1.58836605 0.10764486 0.79066777 0.58814039 -0.55862578 5 -0.39496922 -1.14753872 0.09733060 -0.04647012 0.77910009 0.31248682 6 2.07010584 -0.53566455 1.02728802 1.20495643 -0.17887953 -0.90030251 7 1.47474579 -0.45703857 -2.59936634 1.64342747 0.72916704 -0.50005868 8 0.50297988 -2.09212656 0.88033064 -0.46835768 0.77978408 0.08147391 9 -2.03635360 -1.80998240 -1.05348022 1.27439720 -0.98394672 -0.12167472 10 -0.14938890 0.40035094 -1.36978998 -0.16925431 -0.03038763 0.54726649 11 0.69183191 0.50455023 -0.51572310 -0.35153648 1.07151138 -0.72977121 12 0.64072135 -1.95329979 0.33945566 -1.08481220 -1.24922911 2.10174795 Jul Aug Sep Oct Nov Dec 1 -1.16213358 -0.11926862 0.28150057 0.04623548 -1.10157169 -1.22873689 2 -0.56004033 0.17944630 -0.29655904 -0.35088413 -0.63690265 -0.10753421 3 1.77468041 0.75360492 -0.20737206 -0.87940348 0.44730880 1.72253016 4 -0.40994818 -0.67300466 1.54277003 -1.00950034 0.38055412 -0.02048325 5 -0.86462092 -1.84219155 -0.26938589 -0.08724598 0.21461357 -1.15425164 6 0.13984334 -0.58215686 1.01918267 0.08074238 -0.02787289 -0.04041799 7 0.76181969 0.06507856 -0.29632676 -0.61871938 -0.37488899 -0.06569663 8 -1.12244490 -0.69961309 -0.65032354 -0.64427999 0.47983768 0.60965069 9 0.53971409 0.89677224 0.37611152 0.31569060 1.71245074 0.18859786 10 1.45624254 -1.24705250 0.96773500 0.66204503 0.90718205 0.09280849 11 0.18523122 0.57183977 -1.06839696 -0.41542353 -1.46287519 -0.17956774 12 0.24242607 0.58876604 0.06704551 -0.83574916 -0.93993574 > 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 > postscript(file="/var/fisher/rcomp/tmp/1ehe81352480320.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') > grid() > dev.off() null device 1 > mylagmax <- nx/2 > postscript(file="/var/fisher/rcomp/tmp/2rjy91352480320.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/3ddjw1352480320.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/4xpex1352480320.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/5sja81352480320.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/65mi71352480320.tab") > > try(system("convert tmp/1ehe81352480320.ps tmp/1ehe81352480320.png",intern=TRUE)) character(0) > try(system("convert tmp/2rjy91352480320.ps tmp/2rjy91352480320.png",intern=TRUE)) character(0) > try(system("convert tmp/3ddjw1352480320.ps tmp/3ddjw1352480320.png",intern=TRUE)) character(0) > try(system("convert tmp/4xpex1352480320.ps tmp/4xpex1352480320.png",intern=TRUE)) character(0) > try(system("convert tmp/5sja81352480320.ps tmp/5sja81352480320.png",intern=TRUE)) character(0) > > > proc.time() user system elapsed 3.873 0.586 4.449