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 computationFri, 16 Dec 2016 20:49:03 +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/16/t1481917834rp7tdme6j0770ld.htm/, Retrieved Thu, 02 May 2024 20:16:41 +0000
Statistical Computations at FreeStatistics.org, Office for Research Development and Education, URL https://freestatistics.org/blog/index.php?pk=300510, Retrieved Thu, 02 May 2024 20:16:41 +0000
QR Codes:

Original text written by user:
IsPrivate?No (this computation is public)
User-defined keywords
Estimated Impact71
Family? (F = Feedback message, R = changed R code, M = changed R Module, P = changed Parameters, D = changed Data)
-       [Structural Time Series Models] [] [2016-12-16 19:49:03] [404ac5ee4f7301873f6a96ef36861981] [Current]
Feedback Forum

Post a new message
Dataseries X:
2151.06
2332.26
2457.82
2533.53
2867.22
3186.52
3487.47
3733.52
4052.26
4482.15
5116.47
5671.98
6086.66
6229.16
6526.62
6735.6
6874.34
7206.03
7491.36




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=300510&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=300510&T=0

Globally Unique Identifier (entire table): ba.freestatistics.org/blog/index.php?pk=300510&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
12151.062151.06000
22332.262329.52700351201178.209779945810.1286115501444991.35803051064298
32457.822458.34879346847130.1881721557030.152817539797708-0.36511376194396
42533.532534.119136081177.21990303054660.154773574977382-0.400450846671405
52867.222863.61545044741322.7838414858040.1559590209897241.85646284049277
63186.523186.36451638025322.7499913571160.155958995434958-0.00025590676219744
73487.473487.60803001251301.8158458776110.155959517101107-0.158262007611447
83733.523734.12003306502247.9837529978780.155960136547708-0.406970282178104
94052.264051.16005359315315.2022907767320.1559601179684340.508171721067889
104482.154480.43469216129426.2389380917890.1559601335653380.839436352414247
115116.475113.4869405106627.5485195358930.155960135820731.52189916428215
125671.985672.75738836126561.08746818730.155960135906992-0.502445128439261
136086.666093.40065232451424.655898243872-4.82466998314267-1.04366053677104
146229.166233.31199732822157.789178937048-0.566971349613248-2.01337467497817
156526.626525.59290407642288.622394394783-0.7779418390085980.979777317489743
166735.66737.41748697696213.879270277824-0.767932310604539-0.565033782564868
176874.346876.13644419724140.718070068876-0.769003508951765-0.553097710965688
187206.037204.23704146233323.114420258026-0.7685319742316011.37891522862289
197491.367492.60352769522289.291202407955-0.768529949808912-0.25570331331852

