Skip to content

Commit

Permalink
version 0.9.10
Browse files Browse the repository at this point in the history
  • Loading branch information
steve-the-bayesian authored and cran-robot committed Jan 18, 2024
1 parent 2123cc3 commit f4573bf
Show file tree
Hide file tree
Showing 31 changed files with 120 additions and 1,029 deletions.
12 changes: 6 additions & 6 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
Package: bsts
Version: 0.9.9
Date: 2022-11-03
Version: 0.9.10
Date: 2024-01-16
Title: Bayesian Structural Time Series
Author: Steven L. Scott <[email protected]>
Maintainer: Steven L. Scott <[email protected]>
Description: Time series regression using dynamic linear models fit using
MCMC. See Scott and Varian (2014) <DOI:10.1504/IJMMNO.2014.059942>, among many
other sources.
Depends: BoomSpikeSlab (>= 1.2.5), zoo (>= 1.8), xts, Boom (>= 0.9.11),
Depends: BoomSpikeSlab (>= 1.2.6), zoo (>= 1.8), xts, Boom (>= 0.9.13),
R(>= 3.4.0)
Suggests: testthat
LinkingTo: Boom (>= 0.9.11)
LinkingTo: Boom (>= 0.9.13)
License: LGPL-2.1 | MIT + file LICENSE
Encoding: UTF-8
NeedsCompilation: yes
Packaged: 2022-11-06 20:47:53 UTC; steve
Packaged: 2024-01-16 23:31:15 UTC; steve
Repository: CRAN
Date/Publication: 2022-11-07 08:50:11 UTC
Date/Publication: 2024-01-17 13:02:07 UTC
41 changes: 13 additions & 28 deletions MD5
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
3e7a94e74d8420bd9659550450c174f2 *DESCRIPTION
9b8057b8ebc35b974db9119feef02663 *DESCRIPTION
ccd3022578bbd36b69595f56cd8d83e5 *LICENSE
1570eae7bf1ed9a241feeacb9404345b *NAMESPACE
ceb07fe9db975f5c42496dfaa33a5d14 *R/add.ar.R
Expand Down Expand Up @@ -53,6 +53,7 @@ abadc45049de045297dc88b776546d08 *inst/tests/tests/testthat/test-poisson.R
e91ff5f823c6acbff0b7b7d6810a82a8 *inst/tests/tests/testthat/test-prediction.R
74913baa6a0f8135591ba1c6d7b7e46e *inst/tests/tests/testthat/test-regressionholiday.R
ebe710afd159f82025b7c8b9d6e6d237 *inst/tests/tests/testthat/test-seasonal.R
e0c7763b06a704f13b10d4248db8f344 *inst/tests/tests/testthat/test-sigma-upper-limit.R
6c0c26d250eb86a7f004138b65297c90 *inst/tests/tests/testthat/test-student.R
9f6f10bf2045923b08f20734cef76b22 *inst/tests/tests/testthat/test-trig.R
0465bac211a2e128119a6fbd17f19c56 *inst/tests/testthat.R
Expand All @@ -70,6 +71,7 @@ abadc45049de045297dc88b776546d08 *inst/tests/testthat/test-poisson.R
e91ff5f823c6acbff0b7b7d6810a82a8 *inst/tests/testthat/test-prediction.R
74913baa6a0f8135591ba1c6d7b7e46e *inst/tests/testthat/test-regressionholiday.R
ebe710afd159f82025b7c8b9d6e6d237 *inst/tests/testthat/test-seasonal.R
e0c7763b06a704f13b10d4248db8f344 *inst/tests/testthat/test-sigma-upper-limit.R
6c0c26d250eb86a7f004138b65297c90 *inst/tests/testthat/test-student.R
9f6f10bf2045923b08f20734cef76b22 *inst/tests/testthat/test-trig.R
65ad45f30d10d63352989bcab06c428f *man/HarveyCumulator.Rd
Expand All @@ -91,7 +93,8 @@ dd0f4a731a23a55e13853e991fd64d2c *man/add.trig.Rd
98e85cce5007520dfeb7e492ade2722a *man/aggregate.time.series.Rd
bd91ad411945df7d74b054e3561cc2a6 *man/aggregate.weeks.to.months.Rd
db4593d8299a0b801fe53df3ecd777da *man/auto.ar.Rd
46167431326cedf0a047ae9a8dc18862 *man/bsts.Rd
0467eabb71ff9bfc6ae4d958d09aae86 *man/bsts-package.Rd
82ca0c557d1452e4d6abc107365e9a84 *man/bsts.Rd
177c7d07d4182091f2d0b810a1dd0819 *man/bsts.options.Rd
2ceaadc5491d127d9021ff75b21c8e7e *man/compare.bsts.models.Rd
99b12efa80a168f273cf27497dd8ba2b *man/date.range.Rd
Expand All @@ -111,7 +114,7 @@ e7b9351ff2f8b0c117c1b2377303603d *man/geometric.sequence.Rd
cf7b7d18e7252f5eccd0341eb26a6d82 *man/last.day.in.month.Rd
d001026a7f503a1d7e4c3139b193bfe5 *man/match.week.to.month.Rd
5c321a7f4189941f9d151f71627da8d2 *man/max.window.width.Rd
576c4c6a098bada394edefb47521ed30 *man/mbsts.Rd
ddf15410ad1df7752a9ac9d277b0b409 *man/mbsts.Rd
43b82cce35af62b441d08cda809329a1 *man/mixed.frequency.Rd
4c9639c7bfb85396081677060adc4541 *man/month.distance.Rd
129cf408079a8ce4c6fea7e5e1c54515 *man/named.holidays.Rd
Expand Down Expand Up @@ -142,25 +145,25 @@ bdeeea57d63366747d7bbace634387f7 *man/turkish.Rd
b57c602efad59be679c77a916faf619c *man/week.ends.Rd
d96e18ecf4ab02527bf1b60ce08f106e *man/weekday.names.Rd
cd4f3fcff595de3ac83d8e85ce89e627 *man/wide.to.long.Rd
ad3e4c15cd397b85b1c6a45f0803500a *src/Makevars
6afd68425262b76be593fe3cff3d8515 *src/Makevars
d99ce4ef93988dc2e1b7279ab92be31e *src/aggregate_time_series.cc
84059b88fee889c7194f6d541ce3ed54 *src/bsts.cc
2fe9977b38f7901775a6f0ae9341eb00 *src/bsts.cc
8c5caf631398cd06050d059691d443e3 *src/bsts_init.cc
604673026495a954489f5e86602bc48f *src/create_dynamic_intercept_state_model.cpp
2d60cd8ba33ef34e0238517e07bf7c9c *src/create_dynamic_intercept_state_model.h
74533455e40f6d52661548ec47182a25 *src/create_shared_state_model.cpp
06586064da9cccf1136dd127958adefe *src/create_shared_state_model.h
619fe844a942187bf979040bffe92752 *src/create_shared_state_model.cpp
2b570f69cfae36e7504ca69b0629812b *src/create_shared_state_model.h
776cfc2e6f5b39a8354601ceaf73905b *src/create_state_model.cpp
f8f89c660dc8cf6920e8694d25b99671 *src/create_state_model.h
4a0ab82799effea8a0f2998cfb9302f7 *src/dirm.cc
d65049aab4c84ce9c17312853647bbe2 *src/dirm.cc
c230f6664bd466e38e8e427d73b81cd2 *src/dynamic_intercept_model_manager.cc
f4b47e0c03ea817b60f652813b16fb06 *src/dynamic_intercept_model_manager.h
e6f88ebc8a3c65c29fd14268e57fe4d9 *src/get_date_ranges.cc
cf13c9e432dda0d3468449ec04dc4804 *src/mbsts.cc
4bc3088809b3d5525ee65288bf8aa959 *src/mixed_frequency.cc
bc75e43ff4ec384d60484d3adee324ba *src/model_manager.cc
17d5861e914a1658a6ec202fce330e6a *src/model_manager.h
c25fa6519d37e732f1ffc9016596a23d *src/multivariate_gaussian_model_manager.cc
ca7ae7e3f1e12ed16c131187921c2595 *src/multivariate_gaussian_model_manager.cc
d1cd0b01191824fd3e84d41bcedd276a *src/multivariate_gaussian_model_manager.h
74e7f2c3bc45e9f519ed32dcfcc4f134 *src/state_space_gaussian_model_manager.cc
2bedea75559c6e5f0a0bd7d3af6090e8 *src/state_space_gaussian_model_manager.h
Expand All @@ -170,27 +173,9 @@ a432aebec2404eb926fe13e9bcb5fb25 *src/state_space_logit_model_manager.cc
e216be891919e3263441168f35507631 *src/state_space_poisson_model_manager.h
d12a59708f82f866ed02944f5431bb59 *src/state_space_regression_model_manager.cc
7ac07cf5d57c124a845c31baeb64f782 *src/state_space_regression_model_manager.h
0af65cdc6fe068f8fc2df588f4898f05 *src/state_space_student_model_manager.cc
7f6a474ddee50e7d05fd12687d3dd8fe *src/state_space_student_model_manager.cc
70d7c3d65ab85979568d692b4a217f9f *src/state_space_student_model_manager.h
b8f60bed801663863a327aa8bd4d367e *src/timestamp_info.cc
1c682544f82b2cf9331c827ec6c3f0cf *src/timestamp_info.h
758355f181bebfed943c020342250e5e *src/utils.cc
02c97999019ae7fc533919fff4029385 *src/utils.h
0465bac211a2e128119a6fbd17f19c56 *tests/testthat.R
2c297be76520a1e86a59e50ffce13d00 *tests/testthat/test-ar.R
630452660972de113c484c1dd4d52269 *tests/testthat/test-autoar.R
172df9e68c0f7876dcaade3768c2d5f9 *tests/testthat/test-date-range.R
0126f04464776f5b1b05c32d25d25f55 *tests/testthat/test-dirm.R
3de38eb5bcb72ddf38c3b818d9518c0d *tests/testthat/test-dynamic-regression.R
236c11dceb0ea37b1966a706f7ac3a62 *tests/testthat/test-goog.R
8e8e34dbc5a1d1735ec663091bcd03a9 *tests/testthat/test-holidays.R
5c8960cc0a588cb58e49ab39b39cf683 *tests/testthat/test-multivariate.R
b8cf1c7b59eede2825f50fea5feac4c1 *tests/testthat/test-plot-components.R
abadc45049de045297dc88b776546d08 *tests/testthat/test-poisson.R
5c420ef79df05489ab47c1ee48ee0323 *tests/testthat/test-prediction-errors.R
e91ff5f823c6acbff0b7b7d6810a82a8 *tests/testthat/test-prediction.R
74913baa6a0f8135591ba1c6d7b7e46e *tests/testthat/test-regressionholiday.R
ebe710afd159f82025b7c8b9d6e6d237 *tests/testthat/test-seasonal.R
e0c7763b06a704f13b10d4248db8f344 *tests/testthat/test-sigma-upper-limit.R
6c0c26d250eb86a7f004138b65297c90 *tests/testthat/test-student.R
9f6f10bf2045923b08f20734cef76b22 *tests/testthat/test-trig.R
File renamed without changes.
19 changes: 19 additions & 0 deletions inst/tests/testthat/test-sigma-upper-limit.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
library(bsts)
library(testthat)

