From 0902b470263e8081ebc8526b7d30f891f9c9fb16 Mon Sep 17 00:00:00 2001 From: Sebastian Weber Date: Wed, 20 Nov 2024 15:40:22 +0100 Subject: [PATCH] update --- DESCRIPTION | 8 ++++---- Makefile | 5 +++++ NEWS.md | 2 ++ R/mixstanvar.R | 8 ++++---- tests/testthat/helper-utils.R | 10 ++++++++++ tools/make-ds.R | 2 +- 6 files changed, 26 insertions(+), 9 deletions(-) create mode 100644 tests/testthat/helper-utils.R diff --git a/DESCRIPTION b/DESCRIPTION index b1eb6c6..34bc702 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -9,7 +9,7 @@ Description: Tool-set to support Bayesian evidence synthesis. This and Schmidli et al. (2014) explain details on the methodology. Version: 1.7-4 -Date: 2024-11-19 +Date: 2024-11-20 Authors@R: c(person("Novartis", "Pharma AG", role = "cph") ,person("Sebastian", "Weber", email="sebastian.weber@novartis.com", role=c("aut", "cre")) ,person("Beat", "Neuenschwander", email="beat.neuenschwander@novartis.com", role="ctb") @@ -25,7 +25,7 @@ Imports: methods, Rcpp (>= 0.12.0), RcppParallel (>= 5.0.1), - rstan (>= 2.26.0), + rstan (>= 2.32.0), rstantools (>= 2.4.0), assertthat, mvtnorm, @@ -44,8 +44,8 @@ LinkingTo: Rcpp (>= 0.12.0), RcppEigen (>= 0.3.3.3.0), RcppParallel (>= 5.0.1), - rstan (>= 2.26.0), - StanHeaders (>= 2.26.0) + rstan (>= 2.32.0), + StanHeaders (>= 2.32.0) License: GPL (>=3) LazyData: true Biarch: true diff --git a/Makefile b/Makefile index 59dfa27..3692867 100644 --- a/Makefile +++ b/Makefile @@ -156,6 +156,11 @@ r-source-check : r-source cd build; tar xvzf $(RPKG)-source.tar.gz cd build; NOT_CRAN=true $(RCMD) CMD check $(RPKG) +PHONY += r-source-release-check +r-source-release-check : r-source-release + cd build; tar xvzf $(RPKG)_$(PKG_VERSION).tar.gz + cd build; NOT_CRAN=true $(RCMD) CMD check $(RPKG) + build/installed/$(RPKG)/DESCRIPTION : build/r-source-fast rm -rf build/installed install -d build/installed diff --git a/NEWS.md b/NEWS.md index a2013eb..0d2baf7 100644 --- a/NEWS.md +++ b/NEWS.md @@ -13,6 +13,8 @@ * Avoid over and underflow of beta-binomial distribution. * Replace calls to deprecated `ggplot2::qplot` with respective calls to `ggplot2::ggplot`. +* Use new `array` notation for `mixstanvar` generated Stan code to + make generated Stan programs compatible with Stan >= 2.33 # RBesT 1.7-3 - January 2nd, 2024 diff --git a/R/mixstanvar.R b/R/mixstanvar.R index 4894a20..6da68e8 100644 --- a/R/mixstanvar.R +++ b/R/mixstanvar.R @@ -136,7 +136,7 @@ mixstanvar <- function(..., verbose=FALSE) { if(includes_density("mvnormMix")) { sv <- sv + brms::stanvar(name="mixmvnorm_lpdf", scode=" -real mixmvnorm_lpdf(vector y, vector w, vector[] m, matrix[] L) { +real mixmvnorm_lpdf(vector y, vector w, array[] vector m, array[] matrix L) { int Nc = rows(w); vector[Nc] lp_mix; for(i in 1:Nc) { @@ -218,10 +218,10 @@ mix2brms.mvnormMix <- function(mix, name, verbose=FALSE) { mvprior <- brms::stanvar(Nc, glue::glue("{prefix}Nc")) + brms::stanvar(p, glue::glue("{prefix}p")) + brms::stanvar(array(mix[1,,drop=TRUE], dim=Nc), glue::glue("{prefix}w"), scode=glue::glue("vector[{prefix}Nc] {prefix}w;")) + - brms::stanvar(t(mix[2:(p+1),,drop=FALSE]), glue::glue("{prefix}m"), scode=glue::glue("vector[{prefix}p] {prefix}m[{prefix}Nc];")) + - brms::stanvar(Sigma, glue::glue("{prefix}sigma"), scode=glue::glue("matrix[{prefix}p, {prefix}p] {prefix}sigma[{prefix}Nc];")) + + brms::stanvar(t(mix[2:(p+1),,drop=FALSE]), glue::glue("{prefix}m"), scode=glue::glue("array[{prefix}Nc] vector[{prefix}p] {prefix}m;")) + + brms::stanvar(Sigma, glue::glue("{prefix}sigma"), scode=glue::glue("array[{prefix}Nc] matrix[{prefix}p, {prefix}p] {prefix}sigma;")) + brms::stanvar(scode=glue::glue(" -matrix[{{prefix}}p, {{prefix}}p] {{prefix}}sigma_L[{{prefix}}Nc]; +array[{{prefix}}Nc] matrix[{{prefix}}p, {{prefix}}p] {{prefix}}sigma_L; for (i in 1:{{prefix}}Nc) { {{prefix}}sigma_L[i] = cholesky_decompose({{prefix}}sigma[i]); }", .open="{{", .close="}}"), block="tdata") diff --git a/tests/testthat/helper-utils.R b/tests/testthat/helper-utils.R new file mode 100644 index 0000000..95db7f2 --- /dev/null +++ b/tests/testthat/helper-utils.R @@ -0,0 +1,10 @@ + +source_example <- function(example, env=parent.frame(), disable_plots=TRUE) { + ex_source <- readLines(system.file("examples", example, package="RBesT", mustWork=TRUE)) + if(disable_plots) { + ex_source <- grep("plot\\(", ex_source, value=TRUE, invert=TRUE) + } + suppressMessages(ex <- source(textConnection(ex_source), + local=env, echo=FALSE, verbose=FALSE)) + invisible(ex) +} diff --git a/tools/make-ds.R b/tools/make-ds.R index 1ceff44..38f9787 100644 --- a/tools/make-ds.R +++ b/tools/make-ds.R @@ -43,7 +43,7 @@ make_internal_ds <- function() { calibration_meta["MD5"] <- vals["MD5"] pkg_create_date <- Sys.time() - pkg_sha <- "87eef77" + pkg_sha <- "1f6edf8" if (gsub("\\$", "", pkg_sha) == "Format:%h") { pkg_sha <- system("git rev-parse --short HEAD", intern=TRUE)