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 computationWed, 14 Dec 2016 23:08:00 +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/14/t1481753659fautmz4wp5q5p8u.htm/, Retrieved Fri, 03 May 2024 15:49:06 +0000
Statistical Computations at FreeStatistics.org, Office for Research Development and Education, URL https://freestatistics.org/blog/index.php?pk=299741, Retrieved Fri, 03 May 2024 15:49:06 +0000
QR Codes:

Original text written by user:
IsPrivate?No (this computation is public)
User-defined keywords
Estimated Impact47
Family? (F = Feedback message, R = changed R code, M = changed R Module, P = changed Parameters, D = changed Data)
-       [Structural Time Series Models] [N584 F1 competitie] [2016-12-14 22:08:00] [0fbc99f8be9cad246c7cf6558103ab95] [Current]
Feedback Forum

Post a new message
Dataseries X:
6114
6842
7751
7798
7656
7597
7360
7160
6873
6742
6593
6435
6482
6321
6092
6022
5891
5670
5358




Summary of computational transaction
Raw Input view raw input (R code)
Raw Outputview raw output of R engine
Computing time4 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 time4 seconds \tabularnewline
R ServerBig Analytics Cloud Computing Center \tabularnewline
\hline
\end{tabular}
%Source: https://freestatistics.org/blog/index.php?pk=299741&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]4 seconds[/C][/ROW] [ROW]R Server[/C]Big Analytics Cloud Computing Center[/C][/ROW] [/TABLE] Source: https://freestatistics.org/blog/index.php?pk=299741&T=0

Globally Unique Identifier (entire table): ba.freestatistics.org/blog/index.php?pk=299741&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 time4 seconds
R ServerBig Analytics Cloud Computing Center







Structural Time Series Model -- Interpolation
tObservedLevelSlopeSeasonalStand. Residuals
161146114000
268426842.00000003227727.99999993546-3.2269805771211e-082.48161169038516
377517750.99999999572909.0000000998464.27752227181781e-090.616994115713216
477987798.0000001294647.0000000000005-1.29456000072915e-07-2.93839186581413
576567656.00000012946-141.999999999999-1.29456000072917e-07-0.644264573516764
675977597.00000012946-58.9999999999998-1.29456000072917e-070.282931003184609
773607360.00000012946-236.999999999999-1.29456000072917e-07-0.606767693576635
871607160.00000012946-200-1.29456000072917e-070.126125868889524
968736873.00000012946-287-1.29456000072917e-07-0.296566232253748
1067426742.00000012946-130.999999999999-1.29456000072917e-070.531773933696379
1165936593.00000012946-149-1.29456000072917e-07-0.0613585308111225
1264356435.00000012946-158-1.29456000072918e-07-0.0306792654055591
1364826481.9999993244646.9999992177246.75538243544065e-070.698805487056992
1463216320.99999991241-160.9999992460928.7589476401489e-08-0.709031906900766
1560926092.00000007934-228.999999842108-7.9344714873067e-08-0.231798895968159
1660226022.00000005468-70-5.46769305517428e-080.542000355158216
1758915891.00000005468-131-5.46769305517441e-08-0.207937243304353
1856705670.00000005468-221-5.4676930551744e-08-0.306792654055603
1953585358.00000005468-312-5.46769305517441e-08-0.310201461322887