test_that("sigma.upper.limit can be specified at the main bsts call.", {
y <- rnorm(4)
x <- rnorm(4)
ss <- AddLocalLevel(list(), y)

warning("enable the test for 'sigma.upper.limit'")

## for (i in 1:20) {
## model <- bsts(y, ss, niter = 100, ping = -1, sigma.upper.limit = 10)
## }
## expect_true(inherits(model, "bsts"))

## for(i in 1:20) {
## model <- bsts(y ~ x, ss, niter = 10, ping = -1, sigma.upper.limit = 10)
## }
})
36 changes: 36 additions & 0 deletions man/bsts-package.Rd
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
\name{bsts-package}
\alias{bsts-package}
\docType{package}
\title{
bsts
}

\description{
Time series regression using dynamic linear models fit using
MCMC. See Scott and Varian (2014) <DOI:10.1504/IJMMNO.2014.059942>, among many
other sources.
}

\details{
\subsection{Installation note for Linux users}{ If you are installing bsts
using \code{\link{install.packages}} on a Linux machine (and thus
compiling yourself) you will almost certainly want to set the
\code{Ncpus} argument to a large number. Windows and Mac users can
ignore this advice. }

}

\author{
Author: Steven L. Scott <steve.the.bayesian@gmail.com>
Maintainer: Steven L. Scott <steve.the.bayesian@gmail.com>
}

