Free Statistics

of Irreproducible Research!

Author's title

Author*The author of this computation has been verified*
R Software Modulerwasp_structuraltimeseries.wasp
Title produced by softwareStructural Time Series Models
Date of computationSun, 18 Dec 2016 15:11:28 +0100
Cite this page as followsStatistical Computations at FreeStatistics.org, Office for Research Development and Education, URL https://freestatistics.org/blog/index.php?v=date/2016/Dec/18/t1482070384pl56fbffam46yh7.htm/, Retrieved Fri, 01 Nov 2024 03:32:23 +0000
Statistical Computations at FreeStatistics.org, Office for Research Development and Education, URL https://freestatistics.org/blog/index.php?pk=301101, Retrieved Fri, 01 Nov 2024 03:32:23 +0000
QR Codes:

Original text written by user:
IsPrivate?No (this computation is public)
User-defined keywords
Estimated Impact72
Family? (F = Feedback message, R = changed R code, M = changed R Module, P = changed Parameters, D = changed Data)
-       [Structural Time Series Models] [structural time s...] [2016-12-18 14:11:28] [cedc5386ad7644fa02c81dc221bdf6b7] [Current]
Feedback Forum

Post a new message
Dataseries X:
691.72
839.86
1083.36
1326.82
1555.92
1385.54
1704.08
1737.16
1913.56
2487.28
2696.24
2982.52
3165.84
3580.66




Summary of computational transaction
Raw Input view raw input (R code)
Raw Outputview raw output of R engine
Computing time3 seconds
R ServerBig Analytics Cloud Computing Center

\begin{tabular}{lllllllll}
\hline
Summary of computational transaction \tabularnewline
Raw Input view raw input (R code)  \tabularnewline
Raw Outputview raw output of R engine  \tabularnewline
Computing time3 seconds \tabularnewline
R ServerBig Analytics Cloud Computing Center \tabularnewline
\hline
\end{tabular}
%Source: https://freestatistics.org/blog/index.php?pk=301101&T=0

[TABLE]
[ROW]
Summary of computational transaction[/C][/ROW] [ROW]Raw Input[/C] view raw input (R code) [/C][/ROW] [ROW]Raw Output[/C]view raw output of R engine [/C][/ROW] [ROW]Computing time[/C]3 seconds[/C][/ROW] [ROW]R Server[/C]Big Analytics Cloud Computing Center[/C][/ROW] [/TABLE] Source: https://freestatistics.org/blog/index.php?pk=301101&T=0

Globally Unique Identifier (entire table): ba.freestatistics.org/blog/index.php?pk=301101&T=0

As an alternative you can also use a QR Code:  

The GUIDs for individual cells are displayed in the table below:

Summary of computational transaction
Raw Input view raw input (R code)
Raw Outputview raw output of R engine
Computing time3 seconds
R ServerBig Analytics Cloud Computing Center







Structural Time Series Model -- Interpolation
tObservedLevelSlopeSeasonalStand. Residuals
1691.72691.72000
2839.86819.84815956037528.808306258578720.01184043962520.761907318391191
31083.361037.07935741206108.80812721799746.28064258794291.25105920865598
41326.821300.33921298185183.21489233675226.48078701815280.953965116071532
51555.921546.6617067266213.6012585330079.258293273395310.387621898642
61385.541455.4396264570166.74722066005-69.8996264570106-1.89111475769963
71704.081644.84082336416125.94889065616259.23917663584350.763496532816836
81737.161745.47358950615113.720541989136-8.31358950615171-0.157704309256131
91913.561895.88092355245131.44408643482717.67907644754580.228566491656865
102487.282395.40022409138309.27028429111991.8797759086222.29326680519597
112696.242714.79398068634314.161339275104-18.55398068633950.063075562895928
122982.522986.42972526533293.615025703169-3.90972526532664-0.264967461197746
133165.843240.4231592389274.936938548064-74.5831592389042-0.264874442851182
143580.663585.4485850613307.116722749547-4.788585061304340.392854545083798

