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(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.17111066 0.03423555 0.05743738 3.88544745 > 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.13384738 1 Q4 27.13421 0.2331183 0.22873126 2 Q1 27.44028 0.2475184 -0.61886607 2 Q2 28.16439 0.3342289 0.26905342 2 Q3 27.83137 0.2142972 0.12358502 2 Q4 28.66813 0.3282711 0.35405027 3 Q1 28.57632 0.2431462 -0.86986728 3 Q2 29.13376 0.3007397 0.39486465 3 Q3 30.32825 0.4667020 0.28908878 3 Q4 30.36614 0.3855809 0.30439217 4 Q1 31.54070 0.5409590 -0.71493874 4 Q2 32.33081 0.5880546 0.28909975 4 Q3 33.21627 0.6444627 0.32704536 4 Q4 33.11345 0.5017928 0.03330592 5 Q1 34.00865 0.5773982 -0.58710790 5 Q2 35.38675 0.7300932 0.40305195 5 Q3 36.31672 0.7682215 0.38005811 5 Q4 36.70454 0.6955277 -0.12696617 6 Q1 36.42343 0.5093398 -0.97806108 6 Q2 37.14479 0.5498263 0.53715186 6 Q3 38.72611 0.7467397 0.72237488 6 Q4 40.05184 0.8573235 0.07509671 7 Q1 42.41868 1.1448076 -0.66044231 7 Q2 42.90896 1.0198649 0.06902657 7 Q3 44.09009 1.0506361 0.66856623 7 Q4 45.14425 1.0513087 -0.14953828 8 Q1 47.40675 1.2820524 -0.20643321 8 Q2 50.63909 1.6541486 0.45309209 8 Q3 52.02538 1.6030622 0.37431460 8 Q4 53.53302 1.5848579 -0.39031444 9 Q1 53.81436 1.3364606 -0.87812605 9 Q2 54.87225 1.2833315 0.54252707 9 Q3 57.37194 1.5152477 0.81638240 9 Q4 59.39285 1.6116862 -0.14727963 10 Q1 62.05927 1.8126920 -0.62536394 10 Q2 62.38557 1.5292716 -0.17454517 10 Q3 63.64923 1.4786392 0.74586992 10 Q4 65.16546 1.4858070 -0.22145522 11 Q1 69.79279 2.0845033 0.54390316 11 Q2 71.35444 1.9848231 -0.57724741 11 Q3 72.62633 1.8489320 0.43327509 11 Q4 72.72634 1.5155080 -1.12452230 12 Q1 74.22018 1.5113777 0.81198864 12 Q2 75.24920 1.4194294 -0.53259992 12 Q3 75.43879 1.1850254 0.38801191 12 Q4 76.39561 1.1415238 -1.05640066 13 Q1 77.71588 1.1755867 1.01888073 13 Q2 79.05650 1.2070434 -0.30157765 13 Q3 81.82508 1.5046549 0.85634639 13 Q4 81.85356 1.2232854 -1.66062761 14 Q1 83.03007 1.2143726 1.03932328 14 Q2 84.68724 1.2987689 -0.34463414 14 Q3 85.25374 1.1592097 0.83325025 14 Q4 85.40245 0.9666126 -1.90191955 15 Q1 87.64123 1.2090514 1.47118710 15 Q2 89.37258 1.3085959 -0.14783356 15 Q3 92.99810 1.7501524 1.56330670 15 Q4 96.75946 2.1334641 -1.74511329 > m$resid Qtr1 Qtr2 Qtr3 Qtr4 1 0.00000000 0.00000000 0.31176086 0.45790295 2 0.10791325 0.40625818 -0.65524073 0.65433478 3 -0.47392722 0.31973080 0.93195405 -0.44955649 4 0.81619097 0.25786381 0.30968884 -0.77604658 5 0.40319368 0.82629888 0.20716468 -0.39377434 6 -1.00499506 0.21827651 1.06586906 0.59840653 7 1.55667132 -0.67347390 0.16639332 0.00363809 8 1.24926727 2.00708179 -0.27620024 -0.09844269 9 -1.34402972 -0.28676358 1.25381252 0.52140511 10 1.08713777 -1.53043625 -0.27371935 0.03874841 11 3.23723314 -0.53841636 -0.73458192 -1.80228929 12 -0.02232955 -0.49674698 -1.26703945 -0.23513001 13 0.18413617 0.16996530 1.60863211 -1.52077449 14 -0.04817698 0.45604435 -0.75431437 -1.04094507 15 1.31041865 0.53793042 2.38655217 2.07168501 > 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/1o4di1293369976.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/rcomp/tmp/2zdul1293369976.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/rcomp/tmp/3zdul1293369976.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/rcomp/tmp/4a5co1293369976.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/rcomp/tmp/5a5co1293369976.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/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/66w9f1293369976.tab") > > try(system("convert tmp/1o4di1293369976.ps tmp/1o4di1293369976.png",intern=TRUE)) character(0) > try(system("convert tmp/2zdul1293369976.ps tmp/2zdul1293369976.png",intern=TRUE)) character(0) > try(system("convert tmp/3zdul1293369976.ps tmp/3zdul1293369976.png",intern=TRUE)) character(0) > try(system("convert tmp/4a5co1293369976.ps tmp/4a5co1293369976.png",intern=TRUE)) character(0) > try(system("convert tmp/5a5co1293369976.ps tmp/5a5co1293369976.png",intern=TRUE)) character(0) > > > proc.time() user system elapsed 1.251 0.823 2.747