R version 2.12.0 (2010-10-15) Copyright (C) 2010 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(26,26,27,28,27,29,27,30,27,30,32,30,32,33,34,32,34,37,37,36,34,38,41,41,44,42,45,45,49,54,52,53,51,55,60,60,63,60,64,65,75,70,72,69,75,74,74,75,79,79,85,78,84,85,85,82,91,90,98,98) > par1 = '4' > #'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.17111104 0.03423552 0.05743739 3.88544394 > m$fitted level slope sea 1 Q1 26.00000 0.0000000 0.00000000 1 Q2 26.00000 0.0000000 0.00000000 1 Q3 26.48851 0.1221537 0.13384739 1 Q4 27.13421 0.2331182 0.22873127 2 Q1 27.44028 0.2475184 -0.61886601 2 Q2 28.16439 0.3342288 0.26905341 2 Q3 27.83137 0.2142972 0.12358492 2 Q4 28.66813 0.3282711 0.35405035 3 Q1 28.57632 0.2431462 -0.86986735 3 Q2 29.13376 0.3007397 0.39486474 3 Q3 30.32825 0.4667020 0.28908881 3 Q4 30.36614 0.3855809 0.30439220 4 Q1 31.54070 0.5409590 -0.71493878 4 Q2 32.33081 0.5880546 0.28909979 4 Q3 33.21627 0.6444627 0.32704545 4 Q4 33.11345 0.5017927 0.03330578 5 Q1 34.00865 0.5773982 -0.58710785 5 Q2 35.38675 0.7300932 0.40305207 5 Q3 36.31672 0.7682215 0.38005822 5 Q4 36.70454 0.6955276 -0.12696640 6 Q1 36.42343 0.5093398 -0.97806121 6 Q2 37.14479 0.5498262 0.53715204 6 Q3 38.72611 0.7467397 0.72237517 6 Q4 40.05184 0.8573235 0.07509661 7 Q1 42.41868 1.1448076 -0.66044233 7 Q2 42.90896 1.0198648 0.06902647 7 Q3 44.09009 1.0506360 0.66856647 7 Q4 45.14425 1.0513086 -0.14953845 8 Q1 47.40675 1.2820523 -0.20643301 8 Q2 50.63909 1.6541485 0.45309222 8 Q3 52.02538 1.6030620 0.37431463 8 Q4 53.53302 1.5848578 -0.39031472 9 Q1 53.81436 1.3364605 -0.87812614 9 Q2 54.87225 1.2833314 0.54252727 9 Q3 57.37194 1.5152476 0.81638266 9 Q4 59.39285 1.6116862 -0.14727976 10 Q1 62.05927 1.8126919 -0.62536395 10 Q2 62.38557 1.5292715 -0.17454535 10 Q3 63.64923 1.4786391 0.74587012 10 Q4 65.16546 1.4858070 -0.22145531 11 Q1 69.79279 2.0845033 0.54390363 11 Q2 71.35444 1.9848230 -0.57724775 11 Q3 72.62633 1.8489319 0.43327510 11 Q4 72.72634 1.5155080 -1.12452275 12 Q1 74.22018 1.5113777 0.81198919 12 Q2 75.24920 1.4194294 -0.53260012 12 Q3 75.43879 1.1850254 0.38801189 12 Q4 76.39561 1.1415239 -1.05640100 13 Q1 77.71588 1.1755867 1.01888124 13 Q2 79.05650 1.2070435 -0.30157773 13 Q3 81.82508 1.5046550 0.85634652 13 Q4 81.85356 1.2232854 -1.66062818 14 Q1 83.03007 1.2143727 1.03932370 14 Q2 84.68724 1.2987690 -0.34463420 14 Q3 85.25374 1.1592097 0.83325035 14 Q4 85.40245 0.9666126 -1.90192011 15 Q1 87.64123 1.2090514 1.47118761 15 Q2 89.37258 1.3085959 -0.14783352 15 Q3 92.99810 1.7501524 1.56330704 15 Q4 96.75946 2.1334641 -1.74511373 > m$resid Qtr1 Qtr2 Qtr3 Qtr4 1 0.000000000 0.000000000 0.311760983 0.457903129 2 0.107913243 0.406258323 -0.655240986 0.654335034 3 -0.473927412 0.319730897 0.931954385 -0.449556794 4 0.816191289 0.257863814 0.309688872 -0.776046862 5 0.403193878 0.826299175 0.207164677 -0.393774403 6 -1.004995374 0.218276632 1.065869438 0.598406806 7 1.556671850 -0.673474327 0.166393242 0.003638192 8 1.249267685 2.007082457 -0.276200561 -0.098442644 9 -1.344030205 -0.286763606 1.253813104 0.521405425 10 1.087138170 -1.530436873 -0.273719439 0.038748613 11 3.237234263 -0.538416635 -0.734582308 -1.802289753 12 -0.022329617 -0.496746875 -1.267039789 -0.235129753 13 0.184136082 0.169965469 1.608632654 -1.520775034 14 -0.048177249 0.456044565 -0.754314765 -1.040945193 15 1.310418967 0.537930546 2.386552858 2.071685743 > 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/www/rcomp/tmp/1xb0h1293453803.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/www/rcomp/tmp/2xb0h1293453803.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/rcomp/tmp/3xb0h1293453803.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/rcomp/tmp/4qkzk1293453803.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/rcomp/tmp/50tym1293453803.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/rcomp/createtable file can be downloaded at http://www.wessa.net/cretab > load(file="/var/www/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/rcomp/tmp/626lk1293453803.tab") > > try(system("convert tmp/1xb0h1293453803.ps tmp/1xb0h1293453803.png",intern=TRUE)) character(0) > try(system("convert tmp/2xb0h1293453803.ps tmp/2xb0h1293453803.png",intern=TRUE)) character(0) > try(system("convert tmp/3xb0h1293453803.ps tmp/3xb0h1293453803.png",intern=TRUE)) character(0) > try(system("convert tmp/4qkzk1293453803.ps tmp/4qkzk1293453803.png",intern=TRUE)) character(0) > try(system("convert tmp/50tym1293453803.ps tmp/50tym1293453803.png",intern=TRUE)) character(0) > > > proc.time() user system elapsed 1.430 0.960 2.365