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, 07 Dec 2016 17:55:39 +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/07/t14811298125yost1x288se1h2.htm/, Retrieved Tue, 07 May 2024 09:11:33 +0000
Statistical Computations at FreeStatistics.org, Office for Research Development and Education, URL https://freestatistics.org/blog/index.php?pk=298259, Retrieved Tue, 07 May 2024 09:11:33 +0000
QR Codes:

Original text written by user:
IsPrivate?No (this computation is public)
User-defined keywords
Estimated Impact59
Family? (F = Feedback message, R = changed R code, M = changed R Module, P = changed Parameters, D = changed Data)
-       [Structural Time Series Models] [N434 F1 comp] [2016-12-07 16:55:39] [fe6e63930acb843607fc81833855c27b] [Current]
Feedback Forum

Post a new message
Dataseries X:
2481
2740
3121
3321
3430
3842
4272
4502
4450
4739
5099
5287
5406
5622
5896




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

Globally Unique Identifier (entire table): ba.freestatistics.org/blog/index.php?pk=298259&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
124812481000
227402728.4631074850948.673552342362311.53689251490931.06366576893587
331213112.54944227608207.7634191346798.450557723920061.870433501707
433213312.51330835583203.8907811710958.48669164416535-0.0428434994455945
534303421.2941724959156.0816207208778.70582750410448-0.521047996417988
638423833.58668320274285.3362513968998.413316797261371.40351456481412
742724263.66847069824358.4439071618298.331529301756010.793127820371367
845024493.63255676167293.5237044387988.36744323832572-0.704149182282991
944504441.58477811345118.8772928598348.41522188655109-1.8941794395145
1047394730.59641189593204.8672802980968.403588104071810.932617635813034
1150995090.60165832443283.2806164535538.398341675566590.850441162653419
1252875278.60006477193235.1200806740348.3999352280737-0.522330407320804
1354065502.07309074229229.401219508981-96.073090742286-0.0721690488363008
1456225615.70102969521177.1189441660736.29897030478632-0.513494445395198
1558965890.03623595523226.5968197474175.96376404477370.528278830276952