\begin{tabular}{lllllllll}
\hline
Structural Time Series Model -- Interpolation \tabularnewline
t & Observed & Level & Slope & Seasonal & Stand. Residuals \tabularnewline
1 & 6114 & 6114 & 0 & 0 & 0 \tabularnewline
2 & 6842 & 6842.00000003227 & 727.99999993546 & -3.2269805771211e-08 & 2.48161169038516 \tabularnewline
3 & 7751 & 7750.99999999572 & 909.000000099846 & 4.27752227181781e-09 & 0.616994115713216 \tabularnewline
4 & 7798 & 7798.00000012946 & 47.0000000000005 & -1.29456000072915e-07 & -2.93839186581413 \tabularnewline
5 & 7656 & 7656.00000012946 & -141.999999999999 & -1.29456000072917e-07 & -0.644264573516764 \tabularnewline
6 & 7597 & 7597.00000012946 & -58.9999999999998 & -1.29456000072917e-07 & 0.282931003184609 \tabularnewline
7 & 7360 & 7360.00000012946 & -236.999999999999 & -1.29456000072917e-07 & -0.606767693576635 \tabularnewline
8 & 7160 & 7160.00000012946 & -200 & -1.29456000072917e-07 & 0.126125868889524 \tabularnewline
9 & 6873 & 6873.00000012946 & -287 & -1.29456000072917e-07 & -0.296566232253748 \tabularnewline
10 & 6742 & 6742.00000012946 & -130.999999999999 & -1.29456000072917e-07 & 0.531773933696379 \tabularnewline
11 & 6593 & 6593.00000012946 & -149 & -1.29456000072917e-07 & -0.0613585308111225 \tabularnewline
12 & 6435 & 6435.00000012946 & -158 & -1.29456000072918e-07 & -0.0306792654055591 \tabularnewline
13 & 6482 & 6481.99999932446 & 46.999999217724 & 6.75538243544065e-07 & 0.698805487056992 \tabularnewline
14 & 6321 & 6320.99999991241 & -160.999999246092 & 8.7589476401489e-08 & -0.709031906900766 \tabularnewline
15 & 6092 & 6092.00000007934 & -228.999999842108 & -7.9344714873067e-08 & -0.231798895968159 \tabularnewline
16 & 6022 & 6022.00000005468 & -70 & -5.46769305517428e-08 & 0.542000355158216 \tabularnewline
17 & 5891 & 5891.00000005468 & -131 & -5.46769305517441e-08 & -0.207937243304353 \tabularnewline
18 & 5670 & 5670.00000005468 & -221 & -5.4676930551744e-08 & -0.306792654055603 \tabularnewline
19 & 5358 & 5358.00000005468 & -312 & -5.46769305517441e-08 & -0.310201461322887 \tabularnewline
\hline
\end{tabular}
%Source: https://freestatistics.org/blog/index.php?pk=299741&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]6114[/C][C]6114[/C][C]0[/C][C]0[/C][C]0[/C][/ROW]
[ROW][C]2[/C][C]6842[/C][C]6842.00000003227[/C][C]727.99999993546[/C][C]-3.2269805771211e-08[/C][C]2.48161169038516[/C][/ROW]
[ROW][C]3[/C][C]7751[/C][C]7750.99999999572[/C][C]909.000000099846[/C][C]4.27752227181781e-09[/C][C]0.616994115713216[/C][/ROW]
[ROW][C]4[/C][C]7798[/C][C]7798.00000012946[/C][C]47.0000000000005[/C][C]-1.29456000072915e-07[/C][C]-2.93839186581413[/C][/ROW]
[ROW][C]5[/C][C]7656[/C][C]7656.00000012946[/C][C]-141.999999999999[/C][C]-1.29456000072917e-07[/C][C]-0.644264573516764[/C][/ROW]
[ROW][C]6[/C][C]7597[/C][C]7597.00000012946[/C][C]-58.9999999999998[/C][C]-1.29456000072917e-07[/C][C]0.282931003184609[/C][/ROW]
[ROW][C]7[/C][C]7360[/C][C]7360.00000012946[/C][C]-236.999999999999[/C][C]-1.29456000072917e-07[/C][C]-0.606767693576635[/C][/ROW]
[ROW][C]8[/C][C]7160[/C][C]7160.00000012946[/C][C]-200[/C][C]-1.29456000072917e-07[/C][C]0.126125868889524[/C][/ROW]
[ROW][C]9[/C][C]6873[/C][C]6873.00000012946[/C][C]-287[/C][C]-1.29456000072917e-07[/C][C]-0.296566232253748[/C][/ROW]
[ROW][C]10[/C][C]6742[/C][C]6742.00000012946[/C][C]-130.999999999999[/C][C]-1.29456000072917e-07[/C][C]0.531773933696379[/C][/ROW]
[ROW][C]11[/C][C]6593[/C][C]6593.00000012946[/C][C]-149[/C][C]-1.29456000072917e-07[/C][C]-0.0613585308111225[/C][/ROW]
[ROW][C]12[/C][C]6435[/C][C]6435.00000012946[/C][C]-158[/C][C]-1.29456000072918e-07[/C][C]-0.0306792654055591[/C][/ROW]
[ROW][C]13[/C][C]6482[/C][C]6481.99999932446[/C][C]46.999999217724[/C][C]6.75538243544065e-07[/C][C]0.698805487056992[/C][/ROW]
[ROW][C]14[/C][C]6321[/C][C]6320.99999991241[/C][C]-160.999999246092[/C][C]8.7589476401489e-08[/C][C]-0.709031906900766[/C][/ROW]
[ROW][C]15[/C][C]6092[/C][C]6092.00000007934[/C][C]-228.999999842108[/C][C]-7.9344714873067e-08[/C][C]-0.231798895968159[/C][/ROW]
[ROW][C]16[/C][C]6022[/C][C]6022.00000005468[/C][C]-70[/C][C]-5.46769305517428e-08[/C][C]0.542000355158216[/C][/ROW]
[ROW][C]17[/C][C]5891[/C][C]5891.00000005468[/C][C]-131[/C][C]-5.46769305517441e-08[/C][C]-0.207937243304353[/C][/ROW]
[ROW][C]18[/C][C]5670[/C][C]5670.00000005468[/C][C]-221[/C][C]-5.4676930551744e-08[/C][C]-0.306792654055603[/C][/ROW]
[ROW][C]19[/C][C]5358[/C][C]5358.00000005468[/C][C]-312[/C][C]-5.46769305517441e-08[/C][C]-0.310201461322887[/C][/ROW]
[/TABLE]
Source: https://freestatistics.org/blog/index.php?pk=299741&T=1