\begin{tabular}{lllllllll}
\hline
Structural Time Series Model -- Interpolation \tabularnewline
t & Observed & Level & Slope & Seasonal & Stand. Residuals \tabularnewline
1 & 691.72 & 691.72 & 0 & 0 & 0 \tabularnewline
2 & 839.86 & 819.848159560375 & 28.8083062585787 & 20.0118404396252 & 0.761907318391191 \tabularnewline
3 & 1083.36 & 1037.07935741206 & 108.808127217997 & 46.2806425879429 & 1.25105920865598 \tabularnewline
4 & 1326.82 & 1300.33921298185 & 183.214892336752 & 26.4807870181528 & 0.953965116071532 \tabularnewline
5 & 1555.92 & 1546.6617067266 & 213.601258533007 & 9.25829327339531 & 0.387621898642 \tabularnewline
6 & 1385.54 & 1455.43962645701 & 66.74722066005 & -69.8996264570106 & -1.89111475769963 \tabularnewline
7 & 1704.08 & 1644.84082336416 & 125.948890656162 & 59.2391766358435 & 0.763496532816836 \tabularnewline
8 & 1737.16 & 1745.47358950615 & 113.720541989136 & -8.31358950615171 & -0.157704309256131 \tabularnewline
9 & 1913.56 & 1895.88092355245 & 131.444086434827 & 17.6790764475458 & 0.228566491656865 \tabularnewline
10 & 2487.28 & 2395.40022409138 & 309.270284291119 & 91.879775908622 & 2.29326680519597 \tabularnewline
11 & 2696.24 & 2714.79398068634 & 314.161339275104 & -18.5539806863395 & 0.063075562895928 \tabularnewline
12 & 2982.52 & 2986.42972526533 & 293.615025703169 & -3.90972526532664 & -0.264967461197746 \tabularnewline
13 & 3165.84 & 3240.4231592389 & 274.936938548064 & -74.5831592389042 & -0.264874442851182 \tabularnewline
14 & 3580.66 & 3585.4485850613 & 307.116722749547 & -4.78858506130434 & 0.392854545083798 \tabularnewline
\hline
\end{tabular}
%Source: https://freestatistics.org/blog/index.php?pk=301101&T=1

[TABLE]
[ROW][C]Structural Time Series Model -- Interpolation[/C][/ROW]
[ROW][C]t[/C][C]Observed[/C][C]Level[/C][C]Slope[/C][C]Seasonal[/C][C]Stand. Residuals[/C][/ROW]
[ROW][C]1[/C][C]691.72[/C][C]691.72[/C][C]0[/C][C]0[/C][C]0[/C][/ROW]
[ROW][C]2[/C][C]839.86[/C][C]819.848159560375[/C][C]28.8083062585787[/C][C]20.0118404396252[/C][C]0.761907318391191[/C][/ROW]
[ROW][C]3[/C][C]1083.36[/C][C]1037.07935741206[/C][C]108.808127217997[/C][C]46.2806425879429[/C][C]1.25105920865598[/C][/ROW]
[ROW][C]4[/C][C]1326.82[/C][C]1300.33921298185[/C][C]183.214892336752[/C][C]26.4807870181528[/C][C]0.953965116071532[/C][/ROW]
[ROW][C]5[/C][C]1555.92[/C][C]1546.6617067266[/C][C]213.601258533007[/C][C]9.25829327339531[/C][C]0.387621898642[/C][/ROW]
[ROW][C]6[/C][C]1385.54[/C][C]1455.43962645701[/C][C]66.74722066005[/C][C]-69.8996264570106[/C][C]-1.89111475769963[/C][/ROW]
[ROW][C]7[/C][C]1704.08[/C][C]1644.84082336416[/C][C]125.948890656162[/C][C]59.2391766358435[/C][C]0.763496532816836[/C][/ROW]
[ROW][C]8[/C][C]1737.16[/C][C]1745.47358950615[/C][C]113.720541989136[/C][C]-8.31358950615171[/C][C]-0.157704309256131[/C][/ROW]
[ROW][C]9[/C][C]1913.56[/C][C]1895.88092355245[/C][C]131.444086434827[/C][C]17.6790764475458[/C][C]0.228566491656865[/C][/ROW]
[ROW][C]10[/C][C]2487.28[/C][C]2395.40022409138[/C][C]309.270284291119[/C][C]91.879775908622[/C][C]2.29326680519597[/C][/ROW]
[ROW][C]11[/C][C]2696.24[/C][C]2714.79398068634[/C][C]314.161339275104[/C][C]-18.5539806863395[/C][C]0.063075562895928[/C][/ROW]
[ROW][C]12[/C][C]2982.52[/C][C]2986.42972526533[/C][C]293.615025703169[/C][C]-3.90972526532664[/C][C]-0.264967461197746[/C][/ROW]
[ROW][C]13[/C][C]3165.84[/C][C]3240.4231592389[/C][C]274.936938548064[/C][C]-74.5831592389042[/C][C]-0.264874442851182[/C][/ROW]
[ROW][C]14[/C][C]3580.66[/C][C]3585.4485850613[/C][C]307.116722749547[/C][C]-4.78858506130434[/C][C]0.392854545083798[/C][/ROW]
[/TABLE]
Source: https://freestatistics.org/blog/index.php?pk=301101&T=1