\begin{tabular}{lllllllll}
\hline
Structural Time Series Model -- Interpolation \tabularnewline
t & Observed & Level & Slope & Seasonal & Stand. Residuals \tabularnewline
1 & 2151.06 & 2151.06 & 0 & 0 & 0 \tabularnewline
2 & 2332.26 & 2329.52700351201 & 178.20977994581 & 0.128611550144499 & 1.35803051064298 \tabularnewline
3 & 2457.82 & 2458.34879346847 & 130.188172155703 & 0.152817539797708 & -0.36511376194396 \tabularnewline
4 & 2533.53 & 2534.1191360811 & 77.2199030305466 & 0.154773574977382 & -0.400450846671405 \tabularnewline
5 & 2867.22 & 2863.61545044741 & 322.783841485804 & 0.155959020989724 & 1.85646284049277 \tabularnewline
6 & 3186.52 & 3186.36451638025 & 322.749991357116 & 0.155958995434958 & -0.00025590676219744 \tabularnewline
7 & 3487.47 & 3487.60803001251 & 301.815845877611 & 0.155959517101107 & -0.158262007611447 \tabularnewline
8 & 3733.52 & 3734.12003306502 & 247.983752997878 & 0.155960136547708 & -0.406970282178104 \tabularnewline
9 & 4052.26 & 4051.16005359315 & 315.202290776732 & 0.155960117968434 & 0.508171721067889 \tabularnewline
10 & 4482.15 & 4480.43469216129 & 426.238938091789 & 0.155960133565338 & 0.839436352414247 \tabularnewline
11 & 5116.47 & 5113.4869405106 & 627.548519535893 & 0.15596013582073 & 1.52189916428215 \tabularnewline
12 & 5671.98 & 5672.75738836126 & 561.0874681873 & 0.155960135906992 & -0.502445128439261 \tabularnewline
13 & 6086.66 & 6093.40065232451 & 424.655898243872 & -4.82466998314267 & -1.04366053677104 \tabularnewline
14 & 6229.16 & 6233.31199732822 & 157.789178937048 & -0.566971349613248 & -2.01337467497817 \tabularnewline
15 & 6526.62 & 6525.59290407642 & 288.622394394783 & -0.777941839008598 & 0.979777317489743 \tabularnewline
16 & 6735.6 & 6737.41748697696 & 213.879270277824 & -0.767932310604539 & -0.565033782564868 \tabularnewline
17 & 6874.34 & 6876.13644419724 & 140.718070068876 & -0.769003508951765 & -0.553097710965688 \tabularnewline
18 & 7206.03 & 7204.23704146233 & 323.114420258026 & -0.768531974231601 & 1.37891522862289 \tabularnewline
19 & 7491.36 & 7492.60352769522 & 289.291202407955 & -0.768529949808912 & -0.25570331331852 \tabularnewline
\hline
\end{tabular}
%Source: https://freestatistics.org/blog/index.php?pk=300510&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]2151.06[/C][C]2151.06[/C][C]0[/C][C]0[/C][C]0[/C][/ROW]
[ROW][C]2[/C][C]2332.26[/C][C]2329.52700351201[/C][C]178.20977994581[/C][C]0.128611550144499[/C][C]1.35803051064298[/C][/ROW]
[ROW][C]3[/C][C]2457.82[/C][C]2458.34879346847[/C][C]130.188172155703[/C][C]0.152817539797708[/C][C]-0.36511376194396[/C][/ROW]
[ROW][C]4[/C][C]2533.53[/C][C]2534.1191360811[/C][C]77.2199030305466[/C][C]0.154773574977382[/C][C]-0.400450846671405[/C][/ROW]
[ROW][C]5[/C][C]2867.22[/C][C]2863.61545044741[/C][C]322.783841485804[/C][C]0.155959020989724[/C][C]1.85646284049277[/C][/ROW]
[ROW][C]6[/C][C]3186.52[/C][C]3186.36451638025[/C][C]322.749991357116[/C][C]0.155958995434958[/C][C]-0.00025590676219744[/C][/ROW]
[ROW][C]7[/C][C]3487.47[/C][C]3487.60803001251[/C][C]301.815845877611[/C][C]0.155959517101107[/C][C]-0.158262007611447[/C][/ROW]
[ROW][C]8[/C][C]3733.52[/C][C]3734.12003306502[/C][C]247.983752997878[/C][C]0.155960136547708[/C][C]-0.406970282178104[/C][/ROW]
[ROW][C]9[/C][C]4052.26[/C][C]4051.16005359315[/C][C]315.202290776732[/C][C]0.155960117968434[/C][C]0.508171721067889[/C][/ROW]
[ROW][C]10[/C][C]4482.15[/C][C]4480.43469216129[/C][C]426.238938091789[/C][C]0.155960133565338[/C][C]0.839436352414247[/C][/ROW]
[ROW][C]11[/C][C]5116.47[/C][C]5113.4869405106[/C][C]627.548519535893[/C][C]0.15596013582073[/C][C]1.52189916428215[/C][/ROW]
[ROW][C]12[/C][C]5671.98[/C][C]5672.75738836126[/C][C]561.0874681873[/C][C]0.155960135906992[/C][C]-0.502445128439261[/C][/ROW]
[ROW][C]13[/C][C]6086.66[/C][C]6093.40065232451[/C][C]424.655898243872[/C][C]-4.82466998314267[/C][C]-1.04366053677104[/C][/ROW]
[ROW][C]14[/C][C]6229.16[/C][C]6233.31199732822[/C][C]157.789178937048[/C][C]-0.566971349613248[/C][C]-2.01337467497817[/C][/ROW]
[ROW][C]15[/C][C]6526.62[/C][C]6525.59290407642[/C][C]288.622394394783[/C][C]-0.777941839008598[/C][C]0.979777317489743[/C][/ROW]
[ROW][C]16[/C][C]6735.6[/C][C]6737.41748697696[/C][C]213.879270277824[/C][C]-0.767932310604539[/C][C]-0.565033782564868[/C][/ROW]
[ROW][C]17[/C][C]6874.34[/C][C]6876.13644419724[/C][C]140.718070068876[/C][C]-0.769003508951765[/C][C]-0.553097710965688[/C][/ROW]
[ROW][C]18[/C][C]7206.03[/C][C]7204.23704146233[/C][C]323.114420258026[/C][C]-0.768531974231601[/C][C]1.37891522862289[/C][/ROW]
[ROW][C]19[/C][C]7491.36[/C][C]7492.60352769522[/C][C]289.291202407955[/C][C]-0.768529949808912[/C][C]-0.25570331331852[/C][/ROW]
[/TABLE]
Source: https://freestatistics.org/blog/index.php?pk=300510&T=1

