R version 2.13.0 (2011-04-13) Copyright (C) 2011 The R Foundation for Statistical Computing ISBN 3-900051-07-0 Platform: i486-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(101.5,100.7,110.6,96.8,100,104.8,86.8,92,100.2,106.6,102.1,93.7,97.6,96.9,105.6,102.8,101.7,104.2,92.7,91.9,106.5,112.3,102.8,96.5,101,98.9,105.1,103,99,104.3,94.6,90.4,108.9,111.4,100.8,102.5,98.2,98.7,113.3,104.6,99.3,111.8,97.3,97.7,115.6,111.9,107,107.1,100.6,99.2,108.4,103,99.8,115,90.8,95.9,114.4,108.2,112.6,109.1,105,105,118.5,103.7,112.5,116.6,96.6,101.9,116.5,119.3,115.4,108.5,111.5,108.8,121.8,109.6,112.2,119.6,104.1,105.3,115,124.1,116.8,107.5,115.6,116.2,116.3,119,111.9,118.6,106.9,103.2,118.6,118.7,102.8,100.6,94.9,94.5,102.9,95.3,92.5,102.7,91.5,89.5,104.2,105.2,99,95.5,90.5,96.1,113,101.9,101.4,113.6,96.6,97.8,114.9,112.5,108.4,107,103.5,107.5,122.3) > 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 3.280223 0.000000 5.688229 0.000000 > m$fitted level slope sea Jan 1 101.50000 0.000000000 0.0000000 Feb 1 101.11091 -0.007984070 -0.4109147 Mar 1 105.80165 0.294948273 4.7983507 Apr 1 102.81971 0.103397965 -6.0197054 May 1 100.99431 0.025465281 -0.9943120 Jun 1 102.02250 0.051445738 2.7775038 Jul 1 96.22192 -0.055641867 -9.4219197 Aug 1 92.90047 -0.106360429 -0.9004686 Sep 1 94.89998 -0.074587669 5.3000184 Oct 1 100.16690 0.007415593 6.4331034 Nov 1 102.42680 0.042549972 -0.3267980 Dec 1 99.55514 -0.003024250 -5.8551425 Jan 2 98.36016 0.019220738 -0.7601573 Feb 2 98.41033 0.019014453 -1.5103260 Mar 2 98.42283 0.018912009 7.1771730 Apr 2 102.14954 0.118315919 0.6504632 May 2 102.73714 0.131279291 -1.0371439 Jun 2 100.69309 0.080500073 3.5069066 Jul 2 100.31235 0.072033522 -7.6123519 Aug 2 98.36532 0.042379247 -6.4653215 Sep 2 100.32671 0.066146385 6.1732938 Oct 2 103.11613 0.094767828 9.1838696 Nov 2 103.00602 0.093143481 -0.2060193 Dec 2 102.52612 0.090778550 -6.0261184 Jan 3 102.36673 0.090634972 -1.3667261 Feb 3 102.07159 0.089464583 -3.1715930 Mar 3 101.26494 0.080708600 3.8350602 Apr 3 101.33175 0.080488751 1.6682494 May 3 100.19822 0.057878707 -1.1982159 Jun 3 99.93623 0.052017922 4.3637675 Jul 3 100.60527 0.062024585 -6.0052741 Aug 3 100.08876 0.054188319 -9.6887596 Sep 3 101.60980 0.070211478 7.2902003 Oct 3 102.12395 0.073963846 9.2760509 Nov 3 101.67326 0.070745008 -0.8732640 Dec 3 104.10092 0.080906027 -1.6009205 Jan 4 102.75932 0.075508219 -4.5593165 Feb 4 101.85639 0.070288695 -3.1563882 Mar 4 104.48960 0.091911079 8.8104041 Apr 4 104.21308 0.087615537 0.3869191 May 4 102.69533 0.065529797 -3.3953346 Jun 4 104.35276 0.088253692 7.4472436 Jul 4 104.39620 0.087651998 -7.0962044 Aug 4 105.95971 0.104972892 -8.2597102 Sep 4 107.36282 0.117558384 8.2371770 Oct 4 105.96852 0.105951071 5.9314831 Nov 4 106.79939 0.110293843 0.2006118 Dec 4 107.42973 0.112874399 -0.3297257 Jan 5 106.77106 0.109091810 -6.1710611 Feb 5 105.47697 0.100803133 -6.2769656 Mar 5 102.74733 0.079112388 5.6526698 Apr 5 101.93346 0.070587516 1.0665391 May 5 102.73852 0.078618807 -2.9385195 Jun 5 105.00929 0.103759055 9.9907118 Jul 5 103.25833 0.083149563 -12.4583284 Aug 5 103.41665 0.083906686 -7.5166539 Sep 5 104.30135 0.090844421 10.0986547 Oct 5 103.94245 0.087597355 4.2575464 Nov 5 107.06698 0.105942184 5.5330166 Dec 5 108.24070 0.111677847 0.8592954 Jan 6 108.97047 0.114991172 -3.9704735 Feb 6 109.34121 0.116523828 -4.3412123 Mar 6 110.76497 0.125754338 7.7350312 Apr 6 108.33875 0.104768687 -4.6387453 May 6 110.88675 0.127072277 1.6132524 Jun 6 109.47275 0.112374472 7.1272480 Jul 6 109.15246 0.108317188 -12.5524578 Aug 6 109.51781 0.110562228 -7.6178067 Sep 6 108.74733 0.103689013 7.7526740 Oct 6 111.89465 0.124428700 7.4053547 Nov 6 112.21638 0.125612620 3.1836218 Dec 6 110.76243 0.116868236 -2.2624317 Jan 7 112.40751 0.125286904 -0.9075138 Feb 7 113.22419 0.129362563 -4.4241891 Mar 7 113.36693 0.129450291 8.4330731 Apr 7 114.16103 0.134298244 -4.5610265 May 7 112.60439 0.120964940 -0.4043861 Jun 7 112.18111 0.116516142 7.4188912 Jul 7 113.95837 0.129965622 -9.8583719 Aug 7 114.13820 0.130349310 -8.8381960 Sep 7 112.26942 0.116190852 2.7305804 Oct 7 113.53872 0.123590138 10.5612838 Nov 7 113.75130 0.124111423 3.0486980 Dec 7 112.75781 0.117934959 -5.2578129 Jan 8 114.18757 0.125128740 1.4124327 Feb 8 117.03224 0.140665206 -0.8322418 Mar 8 114.14977 0.122141601 2.1502339 Apr 8 116.75092 0.138493295 2.2490814 May 8 115.73265 0.130416569 -3.8326480 Jun 8 114.11971 0.117898794 4.4802886 Jul 8 114.66490 0.120950714 -7.7649026 Aug 8 113.50102 0.112103796 -10.3010184 Sep 8 114.45783 0.117578641 4.1421731 Oct 8 112.29529 0.103822839 6.4047066 Nov 8 107.03055 0.073504460 -4.2305475 Dec 8 105.99125 0.067485405 -5.3912546 Jan 9 101.45204 0.042794945 -6.5520375 Feb 9 97.64110 0.021634174 -3.1411037 Mar 9 98.43421 0.026068716 4.4657899 Apr 9 96.13961 0.012035335 -0.8396136 May 9 95.30290 0.006689483 -2.8029015 Jun 9 96.21236 0.012495649 6.4876371 Jul 9 97.21538 0.018845917 -5.7153817 Aug 9 98.09623 0.024228442 -8.5962261 Sep 9 97.75965 0.022072552 6.4403457 Oct 9 96.42131 0.014357151 8.7786884 Nov 9 97.77843 0.021613355 1.2215694 Dec 9 97.76040 0.021406000 -2.2604017 Jan 10 96.54532 0.014999104 -6.0453154 Feb 10 97.20972 0.018410391 -1.1097222 Mar 10 101.12700 0.039505356 11.8729998 Apr 10 102.57593 0.047398163 -0.6759342 May 10 103.84720 0.054450543 -2.4471991 Jun 10 105.66875 0.064787627 7.9312515 Jul 10 104.90497 0.059951371 -8.3049712 Aug 10 105.11833 0.060829828 -7.3183324 Sep 10 106.28254 0.066948129 8.6174565 Oct 10 105.86285 0.064350907 6.6371487 Nov 10 106.22867 0.065903440 2.1713277 Dec 10 107.48287 0.071872004 -0.4828657 Jan 11 109.26208 0.080369995 -5.7620850 Feb 11 110.58450 0.086595784 -3.0844984 Mar 11 111.36923 0.090161195 10.9307696 > m$resid Jan Feb Mar Apr May 1 0.000000000 -0.190866114 1.777933411 -1.541666000 -1.022506759 2 -0.689941536 0.017671001 -0.003382606 1.878231973 0.245195337 3 -0.138693073 -0.212086602 -0.480451270 -0.007332884 -0.643589053 4 -0.782096057 -0.534481228 1.384923146 -0.197520280 -0.860968621 5 -0.423037385 -0.765970306 -1.536087312 -0.482569185 0.396789375 6 0.338561020 0.139677020 0.711504428 -1.385584613 1.326089821 7 0.836842675 0.377879384 0.007294895 0.361962887 -0.920615418 8 0.718381811 1.487443980 -1.651323797 1.352840937 -0.631134446 9 -2.523270191 -2.109152960 0.421876498 -1.268292035 -0.463787780 10 -0.677470387 0.355626074 2.133945771 0.771119958 0.669525001 11 0.935748699 0.680506148 0.382373210 Jun Jul Aug Sep Oct 1 0.549340852 -3.225965961 -1.800688728 1.159833499 2.938565429 2 -1.172030880 -0.252391666 -1.111269002 1.057912941 1.500962875 3 -0.172067500 0.336166638 -0.317472546 0.807205414 0.244406861 4 0.859531698 -0.024387073 0.807957336 0.712761047 -0.830937616 5 1.188247787 -1.010142306 0.041109945 0.439003281 -0.246832974 6 -0.837904170 -0.235916192 0.140528747 -0.482619248 1.668948972 7 -0.296595234 0.906606389 0.027266405 -1.094790438 0.632000765 8 -0.951706314 0.233507565 -0.702962718 0.462610278 -1.249509107 9 0.493469158 0.541794268 0.471859896 -0.197638101 -0.745551806 10 0.966893943 -0.453553626 0.084019437 0.604587808 -0.266741149 11 Nov Dec 1 1.238332916 -1.601728081 2 -0.112826285 -0.315953860 3 -0.288786893 1.297452714 4 0.398474159 0.285714868 5 1.667198858 0.585860173 6 0.108220096 -0.866007893 7 0.048790116 -0.612527791 8 -2.942670424 -0.609852401 9 0.736018200 -0.021727369 10 0.165269878 0.651408790 11 > 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/wessaorg/rcomp/tmp/1jlb11322764912.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/wessaorg/rcomp/tmp/27rnm1322764912.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/wessaorg/rcomp/tmp/3i3801322764912.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/wessaorg/rcomp/tmp/4a3zk1322764912.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/wessaorg/rcomp/tmp/5un6w1322764912.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/wessaorg/rcomp/createtable file can be downloaded at http://www.wessa.net/cretab > load(file="/var/wessaorg/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/wessaorg/rcomp/tmp/6geza1322764912.tab") > > try(system("convert tmp/1jlb11322764912.ps tmp/1jlb11322764912.png",intern=TRUE)) character(0) > try(system("convert tmp/27rnm1322764912.ps tmp/27rnm1322764912.png",intern=TRUE)) character(0) > try(system("convert tmp/3i3801322764912.ps tmp/3i3801322764912.png",intern=TRUE)) character(0) > try(system("convert tmp/4a3zk1322764912.ps tmp/4a3zk1322764912.png",intern=TRUE)) character(0) > try(system("convert tmp/5un6w1322764912.ps tmp/5un6w1322764912.png",intern=TRUE)) character(0) > > > proc.time() user system elapsed 2.277 0.247 2.530