\begin{tabular}{lllllllll}
\hline
Structural Time Series Model -- Interpolation \tabularnewline
t & Observed & Level & Slope & Seasonal & Stand. Residuals \tabularnewline
1 & 2481 & 2481 & 0 & 0 & 0 \tabularnewline
2 & 2740 & 2728.46310748509 & 48.6735523423623 & 11.5368925149093 & 1.06366576893587 \tabularnewline
3 & 3121 & 3112.54944227608 & 207.763419134679 & 8.45055772392006 & 1.870433501707 \tabularnewline
4 & 3321 & 3312.51330835583 & 203.890781171095 & 8.48669164416535 & -0.0428434994455945 \tabularnewline
5 & 3430 & 3421.2941724959 & 156.081620720877 & 8.70582750410448 & -0.521047996417988 \tabularnewline
6 & 3842 & 3833.58668320274 & 285.336251396899 & 8.41331679726137 & 1.40351456481412 \tabularnewline
7 & 4272 & 4263.66847069824 & 358.443907161829 & 8.33152930175601 & 0.793127820371367 \tabularnewline
8 & 4502 & 4493.63255676167 & 293.523704438798 & 8.36744323832572 & -0.704149182282991 \tabularnewline
9 & 4450 & 4441.58477811345 & 118.877292859834 & 8.41522188655109 & -1.8941794395145 \tabularnewline
10 & 4739 & 4730.59641189593 & 204.867280298096 & 8.40358810407181 & 0.932617635813034 \tabularnewline
11 & 5099 & 5090.60165832443 & 283.280616453553 & 8.39834167556659 & 0.850441162653419 \tabularnewline
12 & 5287 & 5278.60006477193 & 235.120080674034 & 8.3999352280737 & -0.522330407320804 \tabularnewline
13 & 5406 & 5502.07309074229 & 229.401219508981 & -96.073090742286 & -0.0721690488363008 \tabularnewline
14 & 5622 & 5615.70102969521 & 177.118944166073 & 6.29897030478632 & -0.513494445395198 \tabularnewline
15 & 5896 & 5890.03623595523 & 226.596819747417 & 5.9637640447737 & 0.528278830276952 \tabularnewline
\hline
\end{tabular}
%Source: https://freestatistics.org/blog/index.php?pk=298259&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]2481[/C][C]2481[/C][C]0[/C][C]0[/C][C]0[/C][/ROW]
[ROW][C]2[/C][C]2740[/C][C]2728.46310748509[/C][C]48.6735523423623[/C][C]11.5368925149093[/C][C]1.06366576893587[/C][/ROW]
[ROW][C]3[/C][C]3121[/C][C]3112.54944227608[/C][C]207.763419134679[/C][C]8.45055772392006[/C][C]1.870433501707[/C][/ROW]
[ROW][C]4[/C][C]3321[/C][C]3312.51330835583[/C][C]203.890781171095[/C][C]8.48669164416535[/C][C]-0.0428434994455945[/C][/ROW]
[ROW][C]5[/C][C]3430[/C][C]3421.2941724959[/C][C]156.081620720877[/C][C]8.70582750410448[/C][C]-0.521047996417988[/C][/ROW]
[ROW][C]6[/C][C]3842[/C][C]3833.58668320274[/C][C]285.336251396899[/C][C]8.41331679726137[/C][C]1.40351456481412[/C][/ROW]
[ROW][C]7[/C][C]4272[/C][C]4263.66847069824[/C][C]358.443907161829[/C][C]8.33152930175601[/C][C]0.793127820371367[/C][/ROW]
[ROW][C]8[/C][C]4502[/C][C]4493.63255676167[/C][C]293.523704438798[/C][C]8.36744323832572[/C][C]-0.704149182282991[/C][/ROW]
[ROW][C]9[/C][C]4450[/C][C]4441.58477811345[/C][C]118.877292859834[/C][C]8.41522188655109[/C][C]-1.8941794395145[/C][/ROW]
[ROW][C]10[/C][C]4739[/C][C]4730.59641189593[/C][C]204.867280298096[/C][C]8.40358810407181[/C][C]0.932617635813034[/C][/ROW]
[ROW][C]11[/C][C]5099[/C][C]5090.60165832443[/C][C]283.280616453553[/C][C]8.39834167556659[/C][C]0.850441162653419[/C][/ROW]
[ROW][C]12[/C][C]5287[/C][C]5278.60006477193[/C][C]235.120080674034[/C][C]8.3999352280737[/C][C]-0.522330407320804[/C][/ROW]
[ROW][C]13[/C][C]5406[/C][C]5502.07309074229[/C][C]229.401219508981[/C][C]-96.073090742286[/C][C]-0.0721690488363008[/C][/ROW]
[ROW][C]14[/C][C]5622[/C][C]5615.70102969521[/C][C]177.118944166073[/C][C]6.29897030478632[/C][C]-0.513494445395198[/C][/ROW]
[ROW][C]15[/C][C]5896[/C][C]5890.03623595523[/C][C]226.596819747417[/C][C]5.9637640447737[/C][C]0.528278830276952[/C][/ROW]
[/TABLE]
Source: https://freestatistics.org/blog/index.php?pk=298259&T=1

Globally Unique Identifier (entire table): ba.freestatistics.org/blog/index.php?pk=298259&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
124812481000
227402728.4631074850948.673552342362311.53689251490931.06366576893587
331213112.54944227608207.7634191346798.450557723920061.870433501707
433213312.51330835583203.8907811710958.48669164416535-0.0428434994455945
534303421.2941724959156.0816207208778.70582750410448-0.521047996417988
638423833.58668320274285.3362513968998.413316797261371.40351456481412
742724263.66847069824358.4439071618298.331529301756010.793127820371367
845024493.63255676167293.5237044387988.36744323832572-0.704149182282991
944504441.58477811345118.8772928598348.41522188655109-1.8941794395145
1047394730.59641189593204.8672802980968.403588104071810.932617635813034
1150995090.60165832443283.2806164535538.398341675566590.850441162653419
1252875278.60006477193235.1200806740348.3999352280737-0.522330407320804
1354065502.07309074229229.401219508981-96.073090742286-0.0721690488363008
1456225615.70102969521177.1189441660736.29897030478632-0.513494445395198
1558965890.03623595523226.5968197474175.96376404477370.528278830276952