Globally Unique Identifier (entire table): ba.freestatistics.org/blog/index.php?pk=301101&T=1

As an alternative you can also use a QR Code:  

The GUIDs for individual cells are displayed in the table below:

Structural Time Series Model -- Interpolation
tObservedLevelSlopeSeasonalStand. Residuals
1691.72691.72000
2839.86819.84815956037528.808306258578720.01184043962520.761907318391191
31083.361037.07935741206108.80812721799746.28064258794291.25105920865598
41326.821300.33921298185183.21489233675226.48078701815280.953965116071532
51555.921546.6617067266213.6012585330079.258293273395310.387621898642
61385.541455.4396264570166.74722066005-69.8996264570106-1.89111475769963
71704.081644.84082336416125.94889065616259.23917663584350.763496532816836
81737.161745.47358950615113.720541989136-8.31358950615171-0.157704309256131
91913.561895.88092355245131.44408643482717.67907644754580.228566491656865
102487.282395.40022409138309.27028429111991.8797759086222.29326680519597
112696.242714.79398068634314.161339275104-18.55398068633950.063075562895928
122982.522986.42972526533293.615025703169-3.90972526532664-0.264967461197746
133165.843240.4231592389274.936938548064-74.5831592389042-0.264874442851182
143580.663585.4485850613307.116722749547-4.788585061304340.392854545083798







Structural Time Series Model -- Extrapolation
tObservedLevelSeasonal
13945.614739426413857.1741236632488.4406157631718
24334.401248615434157.14017504476177.261073570668
34687.518458527814457.10622642629230.412232101516
44627.376558931294757.07227780782-129.695718876533
55042.3747790775057.03832918935-14.6635501123477
65158.133130035565357.00438057088-198.871250535316
75403.431211308425656.97043195241-253.539220643986
86032.268956587875956.9364833339475.3324732539358
96282.567037131796256.9025347154725.6645024163243
106596.405535280916556.86858609739.5369491839134
116793.504603638886856.83463747852-63.3300338396402
127180.252616578357156.8006888600523.4519277182928

