R version 2.8.0 (2008-10-20) Copyright (C) 2008 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. Natural language support but running in an English locale 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(42.33600 + ,42.14710 + ,40.25640 + ,39.18980 + ,39.13170 + ,38.15070 + ,38.27070 + ,39.13350 + ,40.12190 + ,41.28450 + ,42.57490 + ,43.90190 + ,43.18350 + ,43.61880 + ,44.76240 + ,45.19720 + ,44.38810 + ,43.55520 + ,43.56780 + ,44.21350 + ,45.14510 + ,45.80790 + ,42.32820 + ,37.89990 + ,34.79640 + ,35.21440 + ,36.37270 + ,36.25020 + ,36.82610 + ,36.77230 + ,36.90420 + ,37.04940 + ,36.82590 + ,36.13570 + ,36.03000 + ,35.79270 + ,35.91740 + ,35.40080 + ,35.17230 + ,34.92110 + ,35.02920 + ,34.77390 + ,34.89990 + ,34.90540 + ,34.56800 + ,34.40600 + ,34.45780 + ,34.73160 + ,34.26020 + ,33.88490 + ,34.05490 + ,34.27550 + ,34.13930 + ,34.15870 + ,34.53860 + ,33.79870 + ,33.49730 + ,33.68020 + ,34.32840 + ,34.15380 + ,33.91840 + ,34.32620 + ,34.77500 + ,35.01190 + ,34.55130 + ,34.69510 + ,35.47300 + ,35.97940 + ,36.47890 + ,36.39100 + ,36.67040 + ,37.41620 + ,37.11850 + ,36.30010 + ,35.70020 + ,35.58590 + ,35.67770 + ,35.24080 + ,34.80160 + ,34.43890 + ,34.98810 + ,36.06800 + ,36.35660 + ,36.12540 + ,34.87100 + ,35.21990 + ,34.33900 + ,33.82340 + ,34.51990 + ,35.53000 + ,35.79660 + ,33.84840 + ,33.98710 + ,34.11610 + ,33.82350 + ,32.45400 + ,31.87740 + ,31.11500 + ,31.04360 + ,30.88680 + ,31.30010 + ,30.05070 + ,28.67990 + ,27.64380 + ,27.23940 + ,26.85490 + ,27.01580 + ,26.91880 + ,26.49660 + ,26.78500 + ,26.83980 + ,26.44780 + ,25.17280 + ,24.87840 + ,25.40150 + ,25.77160 + ,26.11810 + ,26.3969 + ,26.65710 + ,25.18390 + ,23.83940 + ,23.86190 + ,24.25810 + ,25.10980 + ,26.16170 + ,26.80870 + ,25.65770 + ,27.09820 + ,27.46650 + ,28.28900 + ,28.69330 + ,27.24010 + ,27.27980 + ,27.64040 + ,26.83100 + ,26.24670 + ,25.22120 + ,25.36530 + ,26.25920 + ,27.22790 + ,26.33150 + ,25.89810 + ,26.68980) > par1 = '12' > par1 <- 5 > nx <- length(x) > x <- ts(x,frequency=par1) > m <- StructTS(x,type='BSM') > m$coef level slope seas epsilon 7.479284e-01 -1.635461e-17 0.000000e+00 0.000000e+00 > m$fitted Time Series: Start = c(1, 1) End = c(29, 3) Frequency = 5 level slope sea 1.0 42.33600 0.0000000000 0.0000000000 1.2 42.17543 -0.0283349983 -0.0283349983 1.4 40.33016 -0.0737585322 -0.0737585322 1.6 39.28720 -0.0973976134 -0.0973976134 1.8 39.22818 -0.0964837154 -0.0964837154 2.0 38.13546 -0.0038101693 0.0152406773 2.2 38.26549 0.0052126314 0.0052126314 2.4 39.11935 0.0141458330 0.0141458330 2.6 40.09771 0.0241896901 0.0241896901 2.8 41.24869 0.0358061216 0.0358061216 3.0 42.51691 -0.0144964909 0.0579859637 3.2 43.85984 0.0420626660 0.0420626660 3.4 43.14647 0.0370264895 0.0370264895 3.6 43.57915 0.0396467099 0.0396467099 3.8 44.71554 0.0468620908 0.0468620908 4.0 45.32574 0.0321343191 -0.1285372762 4.2 44.38529 0.0028102439 0.0028102439 4.4 43.55645 -0.0012466019 -0.0012466019 4.6 43.56898 -0.0011797101 -0.0011797101 4.8 44.21157 0.0019302884 0.0019302884 5.0 45.08573 -0.0148433034 0.0593732136 5.2 45.80539 0.0025073077 0.0025073077 5.4 42.33903 -0.0108344827 -0.0108344827 5.6 37.92760 -0.0276950379 -0.0276950379 5.8 34.83579 -0.0393901137 -0.0393901137 6.0 35.04190 -0.0431240140 0.1724960558 6.2 36.38883 -0.0161326983 -0.0161326983 6.4 36.26667 -0.0164693037 -0.0164693037 6.6 36.84070 -0.0146006308 -0.0146006308 6.8 36.78702 -0.0147238993 -0.0147238993 7.0 36.84181 -0.0155982035 0.0623928139 7.2 37.06113 -0.0117259459 -0.0117259459 7.4 36.83820 -0.0122967654 -0.0122967654 7.6 36.14982 -0.0141190859 -0.0141190859 7.8 36.04436 -0.0143646112 -0.0143646112 8.0 35.74737 -0.0113336760 0.0453347041 8.2 35.92601 -0.0086131764 -0.0086131764 8.4 35.41061 -0.0098056337 -0.0098056337 8.6 35.18262 -0.0103177985 -0.0103177985 8.8 34.93198 -0.0108806074 -0.0108806074 9.0 34.98335 -0.0114623873 0.0458495493 9.2 34.78769 -0.0137939583 -0.0137939583 9.4 34.91340 -0.0135033263 -0.0135033263 9.6 34.91886 -0.0134639003 -0.0134639003 9.8 34.58213 -0.0141345755 -0.0141345755 10.0 34.35647 -0.0123827655 0.0495310619 10.2 34.46877 -0.0109685981 -0.0109685981 10.4 34.74204 -0.0104373134 -0.0104373134 10.6 34.27150 -0.0112957169 -0.0112957169 10.8 33.89687 -0.0119723048 -0.0119723048 11.0 34.00348 -0.0128539711 0.0514158842 11.2 34.28533 -0.0098262711 -0.0098262711 11.4 34.14934 -0.0100401015 -0.0100401015 11.6 34.16869 -0.0099903716 -0.0099903716 11.8 34.54793 -0.0093328836 -0.0093328836 12.0 33.78179 -0.0042279146 0.0169116584 12.2 33.50410 -0.0067956589 -0.0067956589 12.4 33.68670 -0.0065020124 -0.0065020124 12.6 34.33389 -0.0054901082 -0.0054901082 12.8 34.15955 -0.0057510802 -0.0057510802 13.0 33.90162 -0.0041944277 0.0167777108 13.2 34.32668 -0.0004832857 -0.0004832857 13.4 34.77484 0.0001576320 0.0001576320 13.6 35.01141 0.0004948718 0.0004948718 13.8 34.55146 -0.0001610242 -0.0001610242 14.0 34.69127 -0.0009574409 0.0038297635 14.2 35.46773 0.0052701987 0.0052701987 14.4 35.97347 0.0059330688 0.0059330688 14.6 36.47231 0.0065850726 0.0065850726 14.8 36.38454 0.0064604221 0.0064604221 15.0 36.68993 0.0048829457 -0.0195317829 15.2 37.40601 0.0101903703 0.0101903703 15.4 37.10869 0.0098107275 0.0098107275 15.6 36.29131 0.0087907635 0.0087907635 15.8 35.69216 0.0080420664 0.0080420664 16.0 35.61965 0.0084383594 -0.0337534378 16.2 35.66898 0.0087239306 0.0087239306 16.4 35.23259 0.0082093533 0.0082093533 16.6 34.79391 0.0076933102 0.0076933102 16.8 34.43163 0.0072665898 0.0072665898 17.0 35.00670 0.0046500000 -0.0185999999 17.2 36.05649 0.0115108695 0.0115108695 17.4 36.34479 0.0118117264 0.0118117264 17.6 36.11385 0.0115481562 0.0115481562 17.8 34.86082 0.0101765980 0.0101765980 18.0 35.25397 0.0085169329 -0.0340677315 18.2 34.33622 0.0027815385 0.0027815385 18.4 33.82115 0.0022504098 0.0022504098 18.6 34.51694 0.0029610031 0.0029610031 18.8 35.52601 0.0039907975 0.0039907975 19.0 35.80801 0.0028537223 -0.0114148893 19.2 33.85699 -0.0085947573 -0.0085947573 19.4 33.99555 -0.0084518913 -0.0084518913 19.6 34.12442 -0.0083187015 -0.0083187015 19.8 33.83209 -0.0085939012 -0.0085939012 20.0 32.44104 -0.0032407054 0.0129628217 20.2 31.88372 -0.0063217511 -0.0063217511 20.4 31.12202 -0.0070179558 -0.0070179558 20.6 31.05068 -0.0070771849 -0.0070771849 20.8 30.89401 -0.0072147978 -0.0072147978 21.0 31.26567 -0.0086076993 0.0344307970 21.2 30.06561 -0.0149116666 -0.0149116666 21.4 28.69600 -0.0161000000 -0.0161000000 21.6 27.66079 -0.0169931698 -0.0169931698 21.8 27.25673 -0.0173321084 -0.0173321084 22.0 26.79184 -0.0157658326 0.0630633303 22.2 27.03028 -0.0144830125 -0.0144830125 22.4 26.93335 -0.0145520067 -0.0145520067 22.6 26.51149 -0.0148925647 -0.0148925647 22.8 26.79964 -0.0146393990 -0.0146393990 23.0 26.78129 -0.0146270181 0.0585080724 23.2 26.46389 -0.0160873600 -0.0160873600 23.4 25.18989 -0.0170936850 -0.0170936850 23.6 24.89572 -0.0173151757 -0.0173151757 23.8 25.41838 -0.0168838787 -0.0168838787 24.0 25.70025 -0.0178375886 0.0713503545 24.2 26.13385 -0.0157524138 -0.0157524138 24.4 26.41243 -0.0155268759 -0.0155268759 24.6 26.67242 -0.0153159143 -0.0153159143 24.8 25.20033 -0.0164305046 -0.0164305046 25.0 23.79072 -0.0121700151 0.0486800603 25.2 23.87365 -0.0117486029 -0.0117486029 25.4 24.26955 -0.0114488611 -0.0114488611 25.6 25.12062 -0.0108151248 -0.0108151248 25.8 26.17174 -0.0100354365 -0.0100354365 26.0 26.76152 -0.0117957215 0.0471828861 26.2 25.67408 -0.0163761837 -0.0163761837 26.4 27.11355 -0.0153473164 -0.0153473164 26.6 27.48158 -0.0150765702 -0.0150765702 26.8 28.30349 -0.0144858956 -0.0144858956 27.0 28.63149 -0.0154520223 0.0618080892 27.2 27.26111 -0.0210050340 -0.0210050340 27.4 27.30076 -0.0209637661 -0.0209637661 27.6 27.66110 -0.0207045516 -0.0207045516 27.8 26.85224 -0.0212399864 -0.0212399864 28.0 26.16893 -0.0194421088 0.0777684351 28.2 25.24422 -0.0230179016 -0.0230179016 28.4 25.38821 -0.0229083879 -0.0229083879 28.6 26.28151 -0.0223079895 -0.0223079895 28.8 27.24956 -0.0216594240 -0.0216594240 29.0 26.25505 -0.0191126943 0.0764507771 29.2 25.91842 -0.0203230379 -0.0203230379 29.4 26.70961 -0.0198094244 -0.0198094244 > m$resid Time Series: Start = c(1, 1) End = c(29, 3) Frequency = 5 [1] 0.000000000 -0.069072006 -2.127026312 -1.134271930 0.044908297 [6] -1.349354427 0.130181099 0.986448814 1.120706819 1.309608975 [11] 1.536972214 1.425344135 -0.876405404 0.459005717 1.272321218 [16] 0.684598777 -1.051873117 -0.963982254 0.015972086 0.746185882 [21] 1.046626567 0.806945502 -4.018750423 -5.098151876 -3.549780977 [26] 0.292383388 1.542056120 -0.122797598 0.683874561 -0.045254851 [31] 0.082368162 0.262335511 -0.244543797 -0.782804267 -0.105752836 [36] -0.333745843 0.213175199 -0.586694620 -0.252579704 -0.278206170 [41] 0.073313186 -0.207433780 0.161475440 0.021950713 -0.374178901 [46] -0.248611292 0.140814289 0.328970221 -0.532513984 -0.420506286 [51] 0.139142646 0.333589569 -0.146002085 0.034012784 0.450449397 [56] -0.886827407 -0.310140884 0.219174984 0.756445751 -0.195390589 [61] -0.295170688 0.487595147 0.519134948 0.273549820 -0.532784006 [66] 0.163678815 0.884260311 0.579072314 0.570333663 -0.109180865 [71] 0.349283414 0.809870479 -0.355793641 -0.957069017 -0.703395275 [76] -0.094047877 0.046603488 -0.514976731 -0.517040365 -0.428038480 [81] 0.662569822 1.192388975 0.320223781 -0.280841690 -1.463020878 [86] 0.446646691 -1.057589519 -0.599096688 0.802348883 1.163957867 [91] 0.324087151 -2.232432634 0.170234101 0.158858405 -0.328554917 [96] -1.610872016 -0.633460441 -0.873849604 -0.074410615 -0.173044700 [101] 0.441295386 -1.362917799 -1.567124573 -1.178908055 -0.447761968 [106] -0.521126421 0.290944503 -0.095374378 -0.471165862 0.350550364 [111] -0.004316176 -0.346687060 -1.455096978 -0.320520819 0.624631897 [116] 0.347642342 0.517127090 0.340460119 0.318700605 -1.685104778 [121] -1.620754976 0.108978106 0.471537064 0.997691343 1.228365133 [126] 0.697626631 -1.233071898 1.683988921 0.443454289 0.968147042 [131] 0.398250905 -1.553747970 0.070169282 0.441051752 -0.911657815 [136] -0.769695330 -1.038420765 0.193174867 1.059757062 1.145526104 [141] -1.130780197 -0.364317169 0.938644095 > 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/freestat/rcomp/tmp/1m5fk1292011077.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/www/html/freestat/rcomp/tmp/2m5fk1292011077.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/www/html/freestat/rcomp/tmp/3eee51292011077.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/www/html/freestat/rcomp/tmp/475e81292011077.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/www/html/freestat/rcomp/tmp/575e81292011077.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/www/html/freestat/rcomp/createtable file can be downloaded at http://www.wessa.net/cretab > load(file="/var/www/html/freestat/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/freestat/rcomp/tmp/6lfth1292011077.tab") > > try(system("convert tmp/1m5fk1292011077.ps tmp/1m5fk1292011077.png",intern=TRUE)) character(0) > try(system("convert tmp/2m5fk1292011077.ps tmp/2m5fk1292011077.png",intern=TRUE)) character(0) > try(system("convert tmp/3eee51292011077.ps tmp/3eee51292011077.png",intern=TRUE)) character(0) > try(system("convert tmp/475e81292011077.ps tmp/475e81292011077.png",intern=TRUE)) character(0) > try(system("convert tmp/575e81292011077.ps tmp/575e81292011077.png",intern=TRUE)) character(0) > > > proc.time() user system elapsed 2.291 1.219 2.471