Structural Time Series Model -- Extrapolation
tObservedLevelSeasonal
16032.652319879066052.74820471318-20.0958848341249
26081.931296837076251.07023193067-169.13893509361
36440.167732430796449.39225914817-9.22452671737722
46821.996839170796647.71428636566174.282552805126
57009.419331552276846.03631358315163.38301796912
66920.435251157547044.35834080064-123.923089643107
77178.043780829597242.68036801814-64.6365871885468
87512.245139624737441.0023952356371.242744389099
97680.039846697397639.3244224531240.7154242442701
107784.427950775427837.64644967061-53.2184988951873
117985.008437348138035.9684768881-50.960039539971
128275.864326609918234.290504105641.5738225043096

\begin{tabular}{lllllllll}
\hline
Structural Time Series Model -- Extrapolation \tabularnewline
t & Observed & Level & Seasonal \tabularnewline
1 & 6032.65231987906 & 6052.74820471318 & -20.0958848341249 \tabularnewline
2 & 6081.93129683707 & 6251.07023193067 & -169.13893509361 \tabularnewline
3 & 6440.16773243079 & 6449.39225914817 & -9.22452671737722 \tabularnewline
4 & 6821.99683917079 & 6647.71428636566 & 174.282552805126 \tabularnewline
5 & 7009.41933155227 & 6846.03631358315 & 163.38301796912 \tabularnewline
6 & 6920.43525115754 & 7044.35834080064 & -123.923089643107 \tabularnewline
7 & 7178.04378082959 & 7242.68036801814 & -64.6365871885468 \tabularnewline
8 & 7512.24513962473 & 7441.00239523563 & 71.242744389099 \tabularnewline
9 & 7680.03984669739 & 7639.32442245312 & 40.7154242442701 \tabularnewline
10 & 7784.42795077542 & 7837.64644967061 & -53.2184988951873 \tabularnewline
11 & 7985.00843734813 & 8035.9684768881 & -50.960039539971 \tabularnewline
12 & 8275.86432660991 & 8234.2905041056 & 41.5738225043096 \tabularnewline
\hline
\end{tabular}
%Source: https://freestatistics.org/blog/index.php?pk=298259&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]6032.65231987906[/C][C]6052.74820471318[/C][C]-20.0958848341249[/C][/ROW]
[ROW][C]2[/C][C]6081.93129683707[/C][C]6251.07023193067[/C][C]-169.13893509361[/C][/ROW]
[ROW][C]3[/C][C]6440.16773243079[/C][C]6449.39225914817[/C][C]-9.22452671737722[/C][/ROW]
[ROW][C]4[/C][C]6821.99683917079[/C][C]6647.71428636566[/C][C]174.282552805126[/C][/ROW]
[ROW][C]5[/C][C]7009.41933155227[/C][C]6846.03631358315[/C][C]163.38301796912[/C][/ROW]
[ROW][C]6[/C][C]6920.43525115754[/C][C]7044.35834080064[/C][C]-123.923089643107[/C][/ROW]
[ROW][C]7[/C][C]7178.04378082959[/C][C]7242.68036801814[/C][C]-64.6365871885468[/C][/ROW]
[ROW][C]8[/C][C]7512.24513962473[/C][C]7441.00239523563[/C][C]71.242744389099[/C][/ROW]
[ROW][C]9[/C][C]7680.03984669739[/C][C]7639.32442245312[/C][C]40.7154242442701[/C][/ROW]
[ROW][C]10[/C][C]7784.42795077542[/C][C]7837.64644967061[/C][C]-53.2184988951873[/C][/ROW]
[ROW][C]11[/C][C]7985.00843734813[/C][C]8035.9684768881[/C][C]-50.960039539971[/C][/ROW]
[ROW][C]12[/C][C]8275.86432660991[/C][C]8234.2905041056[/C][C]41.5738225043096[/C][/ROW]
[/TABLE]
Source: https://freestatistics.org/blog/index.php?pk=298259&T=2

Globally Unique Identifier (entire table): ba.freestatistics.org/blog/index.php?pk=298259&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
16032.652319879066052.74820471318-20.0958848341249
26081.931296837076251.07023193067-169.13893509361
36440.167732430796449.39225914817-9.22452671737722
46821.996839170796647.71428636566174.282552805126
57009.419331552276846.03631358315163.38301796912
66920.435251157547044.35834080064-123.923089643107
77178.043780829597242.68036801814-64.6365871885468
87512.245139624737441.0023952356371.242744389099
97680.039846697397639.3244224531240.7154242442701
107784.427950775427837.64644967061-53.2184988951873
117985.008437348138035.9684768881-50.960039539971
128275.864326609918234.290504105641.5738225043096



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