\begin{tabular}{lllllllll}
\hline
Structural Time Series Model -- Extrapolation \tabularnewline
t & Observed & Level & Seasonal \tabularnewline
1 & 3945.61473942641 & 3857.17412366324 & 88.4406157631718 \tabularnewline
2 & 4334.40124861543 & 4157.14017504476 & 177.261073570668 \tabularnewline
3 & 4687.51845852781 & 4457.10622642629 & 230.412232101516 \tabularnewline
4 & 4627.37655893129 & 4757.07227780782 & -129.695718876533 \tabularnewline
5 & 5042.374779077 & 5057.03832918935 & -14.6635501123477 \tabularnewline
6 & 5158.13313003556 & 5357.00438057088 & -198.871250535316 \tabularnewline
7 & 5403.43121130842 & 5656.97043195241 & -253.539220643986 \tabularnewline
8 & 6032.26895658787 & 5956.93648333394 & 75.3324732539358 \tabularnewline
9 & 6282.56703713179 & 6256.90253471547 & 25.6645024163243 \tabularnewline
10 & 6596.40553528091 & 6556.868586097 & 39.5369491839134 \tabularnewline
11 & 6793.50460363888 & 6856.83463747852 & -63.3300338396402 \tabularnewline
12 & 7180.25261657835 & 7156.80068886005 & 23.4519277182928 \tabularnewline
\hline
\end{tabular}
%Source: https://freestatistics.org/blog/index.php?pk=301101&T=2

[TABLE]
[ROW][C]Structural Time Series Model -- Extrapolation[/C][/ROW]
[ROW][C]t[/C][C]Observed[/C][C]Level[/C][C]Seasonal[/C][/ROW]
[ROW][C]1[/C][C]3945.61473942641[/C][C]3857.17412366324[/C][C]88.4406157631718[/C][/ROW]
[ROW][C]2[/C][C]4334.40124861543[/C][C]4157.14017504476[/C][C]177.261073570668[/C][/ROW]
[ROW][C]3[/C][C]4687.51845852781[/C][C]4457.10622642629[/C][C]230.412232101516[/C][/ROW]
[ROW][C]4[/C][C]4627.37655893129[/C][C]4757.07227780782[/C][C]-129.695718876533[/C][/ROW]
[ROW][C]5[/C][C]5042.374779077[/C][C]5057.03832918935[/C][C]-14.6635501123477[/C][/ROW]
[ROW][C]6[/C][C]5158.13313003556[/C][C]5357.00438057088[/C][C]-198.871250535316[/C][/ROW]
[ROW][C]7[/C][C]5403.43121130842[/C][C]5656.97043195241[/C][C]-253.539220643986[/C][/ROW]
[ROW][C]8[/C][C]6032.26895658787[/C][C]5956.93648333394[/C][C]75.3324732539358[/C][/ROW]
[ROW][C]9[/C][C]6282.56703713179[/C][C]6256.90253471547[/C][C]25.6645024163243[/C][/ROW]
[ROW][C]10[/C][C]6596.40553528091[/C][C]6556.868586097[/C][C]39.5369491839134[/C][/ROW]
[ROW][C]11[/C][C]6793.50460363888[/C][C]6856.83463747852[/C][C]-63.3300338396402[/C][/ROW]
[ROW][C]12[/C][C]7180.25261657835[/C][C]7156.80068886005[/C][C]23.4519277182928[/C][/ROW]
[/TABLE]
Source: https://freestatistics.org/blog/index.php?pk=301101&T=2

Globally Unique Identifier (entire table): ba.freestatistics.org/blog/index.php?pk=301101&T=2

As an alternative you can also use a QR Code:  

The GUIDs for individual cells are displayed in the table below:

Structural Time Series Model -- Extrapolation
tObservedLevelSeasonal
13945.614739426413857.1741236632488.4406157631718
24334.401248615434157.14017504476177.261073570668
34687.518458527814457.10622642629230.412232101516
44627.376558931294757.07227780782-129.695718876533
55042.3747790775057.03832918935-14.6635501123477
65158.133130035565357.00438057088-198.871250535316
75403.431211308425656.97043195241-253.539220643986
86032.268956587875956.9364833339475.3324732539358
96282.567037131796256.9025347154725.6645024163243
106596.405535280916556.86858609739.5369491839134
116793.504603638886856.83463747852-63.3300338396402
127180.252616578357156.8006888600523.4519277182928