Globally Unique Identifier (entire table): ba.freestatistics.org/blog/index.php?pk=299741&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
161146114000
268426842.00000003227727.99999993546-3.2269805771211e-082.48161169038516
377517750.99999999572909.0000000998464.27752227181781e-090.616994115713216
477987798.0000001294647.0000000000005-1.29456000072915e-07-2.93839186581413
576567656.00000012946-141.999999999999-1.29456000072917e-07-0.644264573516764
675977597.00000012946-58.9999999999998-1.29456000072917e-070.282931003184609
773607360.00000012946-236.999999999999-1.29456000072917e-07-0.606767693576635
871607160.00000012946-200-1.29456000072917e-070.126125868889524
968736873.00000012946-287-1.29456000072917e-07-0.296566232253748
1067426742.00000012946-130.999999999999-1.29456000072917e-070.531773933696379
1165936593.00000012946-149-1.29456000072917e-07-0.0613585308111225
1264356435.00000012946-158-1.29456000072918e-07-0.0306792654055591
1364826481.9999993244646.9999992177246.75538243544065e-070.698805487056992
1463216320.99999991241-160.9999992460928.7589476401489e-08-0.709031906900766
1560926092.00000007934-228.999999842108-7.9344714873067e-08-0.231798895968159
1660226022.00000005468-70-5.46769305517428e-080.542000355158216
1758915891.00000005468-131-5.46769305517441e-08-0.207937243304353
1856705670.00000005468-221-5.4676930551744e-08-0.306792654055603
1953585358.00000005468-312-5.46769305517441e-08-0.310201461322887







Structural Time Series Model -- Extrapolation
tObservedLevelSeasonal
15124.360028666655324.92518568926-200.565157022617
24849.69392969565247.82424981879-398.130320123189
34776.376552557545170.72331394831-394.34676139077
44730.408389071435093.62237807783-363.213989006398
54720.795370074555016.52144220735-295.726072132804
64947.089155706814939.420506336877.66864936993767
75077.91379242434862.3195704664215.594221957902
85287.931535492944785.21863459592502.712900897024
95169.148616259164708.11769872544461.030917533715
104948.064976441354631.01676285496317.048213586389
114746.177266586544553.91582698449192.261439602051
124432.480847842774476.81489111401-44.3340432712384

