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(8.2,8.0,7.5,6.8,6.5,6.6,7.6,8.0,8.1,7.7,7.5,7.6,7.8,7.8,7.8,7.5,7.5,7.1,7.5,7.5,7.6,7.7,7.7,7.9,8.1,8.2,8.2,8.2,7.9,7.3,6.9,6.6,6.7,6.9,7.0,7.1,7.2,7.1,6.9,7.0,6.8,6.4,6.7,6.6,6.4,6.3,6.2,6.5,6.8,6.8,6.4,6.1,5.8,6.1,7.2,7.3,6.9,6.1,5.8,6.2,7.1,7.7,7.9,7.7,7.4,7.5,8.0,8.1) > 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 0.0000000000 0.1112030956 0.0004776921 0.0000000000 > m$fitted level slope sea Jan 1 8.200000 0.000000000 0.000000000 Feb 1 8.001276 -0.198829249 -0.001276224 Mar 1 7.504242 -0.491527403 -0.004242296 Apr 1 6.802201 -0.697066633 -0.002200817 May 1 6.493088 -0.318123204 0.006911702 Jun 1 6.594987 0.092163649 0.005012562 Jul 1 7.587478 0.971613736 0.012521808 Aug 1 8.012429 0.437626846 -0.012428654 Sep 1 8.103410 0.099019027 -0.003409573 Oct 1 7.706589 -0.385322600 -0.006589331 Nov 1 7.495333 -0.215292385 0.004666755 Dec 1 7.595783 0.093128095 0.004217155 Jan 2 7.799282 0.200924129 0.000717856 Feb 2 7.804441 0.009647057 -0.004440614 Mar 2 7.794447 -0.009251420 0.005553275 Apr 2 7.514353 -0.269238885 -0.014353467 May 2 7.480108 -0.043638987 0.019891909 Jun 2 7.132155 -0.335818746 -0.032154607 Jul 2 7.458615 0.300044903 0.041385210 Aug 2 7.522530 0.073334508 -0.022530006 Sep 2 7.589313 0.067043899 0.010687450 Oct 2 7.704672 0.113432483 -0.004672325 Nov 2 7.703948 0.003829245 -0.003948271 Dec 2 7.895028 0.183609645 0.004972011 Jan 3 8.095507 0.199803676 0.004492919 Feb 3 8.212786 0.120544419 -0.012785923 Mar 3 8.183383 -0.021958481 0.016617300 Apr 3 8.228612 0.041871528 -0.028612272 May 3 7.866070 -0.342220158 0.033929573 Jun 3 7.367092 -0.491123522 -0.067092034 Jul 3 6.848649 -0.517074370 0.051351277 Aug 3 6.611461 -0.251214990 -0.011461029 Sep 3 6.685091 0.057349267 0.014908991 Oct 3 6.893037 0.200398378 0.006963181 Nov 3 7.014695 0.125604268 -0.014695368 Dec 3 7.098625 0.086018536 0.001375331 Jan 4 7.193935 0.094842847 0.006065413 Feb 4 7.109118 -0.075855267 -0.009117816 Mar 4 6.901301 -0.200379065 -0.001301450 Apr 4 7.001396 0.083320693 -0.001396175 May 4 6.772568 -0.211245395 0.027432100 Jun 4 6.461703 -0.305269897 -0.061702742 Jul 4 6.635086 0.146505530 0.064913691 Aug 4 6.630990 0.004362443 -0.030990252 Sep 4 6.403755 -0.214226655 -0.003755196 Oct 4 6.284853 -0.124255940 0.015146894 Nov 4 6.210102 -0.077530824 -0.010102382 Dec 4 6.491914 0.261618453 0.008085578 Jan 5 6.787571 0.293740538 0.012428718 Feb 5 6.804891 0.032824395 -0.004890854 Mar 5 6.442744 -0.338339181 -0.042743902 Apr 5 6.084043 -0.357490042 0.015957210 May 5 5.750804 -0.334695040 0.049195833 Jun 5 6.165114 0.369442766 -0.065113872 Jul 5 7.114006 0.914196609 0.085994304 Aug 5 7.346374 0.273200752 -0.046374476 Sep 5 6.933350 -0.371925562 -0.033349756 Oct 5 6.090461 -0.814684917 0.009539461 Nov 5 5.804663 -0.317468538 -0.004662585 Dec 5 6.175989 0.330042527 0.024010761 Jan 6 7.065278 0.855741281 0.034721736 Feb 6 7.696858 0.645020682 0.003142079 Mar 6 7.955820 0.283185326 -0.055820385 Apr 6 7.679627 -0.241547995 0.020372556 May 6 7.378561 -0.297347152 0.021438819 Jun 6 7.598971 0.188119407 -0.098970892 Jul 6 7.893334 0.287741156 0.106666112 Aug 6 8.124130 0.234345958 -0.024130270 > m$resid Jan Feb Mar Apr May Jun 1 0.00000000 -0.59807312 -0.88582139 -0.61616591 1.13637372 1.23035154 2 0.32332452 -0.57499988 -0.05706132 -0.77916968 0.67655283 -0.87617577 3 0.04857396 -0.23803156 -0.42922444 0.19130055 -1.15186764 -0.44652459 4 0.02647006 -0.51224210 -0.37443846 0.85041308 -0.88335908 -0.28195764 5 0.09635980 -0.78262256 -1.11493471 -0.05741704 0.06835556 2.11156205 6 1.57700003 -0.63191863 -1.08625998 -1.57344634 -0.16731839 1.45582259 Jul Aug Sep Oct Nov Dec 1 2.63725885 -1.60129798 -1.01540324 -1.45242381 0.50987964 0.92487868 2 1.90680213 -0.67984983 -0.01886402 0.13910818 -0.32867371 0.53911845 3 -0.07782038 0.79724819 0.92530985 0.42896981 -0.22428963 -0.11870825 4 1.35476581 -0.42625289 -0.65549604 0.26980049 0.14011758 1.01702942 5 1.63358398 -1.92219253 -1.93457840 -1.32772870 1.49103566 1.94174225 6 0.29874105 -0.16011938 > 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/1sx1k1259784785.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/27bhg1259784785.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/3ks2b1259784785.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/40fxz1259784785.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/58m441259784785.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/6cq221259784785.tab") > system("convert tmp/1sx1k1259784785.ps tmp/1sx1k1259784785.png") > system("convert tmp/27bhg1259784785.ps tmp/27bhg1259784785.png") > system("convert tmp/3ks2b1259784785.ps tmp/3ks2b1259784785.png") > system("convert tmp/40fxz1259784785.ps tmp/40fxz1259784785.png") > system("convert tmp/58m441259784785.ps tmp/58m441259784785.png") > > > proc.time() user system elapsed 1.572 0.808 1.798