Globally Unique Identifier (entire table): ba.freestatistics.org/blog/index.php?pk=300510&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
12151.062151.06000
22332.262329.52700351201178.209779945810.1286115501444991.35803051064298
32457.822458.34879346847130.1881721557030.152817539797708-0.36511376194396
42533.532534.119136081177.21990303054660.154773574977382-0.400450846671405
52867.222863.61545044741322.7838414858040.1559590209897241.85646284049277
63186.523186.36451638025322.7499913571160.155958995434958-0.00025590676219744
73487.473487.60803001251301.8158458776110.155959517101107-0.158262007611447
83733.523734.12003306502247.9837529978780.155960136547708-0.406970282178104
94052.264051.16005359315315.2022907767320.1559601179684340.508171721067889
104482.154480.43469216129426.2389380917890.1559601335653380.839436352414247
115116.475113.4869405106627.5485195358930.155960135820731.52189916428215
125671.985672.75738836126561.08746818730.155960135906992-0.502445128439261
136086.666093.40065232451424.655898243872-4.82466998314267-1.04366053677104
146229.166233.31199732822157.789178937048-0.566971349613248-2.01337467497817
156526.626525.59290407642288.622394394783-0.7779418390085980.979777317489743
166735.66737.41748697696213.879270277824-0.767932310604539-0.565033782564868
176874.346876.13644419724140.718070068876-0.769003508951765-0.553097710965688
187206.037204.23704146233323.114420258026-0.7685319742316011.37891522862289
197491.367492.60352769522289.291202407955-0.768529949808912-0.25570331331852







Structural Time Series Model -- Extrapolation
tObservedLevelSeasonal
17713.749502427577969.30598628975-255.556483862182
28008.299755342778281.83082814719-273.531072804421
38412.813583964648594.35567000462-181.542086039985
49020.571344039968906.88051186206113.690832177903
59548.333850201529219.4053537195328.92849648202
69927.328997549019531.93019557694395.398801972072
710081.2352430189844.45503743437236.780205583593
810284.208974495410156.9798792918127.229095203601
910417.424961240410469.5047211492-52.0797599088602
1010643.917951732710782.0295630067-138.111611273987
1110959.097793432811094.5544048641-135.456611431289
1211241.329440623111407.0792467216-165.749806098465