\begin{tabular}{lllllllll}
\hline
Structural Time Series Model -- Extrapolation \tabularnewline
t & Observed & Level & Seasonal \tabularnewline
1 & 5124.36002866665 & 5324.92518568926 & -200.565157022617 \tabularnewline
2 & 4849.6939296956 & 5247.82424981879 & -398.130320123189 \tabularnewline
3 & 4776.37655255754 & 5170.72331394831 & -394.34676139077 \tabularnewline
4 & 4730.40838907143 & 5093.62237807783 & -363.213989006398 \tabularnewline
5 & 4720.79537007455 & 5016.52144220735 & -295.726072132804 \tabularnewline
6 & 4947.08915570681 & 4939.42050633687 & 7.66864936993767 \tabularnewline
7 & 5077.9137924243 & 4862.3195704664 & 215.594221957902 \tabularnewline
8 & 5287.93153549294 & 4785.21863459592 & 502.712900897024 \tabularnewline
9 & 5169.14861625916 & 4708.11769872544 & 461.030917533715 \tabularnewline
10 & 4948.06497644135 & 4631.01676285496 & 317.048213586389 \tabularnewline
11 & 4746.17726658654 & 4553.91582698449 & 192.261439602051 \tabularnewline
12 & 4432.48084784277 & 4476.81489111401 & -44.3340432712384 \tabularnewline
\hline
\end{tabular}
%Source: https://freestatistics.org/blog/index.php?pk=299741&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]5124.36002866665[/C][C]5324.92518568926[/C][C]-200.565157022617[/C][/ROW]
[ROW][C]2[/C][C]4849.6939296956[/C][C]5247.82424981879[/C][C]-398.130320123189[/C][/ROW]
[ROW][C]3[/C][C]4776.37655255754[/C][C]5170.72331394831[/C][C]-394.34676139077[/C][/ROW]
[ROW][C]4[/C][C]4730.40838907143[/C][C]5093.62237807783[/C][C]-363.213989006398[/C][/ROW]
[ROW][C]5[/C][C]4720.79537007455[/C][C]5016.52144220735[/C][C]-295.726072132804[/C][/ROW]
[ROW][C]6[/C][C]4947.08915570681[/C][C]4939.42050633687[/C][C]7.66864936993767[/C][/ROW]
[ROW][C]7[/C][C]5077.9137924243[/C][C]4862.3195704664[/C][C]215.594221957902[/C][/ROW]
[ROW][C]8[/C][C]5287.93153549294[/C][C]4785.21863459592[/C][C]502.712900897024[/C][/ROW]
[ROW][C]9[/C][C]5169.14861625916[/C][C]4708.11769872544[/C][C]461.030917533715[/C][/ROW]
[ROW][C]10[/C][C]4948.06497644135[/C][C]4631.01676285496[/C][C]317.048213586389[/C][/ROW]
[ROW][C]11[/C][C]4746.17726658654[/C][C]4553.91582698449[/C][C]192.261439602051[/C][/ROW]
[ROW][C]12[/C][C]4432.48084784277[/C][C]4476.81489111401[/C][C]-44.3340432712384[/C][/ROW]
[/TABLE]
Source: https://freestatistics.org/blog/index.php?pk=299741&T=2

Globally Unique Identifier (entire table): ba.freestatistics.org/blog/index.php?pk=299741&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
15124.360028666655324.92518568926-200.565157022617
24849.69392969565247.82424981879-398.130320123189
34776.376552557545170.72331394831-394.34676139077
44730.408389071435093.62237807783-363.213989006398
54720.795370074555016.52144220735-295.726072132804
64947.089155706814939.420506336877.66864936993767
75077.91379242434862.3195704664215.594221957902
85287.931535492944785.21863459592502.712900897024
95169.148616259164708.11769872544461.030917533715
104948.064976441354631.01676285496317.048213586389
114746.177266586544553.91582698449192.261439602051
124432.480847842774476.81489111401-44.3340432712384



Parameters (Session):
par1 = TRUE ;
Parameters (R input):
par1 = 12 ; par2 = 12 ; par3 = BFGS ;
R code (references can be found in the software module):
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')