\references{
Please see the references in the help page for the \code{\link{bsts}} function.
}

\keyword{ package }

\seealso{
See the examples in the \code{\link{bsts}} function.
}
15 changes: 9 additions & 6 deletions man/bsts.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,15 @@ bsts(formula,
exposure times. }

\references{
Scott and Varian (2014)
"Predicting the Present with Bayesian Structural Time Series",
International Journal of Mathematical Modelling and Numerical
Optimization. 4--23.

Scott and Varian (2015)
"Bayesian Variable Selection for Nowcasting Economic Time Series",
Economic Analysis of the Digital Economy, pp 119-135.

Harvey (1990), "Forecasting, structural time series, and the Kalman
filter", Cambridge University Press.

Expand All @@ -220,12 +229,6 @@ bsts(formula,
George and McCulloch (1997)
"Approaches for Bayesian variable selection", Statistica Sinica pp
339--374.

Ghosh and Clyde (2011)
"Rao-Blackwellization for Bayesian variable selection and model averaging
in linear and binary regression: a novel data augmentation approach",
JASA pp 1041 --1052.

}

\author{
Expand Down
2 changes: 1 addition & 1 deletion man/mbsts.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ opar <- par(mfrow=c(nfactors,1), mar=c(0, 4, 0, 4), omi=rep(.25, 4))
burn <- 10
for(j in 1:nfactors) {
BoxplotTrue(model$shared.local.level.coefficients[-(1:burn), j, ],
t(observation.coefficients[, j]), axes=F, truth.color="blue")
t(observation.coefficients)[, j], axes=F, truth.color="blue")
abline(h=0, lty=3)
box()
axis(2)
Expand Down
10 changes: 8 additions & 2 deletions src/Makevars
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
BOOM_DIR = `$(R_HOME)/bin/Rscript -e "cat(system.file(package='Boom'))"`
BOOM_LIB = ${BOOM_DIR}/lib${R_ARCH}/libboom.a
PKG_LIBS = ${BOOM_LIB}
PKG_LIBS = ${BOOM_LIB}
PKG_CPPFLAGS = -I${BOOM_DIR}/include -DADD_ -DR_NO_REMAP -DRLANGUAGE

# PKG_CXXFLAGS= -fsanitize=address
# PKG_CXXFLAGS= -fsanitize=undefined

CXX_STD = CXX11
# CXX_STD = CXX11

# When compiling remotely (e.g. on CRAN's winbuilder) flags to be
# passed to make can be specified here.
# -k: keep going
# -j 16: use 16 threads
# MAKEFLAGS=" -j 32 "
2 changes: 1 addition & 1 deletion src/bsts.cc
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ extern "C" {
<< "Time used was "
<< double(current_time - start_time) / CLOCKS_PER_SEC
<< " seconds.";
Rf_warning(warning.str().c_str());
Rf_warning("%s", warning.str().c_str());
return BOOM::appendListElement(
ans,
ToRVector(BOOM::Vector(1, i + 1)),
Expand Down
13 changes: 11 additions & 2 deletions src/create_shared_state_model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,15 @@ namespace BOOM {
SharedStateModelVector &state_models,
CIMSSMB *model,
SEXP r_shared_state_specification,
const std::vector<Ptr<UnivParams>> &residual_variance_parameters,
const std::string &prefix) {
if (!model) return;
int number_of_state_models = Rf_length(r_shared_state_specification);
for (int i = 0; i < number_of_state_models; ++i) {
state_models.add_state(CreateSharedStateModel(
model,
VECTOR_ELT(r_shared_state_specification, i),
residual_variance_parameters,
prefix));
}
InstallPostStateListElements();
Expand Down Expand Up @@ -82,9 +84,14 @@ namespace BOOM {
CISSMF::CreateSharedStateModel(
CIMSSMB *model,
SEXP r_state_component,
const std::vector<Ptr<UnivParams>> &residual_variance_parameters,
const std::string &prefix) {
if (Rf_inherits(r_state_component, "SharedLocalLevel")) {
return CreateSharedLocalLevel(r_state_component, model, prefix);
return CreateSharedLocalLevel(
r_state_component,
model,
residual_variance_parameters,
prefix);
} else {
report_error("Unrecognized shared state model.");
}
Expand Down Expand Up @@ -125,6 +132,7 @@ namespace BOOM {
Ptr<SharedStateModel> CISSMF::CreateSharedLocalLevel(
SEXP r_state_component,
CIMSSMB *model,
const std::vector<Ptr<UnivParams>> &residual_variance_parameters,
const std::string &prefix) {
int nfactors = lround(Rf_asReal(getListElement(r_state_component, "size")));
NEW(ConditionallyIndependentSharedLocalLevelStateModel, state_model)(
Expand Down Expand Up @@ -161,7 +169,8 @@ namespace BOOM {

// Set the posterior sampler for the overall state model.
NEW(ConditionallyIndependentSharedLocalLevelPosteriorSampler,
state_model_sampler)(state_model.get(), slabs, spikes);
state_model_sampler)(state_model.get(), slabs, spikes,
residual_variance_parameters);

state_model->set_method(state_model_sampler);

Expand Down
3 changes: 3 additions & 0 deletions src/create_shared_state_model.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ namespace BOOM {
void AddState(SharedStateModelVector &state_models,
CIMSSMB *model,
SEXP r_shared_state_specification,
const std::vector<Ptr<UnivParams>> &residual_variance_parameters,
const std::string &prefix = "");

// Save the final state (i.e. at time T) of the model for use with
Expand Down Expand Up @@ -118,13 +119,15 @@ namespace BOOM {
Ptr<SharedStateModel> CreateSharedStateModel(
CIMSSMB *model,
SEXP r_state_component,
const std::vector<Ptr<UnivParams>> &residual_variance_parameters,
const std::string &prefix);


// Specific functions to create specific state models.
Ptr<SharedStateModel> CreateSharedLocalLevel(
SEXP r_state_component,
CIMSSMB *model,
const std::vector<Ptr<UnivParams>> &residual_variance_parameters,
const std::string &prefix);
};

Expand Down
6 changes: 3 additions & 3 deletions src/dirm.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ extern "C" {
using namespace BOOM;
using namespace BOOM::RInterface;
using namespace BOOM::bsts;

SEXP analysis_common_r_fit_dirm_(
SEXP r_data_list,
SEXP r_state_specification,
Expand All @@ -55,7 +55,7 @@ extern "C" {
r_data_list,
r_state_specification,
r_prior,
r_options,
r_options,
&io_manager));

// Do one posterior sampling step before getting ready to write. This
Expand Down Expand Up @@ -88,7 +88,7 @@ extern "C" {
<< "Time used was "
<< double(current_time - start_time) / CLOCKS_PER_SEC
<< " seconds.";
Rf_warning(warning.str().c_str());
Rf_warning("%s", warning.str().c_str());
return BOOM::appendListElement(
ans,
ToRVector(BOOM::Vector(1, i + 1)),
Expand Down
12 changes: 9 additions & 3 deletions src/multivariate_gaussian_model_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,16 @@ namespace BOOM {
CreateBareModel(r_data_list_or_model_object, r_prior, r_options, io_manager);
ConditionallyIndependentSharedStateModelFactory
shared_state_model_factory(nseries_, io_manager);
std::vector<Ptr<UnivParams>> residual_variance_parameters;
for (int i = 0; i < model_->nseries(); ++i) {
residual_variance_parameters.push_back(
model_->observation_model()->model(i)->Sigsq_prm());
}
shared_state_model_factory.AddState(
model_->state_models(),
model_.get(),
r_shared_state_specification,
residual_variance_parameters,
"");
shared_state_model_factory.SaveFinalState(model_.get(), &final_state());

Expand Down Expand Up @@ -137,8 +143,8 @@ namespace BOOM {
RListIoManager *subordinate_io_manager =
subordinate_model_io->subordinate_io_manager(i);
StateModelFactory series_state_factory(subordinate_io_manager);
ProxyScalarStateSpaceModel *subordinate_model =
model_->series_specific_model(i).get();
ProxyScalarStateSpaceModel<MultivariateStateSpaceRegressionModel>
*subordinate_model = model_->series_specific_model(i);

series_state_factory.AddState(
subordinate_model, r_subordinate_state_specification);
Expand Down Expand Up @@ -329,7 +335,7 @@ namespace BOOM {
}
for (int i = 0; i < Rf_length(r_prior); ++i) {
BOOM::RInterface::SetRegressionSampler(
model_->observation_model()->model(i).get(),
model_->observation_model()->model(i),
VECTOR_ELT(r_prior, i));
}

Expand Down
2 changes: 1 addition & 1 deletion src/state_space_student_model_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ namespace BOOM {
RListIoManager *io_manager) {
Matrix predictors;
Vector response;
std::vector<bool> response_is_observed;
if (!Rf_isNull(r_data_list)) {
std::vector<bool> response_is_observed;
// If we were passed data from R then use it to build the model.
SEXP r_predictors = getListElement(r_data_list, "predictors");
if (Rf_inherits(r_data_list, "bsts")) {
Expand Down
Loading

0 comments on commit f4573bf

Please sign in to comment.