\begin{tabular}{lllllllll}
\hline
Structural Time Series Model -- Extrapolation \tabularnewline
t & Observed & Level & Seasonal \tabularnewline
1 & 7713.74950242757 & 7969.30598628975 & -255.556483862182 \tabularnewline
2 & 8008.29975534277 & 8281.83082814719 & -273.531072804421 \tabularnewline
3 & 8412.81358396464 & 8594.35567000462 & -181.542086039985 \tabularnewline
4 & 9020.57134403996 & 8906.88051186206 & 113.690832177903 \tabularnewline
5 & 9548.33385020152 & 9219.4053537195 & 328.92849648202 \tabularnewline
6 & 9927.32899754901 & 9531.93019557694 & 395.398801972072 \tabularnewline
7 & 10081.235243018 & 9844.45503743437 & 236.780205583593 \tabularnewline
8 & 10284.2089744954 & 10156.9798792918 & 127.229095203601 \tabularnewline
9 & 10417.4249612404 & 10469.5047211492 & -52.0797599088602 \tabularnewline
10 & 10643.9179517327 & 10782.0295630067 & -138.111611273987 \tabularnewline
11 & 10959.0977934328 & 11094.5544048641 & -135.456611431289 \tabularnewline
12 & 11241.3294406231 & 11407.0792467216 & -165.749806098465 \tabularnewline
\hline
\end{tabular}
%Source: https://freestatistics.org/blog/index.php?pk=300510&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]7713.74950242757[/C][C]7969.30598628975[/C][C]-255.556483862182[/C][/ROW]
[ROW][C]2[/C][C]8008.29975534277[/C][C]8281.83082814719[/C][C]-273.531072804421[/C][/ROW]
[ROW][C]3[/C][C]8412.81358396464[/C][C]8594.35567000462[/C][C]-181.542086039985[/C][/ROW]
[ROW][C]4[/C][C]9020.57134403996[/C][C]8906.88051186206[/C][C]113.690832177903[/C][/ROW]
[ROW][C]5[/C][C]9548.33385020152[/C][C]9219.4053537195[/C][C]328.92849648202[/C][/ROW]
[ROW][C]6[/C][C]9927.32899754901[/C][C]9531.93019557694[/C][C]395.398801972072[/C][/ROW]
[ROW][C]7[/C][C]10081.235243018[/C][C]9844.45503743437[/C][C]236.780205583593[/C][/ROW]
[ROW][C]8[/C][C]10284.2089744954[/C][C]10156.9798792918[/C][C]127.229095203601[/C][/ROW]
[ROW][C]9[/C][C]10417.4249612404[/C][C]10469.5047211492[/C][C]-52.0797599088602[/C][/ROW]
[ROW][C]10[/C][C]10643.9179517327[/C][C]10782.0295630067[/C][C]-138.111611273987[/C][/ROW]
[ROW][C]11[/C][C]10959.0977934328[/C][C]11094.5544048641[/C][C]-135.456611431289[/C][/ROW]
[ROW][C]12[/C][C]11241.3294406231[/C][C]11407.0792467216[/C][C]-165.749806098465[/C][/ROW]
[/TABLE]
Source: https://freestatistics.org/blog/index.php?pk=300510&T=2

Globally Unique Identifier (entire table): ba.freestatistics.org/blog/index.php?pk=300510&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
17713.749502427577969.30598628975-255.556483862182
28008.299755342778281.83082814719-273.531072804421
38412.813583964648594.35567000462-181.542086039985
49020.571344039968906.88051186206113.690832177903
59548.333850201529219.4053537195328.92849648202
69927.328997549019531.93019557694395.398801972072
710081.2352430189844.45503743437236.780205583593
810284.208974495410156.9798792918127.229095203601
910417.424961240410469.5047211492-52.0797599088602
1010643.917951732710782.0295630067-138.111611273987
1110959.097793432811094.5544048641-135.456611431289
1211241.329440623111407.0792467216-165.749806098465



Parameters (Session):
par1 = 12 ; par2 = Double ; par3 = additive ; par4 = 12 ;
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')