Parameters (Session):
par1 = 12 ; par2 = 12 ; par3 = BFGS ;
Parameters (R input):
par1 = 12 ; par2 = 12 ; par3 = BFGS ;
R code (references can be found in the software module):
par3 <- 'BFGS'
par2 <- '1'
par1 <- '1'
require('stsm')
require('stsm.class')
require('KFKSDS')
par1 <- as.numeric(par1)
par2 <- as.numeric(par2)
nx <- length(x)
x <- ts(x,frequency=par1)
m <- StructTS(x,type='BSM')
print(m$coef)
print(m$fitted)
print(m$resid)
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
mm <- stsm.model(model = 'BSM', y = x, transPars = 'StructTS')
fit2 <- stsmFit(mm, stsm.method = 'maxlik.td.optim', method = par3, KF.args = list(P0cov = TRUE))
(fit2.comps <- tsSmooth(fit2, P0cov = FALSE)$states)
m2 <- set.pars(mm, pmax(fit2$par, .Machine$double.eps))
(ss <- char2numeric(m2))
(pred <- predict(ss, x, n.ahead = par2))
mylagmax <- nx/2
bitmap(file='test2.png')
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()
bitmap(file='test3.png')
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()
bitmap(file='test4.png')
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()
bitmap(file='test1.png')
plot(as.numeric(m$resid),main='Standardized Residuals',ylab='Residuals',xlab='time',type='b')
grid()
dev.off()
bitmap(file='test5.png')
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()
bitmap(file='test6.png')
par(mfrow = c(3,1), mar = c(3,3,3,3))
plot(cbind(x, pred$pred), type = 'n', plot.type = 'single', ylab = '')
lines(x)
polygon(c(time(pred$pred), rev(time(pred$pred))), c(pred$pred + 2 * pred$se, rev(pred$pred)), col = 'gray85', border = NA)
polygon(c(time(pred$pred), rev(time(pred$pred))), c(pred$pred - 2 * pred$se, rev(pred$pred)), col = ' gray85', border = NA)
lines(pred$pred, col = 'blue', lwd = 1.5)
mtext(text = 'forecasts of the observed series', side = 3, adj = 0)
plot(cbind(x, pred$a[,1]), type = 'n', plot.type = 'single', ylab = '')
lines(x)
polygon(c(time(pred$a[,1]), rev(time(pred$a[,1]))), c(pred$a[,1] + 2 * sqrt(pred$P[,1]), rev(pred$a[,1])), col = 'gray85', border = NA)
polygon(c(time(pred$a[,1]), rev(time(pred$a[,1]))), c(pred$a[,1] - 2 * sqrt(pred$P[,1]), rev(pred$a[,1])), col = ' gray85', border = NA)
lines(pred$a[,1], col = 'blue', lwd = 1.5)
mtext(text = 'forecasts of the level component', side = 3, adj = 0)
plot(cbind(fit2.comps[,3], pred$a[,3]), type = 'n', plot.type = 'single', ylab = '')
lines(fit2.comps[,3])
polygon(c(time(pred$a[,3]), rev(time(pred$a[,3]))), c(pred$a[,3] + 2 * sqrt(pred$P[,3]), rev(pred$a[,3])), col = 'gray85', border = NA)
polygon(c(time(pred$a[,3]), rev(time(pred$a[,3]))), c(pred$a[,3] - 2 * sqrt(pred$P[,3]), rev(pred$a[,3])), col = ' gray85', border = NA)
lines(pred$a[,3], col = 'blue', lwd = 1.5)
mtext(text = 'forecasts of the seasonal component', side = 3, adj = 0)
dev.off()
load(file='createtable')
a<-table.start()
a<-table.row.start(a)
a<-table.element(a,'Structural Time Series Model -- Interpolation',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='mytable.tab')
a<-table.start()
a<-table.row.start(a)
a<-table.element(a,'Structural Time Series Model -- Extrapolation',4,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,'Seasonal',header=TRUE)
a<-table.row.end(a)
for (i in 1:par2) {
a<-table.row.start(a)
a<-table.element(a,i,header=TRUE)
a<-table.element(a,pred$pred[i])
a<-table.element(a,pred$a[i,1])
a<-table.element(a,pred$a[i,3])
a<-table.row.end(a)
}
a<-table.end(a)
table.save(a,file='mytable1.tab')