| Hosted by CoCalc | Download
Kernel: R (R-Project)

R-package bsts in CoCalc

Bayesian Structural Time Series: Time series regression using dynamic linear models fit using MCMC.

https://cran.r-project.org/web/packages/bsts/index.html

require('bsts')
Loading required package: bsts Loading required package: BoomSpikeSlab Loading required package: Boom Loading required package: MASS Attaching package: ‘Boom’ The following object is masked from ‘package:stats’: rWishart Loading required package: zoo Attaching package: ‘zoo’ The following objects are masked from ‘package:base’: as.Date, as.Date.numeric Loading required package: xts
data(AirPassengers) y <- log(AirPassengers) ss <- AddLocalLinearTrend(list(), y) ss <- AddSeasonal(ss, y, nseasons = 12) model <- bsts(y, state.specification = ss, niter = 500) summary(model)
=-=-=-=-= Iteration 0 Sun Dec 10 13:17:07 2017 =-=-=-=-= =-=-=-=-= Iteration 50 Sun Dec 10 13:17:08 2017 =-=-=-=-= =-=-=-=-= Iteration 100 Sun Dec 10 13:17:09 2017 =-=-=-=-= =-=-=-=-= Iteration 150 Sun Dec 10 13:17:10 2017 =-=-=-=-= =-=-=-=-= Iteration 200 Sun Dec 10 13:17:11 2017 =-=-=-=-= =-=-=-=-= Iteration 250 Sun Dec 10 13:17:12 2017 =-=-=-=-= =-=-=-=-= Iteration 300 Sun Dec 10 13:17:13 2017 =-=-=-=-= =-=-=-=-= Iteration 350 Sun Dec 10 13:17:14 2017 =-=-=-=-= =-=-=-=-= Iteration 400 Sun Dec 10 13:17:15 2017 =-=-=-=-= =-=-=-=-= Iteration 450 Sun Dec 10 13:17:16 2017 =-=-=-=-=
$residual.sd
0.0211826284956157
$prediction.sd
0.0561189186986301
$rsquare
0.997697582822533
$relative.gof
0.719501751226803
pred <- predict(model, horizon = 12, burn = 100) summary(pred)
Length Class Mode mean 12 -none- numeric median 12 -none- numeric interval 24 -none- numeric distribution 4800 -none- numeric original.series 144 zoo numeric
plot(pred)
Image in a Jupyter notebook