From eb1a5cb4e4f19d87b1eb8abec3c7c4bba2e5dff3 Mon Sep 17 00:00:00 2001 From: Andrew Johnson Date: Mon, 14 Sep 2026 09:22:02 +0800 Subject: [PATCH 01/19] Update/simplify actions workflow --- .github/workflows/R-CMD-check.yaml | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/.github/workflows/R-CMD-check.yaml b/.github/workflows/R-CMD-check.yaml index 96412eb7e..98cb8517e 100644 --- a/.github/workflows/R-CMD-check.yaml +++ b/.github/workflows/R-CMD-check.yaml @@ -8,6 +8,10 @@ on: branches: - master +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + name: R-CMD-check jobs: @@ -27,19 +31,23 @@ jobs: TESTTHAT_CPUS: 4 steps: - - uses: n1hility/cancel-previous-runs@master + - uses: actions/checkout@v7 + + - uses: r-lib/actions/setup-r@v2 with: - token: ${{ secrets.GITHUB_TOKEN }} - if: "!startsWith(github.ref, 'refs/tags/') && github.ref != 'refs/heads/master'" + r-version: ${{ matrix.r }} - - uses: actions/checkout@main + - uses: r-lib/actions/setup-pandoc@v2 - - uses: r-lib/actions/setup-r@v2.11.4 + + - name: Install R Package Build Dependencies on MacOS + if: ${{ runner.os == 'macOS' }} + uses: r-hub/actions/setup-r-sysreqs@v1 with: - r-version: ${{ matrix.r }} + type: 'minimal' - - uses: r-lib/actions/setup-pandoc@v2.11.4 - - uses: r-lib/actions/setup-r-dependencies@v2.11.4 + - uses: r-lib/actions/setup-r-dependencies@v2 with: - extra-packages: any::rcmdcheck any::betareg any::HSAUR3 any::biglm any::gamm4 any::V8 - - uses: r-lib/actions/check-r-package@v2.11.4 + dependencies: "TRUE" + + - uses: r-lib/actions/check-r-package@v2 From 502035c61b793b7c389363e92cd263377054a64f Mon Sep 17 00:00:00 2001 From: Andrew Johnson Date: Mon, 14 Sep 2026 09:22:25 +0800 Subject: [PATCH 02/19] Update test expectation for new loo text --- tests/testthat/test_loo.R | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/tests/testthat/test_loo.R b/tests/testthat/test_loo.R index 4b320cef8..d07e0ac25 100644 --- a/tests/testthat/test_loo.R +++ b/tests/testthat/test_loo.R @@ -113,7 +113,7 @@ test_that("loo with k_threshold works", { seed = 12345, iter = 5, chains = 1, cores = 1, refresh = 0)) expect_message(loo(fit, k_threshold = 0.5), "Model will be refit") - + # test that no errors from binomial model because it's trickier to get the # data right internally in reloo (matrix outcome) SW(loo_x <- loo(example_model)) @@ -213,17 +213,17 @@ test_that("loo_compare throws correct errors", { # this uses loo::loo_compare expect_error(loo_compare(l1, l2), - "Not all models have the same number of data points") + "All models must have the same number of observations") expect_error(loo_compare(list(l4, l2, l3)), - "Not all models have the same number of data points") - + "All models must have the same number of observations") + # using loo_compare.stanreg (can do extra checks) fit1$loo <- l1 fit2$loo <- l2 fit3$loo <- l3 fit4$loo <- l4 - - expect_error(loo_compare(fit1, fit2), "Not all models have the same number of data points") + + expect_error(loo_compare(fit1, fit2), "All models must have the same number of observations") expect_warning(loo_compare(fit1, fit3), "Not all models have the same y variable") expect_error(loo_compare(fit1, fit4), "Discrete and continuous observation models can't be compared") @@ -269,15 +269,15 @@ test_that("loo_compare works", { expect_s3_class(comp2, "compare.loo") expect_equal(comp1[, "elpd_diff"], loo_compare(list(fit1$loo, fit2$loo))[, "elpd_diff"]) expect_equal(comp2[, "elpd_diff"], loo_compare(list(fit1$loo, fit2$loo, fit3$loo))[, "elpd_diff"]) - + comp1_detail <- loo_compare(fit1, fit2, detail=TRUE) expect_output(print(comp1_detail), "Model formulas") - + # equivalent to stanreg_list method expect_equivalent(comp2, loo_compare(stanreg_list(fit1, fit2, fit3))) # for kfold - expect_warning(comp3 <- loo_compare(k1, k2, k3), + expect_warning(comp3 <- loo_compare(k1, k2, k3), "Not all kfold objects have the same K value") expect_true(attr(k4, "discrete")) expect_true(attr(k5, "discrete")) From ec631303ae5721596675182f1dc487bf26f19397 Mon Sep 17 00:00:00 2001 From: Andrew Johnson Date: Mon, 14 Sep 2026 09:22:58 +0800 Subject: [PATCH 03/19] Update VarCorr return to align with lme4 changes --- R/stanreg-methods.R | 6 ++++-- tests/testthat/test_methods.R | 3 +-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/R/stanreg-methods.R b/R/stanreg-methods.R index 6e54a52f4..f267a708d 100644 --- a/R/stanreg-methods.R +++ b/R/stanreg-methods.R @@ -363,7 +363,8 @@ VarCorr.stanreg <- function(x, sigma = 1, ...) { rownames(Sigma) <- colnames(Sigma) <- cnms[[i]] stddev <- sqrt(diag(Sigma)) corr <- cov2cor(Sigma) - structure(Sigma, stddev = stddev, correlation = corr) + structure(Sigma, stddev = stddev, correlation = corr, + class = c("vcmat_us", "matrix", "array")) }) } else { # stanfit contains lower tri Sigma entries spt <- split(Sigma, rep.int(ncseq, (nc * (nc + 1)) / 2)) @@ -375,7 +376,8 @@ VarCorr.stanreg <- function(x, sigma = 1, ...) { rownames(Sigma) <- colnames(Sigma) <- cnms[[i]] stddev <- sqrt(diag(Sigma)) corr <- cov2cor(Sigma) - structure(Sigma, stddev = stddev, correlation = corr) + structure(Sigma, stddev = stddev, correlation = corr, + class = c("vcmat_us", "matrix", "array")) }) } names(ans) <- nms diff --git a/tests/testthat/test_methods.R b/tests/testthat/test_methods.R index 4df7bd71a..2a0090bf2 100644 --- a/tests/testthat/test_methods.R +++ b/tests/testthat/test_methods.R @@ -71,7 +71,7 @@ SW({ att_names <- function(object) { nms <- names(object) - att_nms <- names(attributes(object)) + att_nms <- sort(names(attributes(object))) att_nms2 <- lapply(object, function(x) sort(names(attributes(x)))) c(nms, att_nms, att_nms2) } @@ -869,4 +869,3 @@ test_that("as_draws methods work", { "not fit using MCMC" ) }) - From e3514b275847944f79bc99b24abeca7c50ab226e Mon Sep 17 00:00:00 2001 From: Andrew Johnson Date: Mon, 14 Sep 2026 09:39:00 +0800 Subject: [PATCH 04/19] Update pp_check exclusions for new functions --- R/pp_check.R | 2 +- tests/testthat/test_pp_check.R | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/R/pp_check.R b/R/pp_check.R index e484edf44..cbf4b00ac 100644 --- a/R/pp_check.R +++ b/R/pp_check.R @@ -312,7 +312,7 @@ is_binomial_ppc <- function(object, ...) { if (!is.null(xvar)) { dots[["x"]] <- .ppc_xvar(object, xvar, m = m) } else { - if (funname %in% c("ppc_intervals", "ppc_ribbon", "ppc_error_binned")) { + if (funname %in% c("ppc_intervals", "ppc_ribbon", "ppc_error_binned", "ppc_error_scatter_avg")) { message("'x' not specified in '...'. Using x=1:length(y).") dots[["x"]] <- seq_along(y) } else { diff --git a/tests/testthat/test_pp_check.R b/tests/testthat/test_pp_check.R index adc1831ed..b2c9720a9 100644 --- a/tests/testthat/test_pp_check.R +++ b/tests/testthat/test_pp_check.R @@ -49,7 +49,12 @@ test_that("pp_check.stanreg creates ggplot object", { "ppc_rootogram", "ppc_error_binned", "ppc_km_overlay", - "ppc_pit_ecdf") + "ppc_pit_ecdf", + "ppc_calibration", + "ppc_calibration_overlay", + "ppc_dots", + "ppc_loo_calibration", + "ppc_loo_pit_ecdf") for (f in ppc_funs_not_grouped) for (j in 1:2) { if (!f %in% exclude) { expect_gg(suppressWarnings(pp_check(fit, plotfun = f, nreps = j)), @@ -59,7 +64,8 @@ test_that("pp_check.stanreg creates ggplot object", { }) test_that("pp_check.stanreg creates ggplot object for grouped functions", { - exclude <- c("ppc_km_overlay_grouped", "ppc_pit_ecdf_grouped") + exclude <- c("ppc_km_overlay_grouped", "ppc_pit_ecdf_grouped", "ppc_calibration_grouped", + "ppc_calibration_overlay_grouped", "ppc_loo_calibration_grouped") for (f in setdiff(ppc_funs_grouped, ppc_funs_discrete)) for (j in 1:2) { if (!(f %in% exclude)) { expect_gg(suppressWarnings(pp_check(fit2, plotfun = f, nreps = j, group = "am", x = "wt")), From 1e75183cf853e2d18359cd7a9491d62a2a2e9743 Mon Sep 17 00:00:00 2001 From: Andrew Johnson Date: Mon, 14 Sep 2026 09:44:33 +0800 Subject: [PATCH 05/19] Update clogit test expectations --- tests/testthat/test_stan_clogit.R | 4 ---- 1 file changed, 4 deletions(-) diff --git a/tests/testthat/test_stan_clogit.R b/tests/testthat/test_stan_clogit.R index 532d4314f..df071e034 100644 --- a/tests/testthat/test_stan_clogit.R +++ b/tests/testthat/test_stan_clogit.R @@ -36,10 +36,6 @@ SW(fit <- stan_clogit(case ~ spontaneous + induced, strata = stratum, prior = NU test_that("stan_clogit is similar to survival::clogit", { ref_vals <- c(spontaneous = 1.985876, induced = 1.409012) - # Account for RNG change in new Stan - if (utils::packageVersion("StanHeaders") >= "2.36") { - ref_vals <- c(spontaneous = 2.062676, induced = 1.360712) - } expect_equal(ref_vals, coef(fit), tol = threshold) }) From 71b48518494e2a37bb78f9b217dc5e1bcc924e0a Mon Sep 17 00:00:00 2001 From: Andrew Johnson Date: Mon, 14 Sep 2026 10:04:34 +0800 Subject: [PATCH 06/19] Update loo test helper to align with implementation --- tests/testthat/helper.R | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/testthat/helper.R b/tests/testthat/helper.R index 18d409528..a3974c30b 100644 --- a/tests/testthat/helper.R +++ b/tests/testthat/helper.R @@ -53,7 +53,7 @@ check_for_pp_errors <- function(fit, data = NULL, offset = NULL) { expect_equivalent_loo <- function(fit) { LOO.CORES <- ifelse(.Platform$OS.type == "windows", 1, 2) - l <- suppressWarnings(loo(fit, cores = LOO.CORES)) + l <- suppressWarnings(loo(fit, cores = LOO.CORES, r_eff = TRUE)) w <- suppressWarnings(waic(fit)) expect_s3_class(l, "psis_loo") expect_s3_class(l, "loo") @@ -214,4 +214,3 @@ recover_pars <- function(modLong, modEvent = NULL, idvar = "id") { list(fixef = fixef_pars, ranef = ranef_pars, event = event_pars)) return(ret) } - From 0d0be9af1b5f58e1de80726ef49b91fdbabd8bcf Mon Sep 17 00:00:00 2001 From: Andrew Johnson Date: Mon, 14 Sep 2026 10:11:38 +0800 Subject: [PATCH 07/19] Replace deprecated ggplot syntax, re-generate doc --- DESCRIPTION | 2 +- NAMESPACE | 177 ++++++++++++++++++++++------------------ R/stan_gamm4.R | 12 +-- man/reexports.Rd | 2 +- man/rstanarm-package.Rd | 3 +- man/stan_betareg.Rd | 2 +- man/stan_biglm.Rd | 2 +- man/stan_clogit.Rd | 2 +- man/stan_gamm4.Rd | 2 +- man/stan_glm.Rd | 2 +- man/stan_glmer.Rd | 2 +- man/stan_jm.Rd | 2 +- man/stan_lm.Rd | 2 +- man/stan_mvmer.Rd | 2 +- man/stan_nlmer.Rd | 2 +- man/stan_polr.Rd | 2 +- 16 files changed, 119 insertions(+), 99 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 5a5a8fde3..c80c2b622 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -76,4 +76,4 @@ UseLTO: true NeedsCompilation: yes URL: https://mc-stan.org/rstanarm/, https://discourse.mc-stan.org BugReports: https://github.com/stan-dev/rstanarm/issues -RoxygenNote: 7.3.3 +Config/roxygen2/version: 8.1.0 diff --git a/NAMESPACE b/NAMESPACE index 1f93e3581..831990c53 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -197,88 +197,107 @@ import(methods) import(rstantools) import(shinystan) import(stats) -importFrom(Matrix,Matrix) -importFrom(Matrix,t) +importFrom(Matrix, + Matrix, + t +) importFrom(RcppParallel,RcppParallelLibs) -importFrom(bayesplot,pairs_condition) -importFrom(bayesplot,pairs_style_np) -importFrom(ggplot2,"%+replace%") -importFrom(ggplot2,aes) -importFrom(ggplot2,aes_) -importFrom(ggplot2,aes_string) -importFrom(ggplot2,coord_cartesian) -importFrom(ggplot2,element_line) -importFrom(ggplot2,element_text) -importFrom(ggplot2,expand_limits) -importFrom(ggplot2,facet_wrap) -importFrom(ggplot2,geom_contour) -importFrom(ggplot2,geom_line) -importFrom(ggplot2,geom_point) -importFrom(ggplot2,geom_pointrange) -importFrom(ggplot2,geom_ribbon) -importFrom(ggplot2,geom_segment) -importFrom(ggplot2,geom_smooth) -importFrom(ggplot2,geom_step) -importFrom(ggplot2,geom_vline) -importFrom(ggplot2,ggplot) -importFrom(ggplot2,ggplot_build) -importFrom(ggplot2,labs) -importFrom(ggplot2,rel) -importFrom(ggplot2,scale_color_gradient2) -importFrom(ggplot2,scale_x_continuous) -importFrom(ggplot2,scale_x_discrete) -importFrom(ggplot2,theme) -importFrom(ggplot2,theme_bw) -importFrom(ggplot2,xlab) -importFrom(lme4,fixef) -importFrom(lme4,glFormula) -importFrom(lme4,glmer) -importFrom(lme4,glmerControl) -importFrom(lme4,lmer) -importFrom(lme4,lmerControl) -importFrom(lme4,mkVarCorr) -importFrom(lme4,ngrps) -importFrom(lme4,nlformula) -importFrom(lme4,nlmer) -importFrom(lme4,nlmerControl) -importFrom(lme4,ranef) -importFrom(loo,is.kfold) -importFrom(loo,is.loo) -importFrom(loo,is.waic) -importFrom(loo,kfold) -importFrom(loo,loo) -importFrom(loo,loo.function) -importFrom(loo,loo.matrix) -importFrom(loo,loo_compare) -importFrom(loo,loo_model_weights) -importFrom(loo,psis) -importFrom(loo,waic) -importFrom(loo,waic.function) -importFrom(loo,waic.matrix) +importFrom(bayesplot, + pairs_condition, + pairs_style_np +) +importFrom(ggplot2, + "%+replace%", + aes, + aes_string, + coord_cartesian, + element_line, + element_text, + expand_limits, + facet_wrap, + geom_contour, + geom_line, + geom_point, + geom_pointrange, + geom_ribbon, + geom_segment, + geom_smooth, + geom_step, + geom_vline, + ggplot, + ggplot_build, + labs, + rel, + scale_color_gradient2, + scale_x_continuous, + scale_x_discrete, + theme, + theme_bw, + xlab +) +importFrom(lme4, + fixef, + glFormula, + glmer, + glmerControl, + lmer, + lmerControl, + mkVarCorr, + ngrps, + nlformula, + nlmer, + nlmerControl, + ranef +) +importFrom(loo, + is.kfold, + is.loo, + is.waic, + kfold, + loo, + loo.function, + loo.matrix, + loo_compare, + loo_model_weights, + psis, + waic, + waic.function, + waic.matrix +) importFrom(nlme,VarCorr) -importFrom(posterior,as_draws) -importFrom(posterior,as_draws_array) -importFrom(posterior,as_draws_df) -importFrom(posterior,as_draws_list) -importFrom(posterior,as_draws_matrix) -importFrom(posterior,as_draws_rvars) +importFrom(posterior, + as_draws, + as_draws_array, + as_draws_df, + as_draws_list, + as_draws_matrix, + as_draws_rvars +) importFrom(reformulas,findbars) -importFrom(rstan,constrain_pars) -importFrom(rstan,extract) -importFrom(rstan,extract_sparse_parts) -importFrom(rstan,get_posterior_mean) -importFrom(rstan,optimizing) -importFrom(rstan,sampling) -importFrom(rstan,stanc) -importFrom(rstan,vb) -importFrom(rstantools,loo_R2) -importFrom(rstantools,nsamples) -importFrom(stats,cov2cor) -importFrom(stats,getInitial) +importFrom(rstan, + constrain_pars, + extract, + extract_sparse_parts, + get_posterior_mean, + optimizing, + sampling, + stanc, + vb +) +importFrom(rstantools, + loo_R2, + nsamples +) +importFrom(stats, + cov2cor, + getInitial +) importFrom(survival,Surv) -importFrom(utils,capture.output) -importFrom(utils,head) -importFrom(utils,packageVersion) -importFrom(utils,tail) +importFrom(utils, + capture.output, + head, + packageVersion, + tail +) importMethodsFrom(rstan,summary) useDynLib(rstanarm, .registration = TRUE) diff --git a/R/stan_gamm4.R b/R/stan_gamm4.R index a6380c845..f593c585e 100644 --- a/R/stan_gamm4.R +++ b/R/stan_gamm4.R @@ -291,7 +291,7 @@ stan_gamm4 <- #' #' @return \code{plot_nonlinear} returns a ggplot object. #' -#' @importFrom ggplot2 aes_ aes_string facet_wrap ggplot geom_contour geom_line geom_ribbon labs scale_color_gradient2 +#' @importFrom ggplot2 aes aes_string facet_wrap ggplot geom_contour geom_line geom_ribbon labs scale_color_gradient2 #' plot_nonlinear <- function(x, smooths, ..., prob = 0.9, facet_args = list(), @@ -416,12 +416,12 @@ plot_nonlinear <- function(x, smooths, ..., facet_args[["strip.position"]] <- "left" on.exit(NULL) - ggplot(plot_data, aes_(x = ~ predictor)) + - geom_ribbon(aes_(ymin = ~ lower, ymax = ~ upper), + ggplot(plot_data, aes(x = predictor)) + + geom_ribbon(aes(ymin = lower, ymax = upper), fill = scheme[[1]], color = scheme[[2]], - alpha = alpha, size = size) + - geom_line(aes_(y = ~ middle), color = scheme[[5]], - size = 0.75 * size, lineend = "round") + + alpha = alpha, linewidth = size) + + geom_line(aes(y = middle), color = scheme[[5]], + linewidth = 0.75 * size, lineend = "round") + labs(y = NULL) + do.call(facet_wrap, facet_args) + bayesplot::theme_default() diff --git a/man/reexports.Rd b/man/reexports.Rd index eeb735c72..9577bbdd1 100644 --- a/man/reexports.Rd +++ b/man/reexports.Rd @@ -11,6 +11,6 @@ These objects are imported from other packages. Follow the links below to see their documentation. \describe{ - \item{survival}{\code{\link[survival]{Surv}}} + \item{survival}{\code{\link[survival:Surv]{Surv()}}} }} diff --git a/man/rstanarm-package.Rd b/man/rstanarm-package.Rd index acaae097f..94686a7fd 100644 --- a/man/rstanarm-package.Rd +++ b/man/rstanarm-package.Rd @@ -7,7 +7,7 @@ \title{Applied Regression Modeling via RStan} \description{ \if{html}{ - \figure{stanlogo.png}{options: width="50" alt="https://mc-stan.org/about/logo/"} + \figure{logo.svg}{options: width="50" alt="https://mc-stan.org/about/logo/"} \emph{Stan Development Team} } @@ -242,6 +242,7 @@ User-friendly Bayesian regression modeling: A tutorial with rstanarm and shinyst Authors: \itemize{ + \item Ben Goodrich \email{benjamin.goodrich@columbia.edu} \item Jonah Gabry \email{jgabry@gmail.com} } diff --git a/man/stan_betareg.Rd b/man/stan_betareg.Rd index c7a641ae0..6e707cd96 100644 --- a/man/stan_betareg.Rd +++ b/man/stan_betareg.Rd @@ -205,7 +205,7 @@ A \link[rstan:stanfit-class]{stanfit} object (or a slightly modified stanfit object) is returned if \code{stan_betareg.fit} is called directly. } \description{ -\if{html}{\figure{stanlogo.png}{options: width="25" alt="https://mc-stan.org/about/logo/"}} +\if{html}{\figure{logo.svg}{options: width="25" alt="https://mc-stan.org/about/logo/"}} Beta regression modeling with optional prior distributions for the coefficients, intercept, and auxiliary parameter \code{phi} (if applicable). } diff --git a/man/stan_biglm.Rd b/man/stan_biglm.Rd index 99b81bc6d..91608231a 100644 --- a/man/stan_biglm.Rd +++ b/man/stan_biglm.Rd @@ -139,7 +139,7 @@ The output of both \code{stan_biglm} and \code{stan_biglm.fit} is an \code{\link{posterior_predict}} cannot be used. } \description{ -\if{html}{\figure{stanlogo.png}{options: width="25" alt="https://mc-stan.org/about/logo/"}} +\if{html}{\figure{logo.svg}{options: width="25" alt="https://mc-stan.org/about/logo/"}} This is the same model as with \code{\link{stan_lm}} but it utilizes the output from \code{\link[biglm]{biglm}} in the \pkg{biglm} package in order to proceed when the data is too large to fit in memory. diff --git a/man/stan_clogit.Rd b/man/stan_clogit.Rd index 180fb7df5..5dfa25769 100644 --- a/man/stan_clogit.Rd +++ b/man/stan_clogit.Rd @@ -126,7 +126,7 @@ A \link[=stanreg-objects]{stanreg} object is returned for \code{stan_clogit}. } \description{ -\if{html}{\figure{stanlogo.png}{options: width="25" alt="https://mc-stan.org/about/logo/"}} +\if{html}{\figure{logo.svg}{options: width="25" alt="https://mc-stan.org/about/logo/"}} A model for case-control studies with optional prior distributions for the coefficients, intercept, and auxiliary parameters. } diff --git a/man/stan_gamm4.Rd b/man/stan_gamm4.Rd index 16434f825..9d1ea43d9 100644 --- a/man/stan_gamm4.Rd +++ b/man/stan_gamm4.Rd @@ -212,7 +212,7 @@ for \code{stan_gamm4}. \code{plot_nonlinear} returns a ggplot object. } \description{ -\if{html}{\figure{stanlogo.png}{options: width="25" alt="https://mc-stan.org/about/logo/"}} +\if{html}{\figure{logo.svg}{options: width="25" alt="https://mc-stan.org/about/logo/"}} Bayesian inference for GAMMs with flexible priors. } \details{ diff --git a/man/stan_glm.Rd b/man/stan_glm.Rd index 1577796fa..f334d82d2 100644 --- a/man/stan_glm.Rd +++ b/man/stan_glm.Rd @@ -290,7 +290,7 @@ A \link[rstan:stanfit-class]{stanfit} object (or a slightly modified stanfit object) is returned if \code{stan_glm.fit} is called directly. } \description{ -\if{html}{\figure{stanlogo.png}{options: width="25" alt="https://mc-stan.org/about/logo/"}} +\if{html}{\figure{logo.svg}{options: width="25" alt="https://mc-stan.org/about/logo/"}} Generalized linear modeling with optional prior distributions for the coefficients, intercept, and auxiliary parameters. } diff --git a/man/stan_glmer.Rd b/man/stan_glmer.Rd index e8c0d6dd9..2385291be 100644 --- a/man/stan_glmer.Rd +++ b/man/stan_glmer.Rd @@ -228,7 +228,7 @@ A list with classes \code{stanreg}, \code{glm}, \code{lm}, one row and one column (in which case it is just the group-level variance). } \description{ -\if{html}{\figure{stanlogo.png}{options: width="25" alt="https://mc-stan.org/about/logo/"}} +\if{html}{\figure{logo.svg}{options: width="25" alt="https://mc-stan.org/about/logo/"}} Bayesian inference for GLMs with group-specific coefficients that have unknown covariance matrices with flexible priors. } diff --git a/man/stan_jm.Rd b/man/stan_jm.Rd index 758f575d0..e8b779eab 100644 --- a/man/stan_jm.Rd +++ b/man/stan_jm.Rd @@ -352,7 +352,7 @@ turns off the iteration updates.} A \link[=stanreg-objects]{stanjm} object is returned. } \description{ -\if{html}{\figure{stanlogo.png}{options: width="25" alt="https://mc-stan.org/about/logo/"}} +\if{html}{\figure{logo.svg}{options: width="25" alt="https://mc-stan.org/about/logo/"}} Fits a shared parameter joint model for longitudinal and time-to-event (e.g. survival) data under a Bayesian framework using Stan. } diff --git a/man/stan_lm.Rd b/man/stan_lm.Rd index 8e2e25151..5c92c3cd4 100644 --- a/man/stan_lm.Rd +++ b/man/stan_lm.Rd @@ -151,7 +151,7 @@ A \link[rstan:stanfit-class]{stanfit} object (or a slightly modified stanfit object) is returned if \code{stan_lm.fit or stan_lm.wfit} is called directly. } \description{ -\if{html}{\figure{stanlogo.png}{options: width="25" alt="https://mc-stan.org/about/logo/"}} +\if{html}{\figure{logo.svg}{options: width="25" alt="https://mc-stan.org/about/logo/"}} Bayesian inference for linear modeling with regularizing priors on the model parameters that are driven by prior beliefs about \eqn{R^2}, the proportion of variance in the outcome attributable to the predictors. See diff --git a/man/stan_mvmer.Rd b/man/stan_mvmer.Rd index 78b7306d9..f6d015bdd 100644 --- a/man/stan_mvmer.Rd +++ b/man/stan_mvmer.Rd @@ -128,7 +128,7 @@ turns off the iteration updates.} A \link[=stanreg-objects]{stanmvreg} object is returned. } \description{ -\if{html}{\figure{stanlogo.png}{options: width="25" alt="https://mc-stan.org/about/logo/"}} +\if{html}{\figure{logo.svg}{options: width="25" alt="https://mc-stan.org/about/logo/"}} Bayesian inference for multivariate GLMs with group-specific coefficients that are assumed to be correlated across the GLM submodels. } diff --git a/man/stan_nlmer.Rd b/man/stan_nlmer.Rd index 866757f46..3d8681c5e 100644 --- a/man/stan_nlmer.Rd +++ b/man/stan_nlmer.Rd @@ -149,7 +149,7 @@ A \link[=stanreg-objects]{stanreg} object is returned for \code{stan_nlmer}. } \description{ -\if{html}{\figure{stanlogo.png}{options: width="25" alt="https://mc-stan.org/about/logo/"}} +\if{html}{\figure{logo.svg}{options: width="25" alt="https://mc-stan.org/about/logo/"}} Bayesian inference for NLMMs with group-specific coefficients that have unknown covariance matrices with flexible priors. } diff --git a/man/stan_polr.Rd b/man/stan_polr.Rd index 53e140a36..6a2d6d80c 100644 --- a/man/stan_polr.Rd +++ b/man/stan_polr.Rd @@ -127,7 +127,7 @@ A \link[rstan:stanfit-class]{stanfit} object (or a slightly modified stanfit object) is returned if \code{stan_polr.fit} is called directly. } \description{ -\if{html}{\figure{stanlogo.png}{options: width="25" alt="https://mc-stan.org/about/logo/"}} +\if{html}{\figure{logo.svg}{options: width="25" alt="https://mc-stan.org/about/logo/"}} Bayesian inference for ordinal (or binary) regression models under a proportional odds assumption. } From 3478f7faa172b8955b663d7832ae59381e2c31be Mon Sep 17 00:00:00 2001 From: Andrew Johnson Date: Mon, 14 Sep 2026 10:39:52 +0800 Subject: [PATCH 08/19] Test run --- .github/workflows/R-CMD-check.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/R-CMD-check.yaml b/.github/workflows/R-CMD-check.yaml index 98cb8517e..01489fe5d 100644 --- a/.github/workflows/R-CMD-check.yaml +++ b/.github/workflows/R-CMD-check.yaml @@ -4,6 +4,7 @@ on: push: branches: - master + - ci-fixes pull_request: branches: - master From 1d530deac93632849c3cb9907ab95ed366b67520 Mon Sep 17 00:00:00 2001 From: Andrew Johnson Date: Mon, 14 Sep 2026 10:43:06 +0800 Subject: [PATCH 09/19] Missed rcmdcheck in workflow --- .github/workflows/R-CMD-check.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/R-CMD-check.yaml b/.github/workflows/R-CMD-check.yaml index 01489fe5d..a3611c0e9 100644 --- a/.github/workflows/R-CMD-check.yaml +++ b/.github/workflows/R-CMD-check.yaml @@ -50,5 +50,6 @@ jobs: - uses: r-lib/actions/setup-r-dependencies@v2 with: dependencies: "TRUE" + extra-packages: any::rcmdcheck - uses: r-lib/actions/check-r-package@v2 From 4e264fa0403b6ecf99d22fa17f46cae829a96c34 Mon Sep 17 00:00:00 2001 From: Andrew Johnson Date: Mon, 14 Sep 2026 11:24:53 +0800 Subject: [PATCH 10/19] Fix grouping-factor consistency --- R/jm_data_block.R | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/R/jm_data_block.R b/R/jm_data_block.R index 113306016..828651cce 100644 --- a/R/jm_data_block.R +++ b/R/jm_data_block.R @@ -857,7 +857,7 @@ get_common_cnms <- function(x, stub = "Long") { if (nm %in% nms[[m]]) paste0(stub, m, "|", x[[m]][[nm]]))) }) names(cnms) <- unique_nms - cnms + cnms[order(names(cnms))] } # Function to return a single list with the factor levels for each @@ -2097,4 +2097,3 @@ handle_weights <- function(mod_stuff, weights, id_var) { wts } - From 096b9097b6ed6e3e8a049ebd0b75eab6469ee5d5 Mon Sep 17 00:00:00 2001 From: Andrew Johnson Date: Mon, 14 Sep 2026 11:55:17 +0800 Subject: [PATCH 11/19] Update test iterations --- tests/testthat/test_stan_clogit.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/testthat/test_stan_clogit.R b/tests/testthat/test_stan_clogit.R index df071e034..2f719bffa 100644 --- a/tests/testthat/test_stan_clogit.R +++ b/tests/testthat/test_stan_clogit.R @@ -20,7 +20,7 @@ suppressPackageStartupMessages(library(rstanarm)) SEED <- 123 -ITER <- 100 +ITER <- 200 CHAINS <- 2 CORES <- 1 REFRESH <- 0 From 8a443983914d7d2b8246595f5b968f6b0a6f0551 Mon Sep 17 00:00:00 2001 From: Andrew Johnson Date: Mon, 14 Sep 2026 13:07:05 +0800 Subject: [PATCH 12/19] Fix unused variable NOTEs --- R/stan_gamm4.R | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/R/stan_gamm4.R b/R/stan_gamm4.R index f593c585e..6608f7ddc 100644 --- a/R/stan_gamm4.R +++ b/R/stan_gamm4.R @@ -301,6 +301,7 @@ plot_nonlinear <- function(x, smooths, ..., stop("Plot only available for models fit using the stan_gamm4 function.") on.exit(message("try plot(x$jam) instead")) scheme <- bayesplot::color_scheme_get() + predictor <- lower <- upper <- middle <- y <- z <- NULL XZ <- x$x XZ <- XZ[,!grepl("_NEW_", colnames(XZ), fixed = TRUE)] @@ -354,7 +355,7 @@ plot_nonlinear <- function(x, smooths, ..., xz <- XZ[, grepl(labels, colnames(XZ), fixed = TRUE), drop = FALSE] plot_data$z <- apply(linear_predictor.matrix(b, xz), 2, FUN = median) return( - ggplot(plot_data, aes_(x = ~x, y = ~y, z = ~z)) + + ggplot(plot_data, aes(x = x, y = y, z = z)) + geom_contour(aes_string(color = "..level.."), size = size/2) + labs(x = xnames[1], y = xnames[2]) + scale_color_gradient2(low = scheme[[1]], From 8ae0e29d4d12540d6dc2b040428ece411b92e5b8 Mon Sep 17 00:00:00 2001 From: Andrew Johnson Date: Mon, 14 Sep 2026 14:05:30 +0800 Subject: [PATCH 13/19] Update to testthat edition 3, run tests in parallel --- DESCRIPTION | 4 +- tests/testthat/helper.R | 15 +++--- tests/testthat/test_loo.R | 16 +++---- tests/testthat/test_methods.R | 31 +++++------- tests/testthat/test_misc.R | 34 +++++++------ tests/testthat/test_plots.R | 6 +-- tests/testthat/test_posterior_predict.R | 12 ++--- tests/testthat/test_pp_check.R | 1 - tests/testthat/test_pp_validate.R | 1 - tests/testthat/test_predict.R | 63 ++++++++++++------------- tests/testthat/test_stan_betareg.R | 15 +++--- tests/testthat/test_stan_clogit.R | 4 +- tests/testthat/test_stan_functions.R | 46 ++++++------------ tests/testthat/test_stan_glm.R | 38 +++++++-------- tests/testthat/test_stan_glmer.R | 30 +++++------- tests/testthat/test_stan_jm.R | 7 ++- tests/testthat/test_stan_lm.R | 14 +++--- tests/testthat/test_stan_mvmer.R | 25 +++++----- tests/testthat/test_stan_nlmer.R | 4 +- tests/testthat/test_stan_polr.R | 8 ++-- 20 files changed, 167 insertions(+), 207 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index c80c2b622..93243271a 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -63,7 +63,7 @@ Suggests: rmarkdown, roxygen2, StanHeaders (>= 2.21.0), - testthat (>= 1.0.2), + testthat (>= 3.0.0), gamm4, shiny, V8 @@ -77,3 +77,5 @@ NeedsCompilation: yes URL: https://mc-stan.org/rstanarm/, https://discourse.mc-stan.org BugReports: https://github.com/stan-dev/rstanarm/issues Config/roxygen2/version: 8.1.0 +Config/testthat/edition: 3 +Config/testthat/parallel: true diff --git a/tests/testthat/helper.R b/tests/testthat/helper.R index a3974c30b..bd1a59e39 100644 --- a/tests/testthat/helper.R +++ b/tests/testthat/helper.R @@ -47,7 +47,7 @@ check_for_pp_errors <- function(fit, data = NULL, offset = NULL) { expect_equal(dim(yrep6), c(3, 5)) expect_error(posterior_predict(fit, draws = nsims + 1), - regexep = "posterior sample size is only") + regexp = "'draws' should be <= posterior sample size") } @@ -69,15 +69,16 @@ expect_equivalent_loo <- function(fit) { if (fit$stan_function != "stan_clogit") { ll <- log_lik(fit) - r_eff <- loo::relative_eff(exp(ll), chain_id = rstanarm:::chain_id_for_loo(fit)) + r_eff <- suppressWarnings(loo::relative_eff( + exp(ll), chain_id = rstanarm:::chain_id_for_loo(fit))) l2 <- suppressWarnings(loo(ll, r_eff = r_eff, cores = LOO.CORES)) expect_equal(l$estimates, l2$estimates) - expect_equivalent(w, suppressWarnings(waic(ll))) + expect_equal(w, suppressWarnings(waic(ll)), ignore_attr = TRUE) } } expect_gg <- function(x, info = NULL, label = NULL) { - testthat::expect_is(x, "ggplot", info = info, label = label) + testthat::expect_true(inherits(x, "ggplot"), info = info, label = label) invisible(ggplot2::ggplot_build(x)) } @@ -96,9 +97,9 @@ expect_identical_sorted_stanmats <- function(x, y) { expect_linpred_equal <- function(object, tol = 0.1) { linpred <- posterior_linpred(object) - expect_equal(apply(linpred, 2, median), object$linear.predictors, - tolerance = tol, - check.attributes = FALSE) + expect_equal(apply(linpred, 2, median), object$linear.predictors, + tolerance = tol, + ignore_attr = TRUE) } expect_matrix <- function(x) expect_true(is.matrix(x)) diff --git a/tests/testthat/test_loo.R b/tests/testthat/test_loo.R index d07e0ac25..891aa1856 100644 --- a/tests/testthat/test_loo.R +++ b/tests/testthat/test_loo.R @@ -28,7 +28,7 @@ if (!exists("example_model")) { } # loo and waic ------------------------------------------------------------ -context("loo and waic") + # These tests just check that the loo.stanreg method (which calls loo.function # method) results are identical to the loo.matrix results. Since for these tests @@ -55,7 +55,7 @@ expect_equivalent_loo <- function(fit) { r <- loo::relative_eff(exp(llik), chain_id = rstanarm:::chain_id_for_loo(fit)) l2 <- suppressWarnings(loo(llik, r_eff = r, cores = LOO.CORES)) expect_equal(l$estimates, l2$estimates) - expect_equivalent(w, suppressWarnings(waic(log_lik(fit)))) + expect_equal(w, suppressWarnings(waic(log_lik(fit))), ignore_attr = TRUE) } test_that("loo & waic do something for non mcmc models", { @@ -93,7 +93,7 @@ test_that("loo can handle empty interaction levels", { # loo with refitting ------------------------------------------------------ -context("loo then refitting") + test_that("loo issues errors/warnings", { expect_warning(loo(example_model, cores = LOO.CORES, k_threshold = 2), @@ -136,7 +136,7 @@ test_that("loo with k_threshold works for edge case(s)", { # kfold ------------------------------------------------------------------- -context("kfold") + test_that("kfold does not throw an error for non mcmc models", { SW(fito <- stan_glm(mpg ~ wt, data = mtcars, algorithm = "optimizing", @@ -274,7 +274,7 @@ test_that("loo_compare works", { expect_output(print(comp1_detail), "Model formulas") # equivalent to stanreg_list method - expect_equivalent(comp2, loo_compare(stanreg_list(fit1, fit2, fit3))) + expect_equal(comp2, loo_compare(stanreg_list(fit1, fit2, fit3)), ignore_attr = TRUE) # for kfold expect_warning(comp3 <- loo_compare(k1, k2, k3), @@ -286,7 +286,7 @@ test_that("loo_compare works", { # helpers ----------------------------------------------------------------- -context("loo and waic helpers") + test_that("kfold_and_reloo_data works", { f <- rstanarm:::kfold_and_reloo_data @@ -296,12 +296,12 @@ test_that("kfold_and_reloo_data works", { # if 'data' arg not originally specified when fitting the model y <- rnorm(40) SW(fit <- stan_glm(y ~ 1, iter = ITER, chains = CHAINS, refresh = 0)) - expect_equivalent(f(fit), model.frame(fit)) + expect_equal(f(fit), model.frame(fit), ignore_attr = TRUE) # if 'subset' arg specified when fitting the model SW(fit2 <- stan_glm(mpg ~ wt, data = mtcars, subset = gear != 5, iter = ITER, chains = CHAINS, refresh = 0)) - expect_equivalent(f(fit2), subset(mtcars[mtcars$gear != 5, c("mpg", "wt")])) + expect_equal(f(fit2), subset(mtcars[mtcars$gear != 5, c("mpg", "wt")]), ignore_attr = TRUE) }) test_that(".weighted works", { diff --git a/tests/testthat/test_methods.R b/tests/testthat/test_methods.R index 2a0090bf2..f8a2f83cd 100644 --- a/tests/testthat/test_methods.R +++ b/tests/testthat/test_methods.R @@ -84,8 +84,6 @@ check_sizes <- function(x,y) { } -context("methods for stanreg objects") - # extractors -------------------------------------------------------------- test_that("stanreg extractor methods work properly", { @@ -211,9 +209,9 @@ test_that("log_lik method works", { llmat[i, ] <- dnorm(y, mean = eta[, i], sd = sigma[i], log = TRUE) llmat_new[i, ] <- dnorm(y_new, mean = eta_new[, i], sd = sigma[i], log = TRUE) } - expect_equal(log_lik(stan_glm1), llmat, check.attributes = FALSE) + expect_equal(log_lik(stan_glm1), llmat, ignore_attr = TRUE) nd <- data.frame(mpg = y_new, wt = x_new[, 2], cyl = x_new[, 3]) - expect_equal(log_lik(stan_glm1, newdata = nd), llmat_new, check.attributes = FALSE) + expect_equal(log_lik(stan_glm1, newdata = nd), llmat_new, ignore_attr = TRUE) # make sure log_lik with newdata equals log_lik if newdata is the same as the @@ -472,7 +470,7 @@ test_that("as.matrix and as.array errors & warnings", { # terms, formula, model.frame, model.matrix, update methods ----------------- -context("model.frame methods") + test_that("model.frame works properly", { expect_identical(model.frame(stan_glm1), model.frame(glm1)) expect_identical(model.frame(stan_glm_opt1), model.frame(glm1)) @@ -488,7 +486,6 @@ test_that("model.frame works properly", { expect_identical(model.frame(stan_betareg1), model.frame(betareg1)) }) -context("terms methods") test_that("terms works properly", { expect_identical(terms(stan_glm1), terms(glm1)) expect_identical(terms(stan_glm_opt1), terms(glm1)) @@ -501,21 +498,20 @@ test_that("terms works properly", { expect_identical(terms(stan_lmer2, fixed.only = TRUE), terms(lmer2, fixed.only = TRUE)) expect_equal(terms(stan_lmer1, random.only = TRUE), - terms(lmer1, random.only = TRUE)) + terms(lmer1, random.only = TRUE), ignore_formula_env = TRUE) expect_equal(terms(stan_lmer2, random.only = TRUE), - terms(lmer2, random.only = TRUE)) + terms(lmer2, random.only = TRUE), ignore_formula_env = TRUE) expect_error(terms(stan_lmer1, fixed.only = TRUE, random.only = TRUE), regexp = "can't both be TRUE") expect_identical(terms(stan_betareg1), terms(betareg1)) }) -context("formula methods") test_that("formula works properly", { expect_identical(formula(stan_glm1), formula(glm1)) expect_identical(formula(stan_glm_opt1), formula(glm1)) expect_identical(formula(stan_glm_vb1), formula(glm1)) expect_identical(formula(stan_betareg1), formula(betareg1)) - expect_equal(terms(stan_polr1), formula(polr1)) + expect_equal(formula(stan_polr1), formula(terms(polr1))) expect_identical(formula(stan_lmer1), formula(lmer1)) expect_identical(formula(stan_lmer2), formula(lmer2)) expect_identical(formula(stan_lmer1, fixed.only = TRUE), @@ -523,9 +519,9 @@ test_that("formula works properly", { expect_identical(formula(stan_lmer2, fixed.only = TRUE), formula(lmer2, fixed.only = TRUE)) expect_equal(formula(stan_lmer1, random.only = TRUE), - formula(lmer1, random.only = TRUE)) + formula(lmer1, random.only = TRUE), ignore_formula_env = TRUE) expect_equal(formula(stan_lmer2, random.only = TRUE), - formula(lmer2, random.only = TRUE)) + formula(lmer2, random.only = TRUE), ignore_formula_env = TRUE) expect_error(formula(stan_lmer1, fixed.only = TRUE, random.only = TRUE), regexp = "can't both be TRUE") @@ -533,12 +529,11 @@ test_that("formula works properly", { tmp <- stan_lmer1 tmp$formula <- NULL attr(tmp$glmod$fr, "formula") <- NULL - expect_equal(formula(tmp), formula(lmer1)) + expect_equal(formula(tmp), formula(lmer1), ignore_formula_env = TRUE) tmp$call <- NULL expect_error(formula(tmp), regexp = "can't find formula", ignore.case = TRUE) }) -context("update methods") test_that("update works properly", { pss <- rstanarm:::posterior_sample_size @@ -550,7 +545,7 @@ test_that("update works properly", { expect_equal(pss(fit3), 4 * pss(stan_betareg1)) call_only <- update(fit1, evaluate = FALSE) - expect_is(call_only, "call") + expect_type(call_only, "language") expect_identical(call_only, getCall(fit1)) # expect_error(fit2 <- update(fit2, algorithm = "optimizing"), @@ -563,7 +558,7 @@ test_that("update works properly", { # print and summary ------------------------------------------------------- -context("print and summary methods") + test_that("print and summary methods ok for mcmc and vb", { expect_output(print(example_model, digits = 2), "stan_glmer") expect_output(print(example_model, digits = 2), "Error terms") @@ -718,7 +713,7 @@ test_that("prior_summary returns correctly named list", { # predictive_error,predictive_interval ------------------------------------ -context("predictive error and interval methods") + test_that("predictive_error works", { expect_error(predictive_error(stan_glm1, draws = 100), "'draws' should be <= posterior sample size") @@ -816,7 +811,7 @@ test_that("stan*_list functions throw proper errors", { test_that("stanreg_list works", { list1 <- stanreg_list(stan_lmer1, stan_lmer2) expect_named(list1, c("stan_lmer1", "stan_lmer2")) - expect_equivalent(attr(list1, "families"), c("gaussian", "gaussian")) + expect_equal(attr(list1, "families"), c("gaussian", "gaussian"), ignore_attr = TRUE) expect_identical(list1$stan_lmer1, stan_lmer1) expect_identical(list1$stan_lmer2, stan_lmer2) }) diff --git a/tests/testthat/test_misc.R b/tests/testthat/test_misc.R index 45ebe2075..ea8e68ee2 100644 --- a/tests/testthat/test_misc.R +++ b/tests/testthat/test_misc.R @@ -26,7 +26,6 @@ if (!exists("example_model")) { example_model <- run_example_model() } -context("helper functions") test_that("nlist works", { nlist <- rstanarm:::nlist @@ -155,7 +154,7 @@ test_that("validate_offset works", { SW(fito <- stan_glm(mpg ~ wt, data = mtcars, algorithm = "optimizing", seed = SEED)) SW(fito2 <- update(fito, offset = rep(5, nrow(mtcars)))) - expect_equal(coef(fito)[1], 5 + coef(fito2)[1], tol = 0.2) + expect_equal(coef(fito)[1], 5 + coef(fito2)[1], tolerance = 0.2) }) test_that("validate_family works", { @@ -246,12 +245,12 @@ test_that("linear_predictor methods work", { vec_ans <- seq(0, 1.5, 0.5) mat_ans <- rbind(vec_ans, 1:4) offset <- rep(2, nrow(x)) - expect_equivalent(linpred_vec(bvec, x), vec_ans) - expect_equivalent(linpred_vec(bvec, x, offset = NULL), vec_ans) - expect_equivalent(linpred_vec(bvec, x, offset), vec_ans + offset) - expect_equivalent(linpred_mat(bmat, x), mat_ans) - expect_equivalent(linpred_mat(bmat, x, offset = NULL), mat_ans) - expect_equivalent(linpred_mat(bmat, x, offset), mat_ans + offset) + expect_equal(linpred_vec(bvec, x), vec_ans, ignore_attr = TRUE) + expect_equal(linpred_vec(bvec, x, offset = NULL), vec_ans, ignore_attr = TRUE) + expect_equal(linpred_vec(bvec, x, offset), vec_ans + offset, ignore_attr = TRUE) + expect_equal(linpred_mat(bmat, x), mat_ans, ignore_attr = TRUE) + expect_equal(linpred_mat(bmat, x, offset = NULL), mat_ans, ignore_attr = TRUE) + expect_equal(linpred_mat(bmat, x, offset), mat_ans + offset, ignore_attr = TRUE) }) # fits to use in multiple calls to test_that below @@ -322,14 +321,14 @@ test_that("is.mer works", { test_that("get_x, get_y, get_z work", { x_ans <- cbind("(Intercept)" = 1, wt = mtcars$wt) y_ans <- mtcars$mpg - expect_equivalent(get_x(fit), x_ans) - expect_equivalent(get_y(fit), y_ans) + expect_equal(get_x(fit), x_ans, ignore_attr = TRUE) + expect_equal(get_y(fit), y_ans, ignore_attr = TRUE) expect_error(get_z(fit), "no applicable method") z_ans2 <- model.matrix(mpg ~ -1 + factor(cyl), data = mtcars) - expect_equivalent(get_x(fit2), x_ans) - expect_equivalent(get_y(fit2), y_ans) - expect_equivalent(as.matrix(get_z(fit2)), z_ans2) + expect_equal(get_x(fit2), x_ans, ignore_attr = TRUE) + expect_equal(get_y(fit2), y_ans, ignore_attr = TRUE) + expect_equal(as.matrix(get_z(fit2)), z_ans2, ignore_attr = TRUE) SW( fit3 <- stan_glmer(mpg ~ wt + (1 + wt|cyl), data = mtcars, refresh = 0, @@ -338,9 +337,9 @@ test_that("get_x, get_y, get_z work", { z_ans3 <- mat.or.vec(nr = nrow(mtcars), nc = 6) z_ans3[, c(1, 3, 5)] <- model.matrix(mpg ~ 0 + factor(cyl), data = mtcars) z_ans3[, c(2, 4, 6)] <- model.matrix(mpg ~ 0 + wt:factor(cyl), data = mtcars) - expect_equivalent(get_x(fit3), x_ans) - expect_equivalent(get_y(fit3), y_ans) - expect_equivalent(as.matrix(get_z(fit3)), z_ans3) + expect_equal(get_x(fit3), x_ans, ignore_attr = TRUE) + expect_equal(get_y(fit3), y_ans, ignore_attr = TRUE) + expect_equal(as.matrix(get_z(fit3)), z_ans3, ignore_attr = TRUE) }) test_that("set_sampling_args works", { @@ -434,7 +433,7 @@ test_that("collect_pars and grep_for_pars work", { expect_identical(grep_for_pars(fit, "herd:[3,5]"), all_varying[c(3,5)]) expect_identical(grep_for_pars(fit, "herd:[3-5]"), all_varying[3:5]) expect_error(grep_for_pars(fit, "NOT A PARAMETER"), regexp = "No matches") - expect_error(grep_for_pars(fit, "b[")) + expect_error(suppressWarnings(grep_for_pars(fit, "b["))) expect_identical(collect_pars(fit, regex_pars = "period"), all_period) expect_identical(collect_pars(fit, pars = "size", regex_pars = "period"), @@ -495,4 +494,3 @@ test_that("validate_newdata works", { newd$period[3] <- NA expect_error(validate_newdata(fit, newdata = newd), "NAs are not allowed") }) - diff --git a/tests/testthat/test_plots.R b/tests/testthat/test_plots.R index 2ad660c24..a2338acdf 100644 --- a/tests/testthat/test_plots.R +++ b/tests/testthat/test_plots.R @@ -30,7 +30,7 @@ SW(fito <- stan_glm(mpg ~ ., data = mtcars, algorithm = "optimizing", seed = SEE SW(fitvb <- update(fito, algorithm = "meanfield")) # plot.stanreg ------------------------------------------------------------ -context("plot.stanreg") + test_that("plot.stanreg errors if chains = 1 but needs multiple", { multiple_chain_plots <- c("trace_highlight", "hist_by_chain", @@ -119,7 +119,7 @@ test_that("plot.stanreg ok for vb", { # pairs.stanreg ----------------------------------------------------------- -context("pairs.stanreg") + test_that("pairs method ok", { expect_silent(pairs(fit, pars = c("period2", "log-posterior"))) expect_silent(pairs(fit, pars = "b[(Intercept) herd:15]", regex_pars = "Sigma")) @@ -132,7 +132,7 @@ test_that("pairs method ok", { # posterior_vs_prior ------------------------------------------------------ -context("posterior_vs_prior") + test_that("posterior_vs_prior ok", { SW(p1 <- posterior_vs_prior(fit, pars = "beta")) expect_gg(p1) diff --git a/tests/testthat/test_posterior_predict.R b/tests/testthat/test_posterior_predict.R index f7a3b35bb..36ac76886 100644 --- a/tests/testthat/test_posterior_predict.R +++ b/tests/testthat/test_posterior_predict.R @@ -48,7 +48,7 @@ test_that("posterior_predict errors if draws > posterior sample size", { }) # VB ---------------------------------------------------------------------- -context("posterior_predict ok for vb") + test_that("silent for vb", { SW(fit1 <- stan_glm(mpg ~ wt + cyl + am, data = mtcars, algorithm = "meanfield", refresh = 0)) @@ -108,8 +108,8 @@ test_that("lme4 tests work similarly", { size = 20, incidence = 0)) p6 <- posterior_predict(sfit, nd3, allow.new.levels = TRUE, seed = SEED) - expect_equal(colMeans(p3), colMeans(p6[, 1:ncol(p3)]), tol = 0.05) - expect_equal(apply(p3, 2, sd), apply(p6[, 1:ncol(p3)], 2, sd), tol = 0.05) + expect_equal(colMeans(p3), colMeans(p6[, 1:ncol(p3)]), tolerance = 0.05) + expect_equal(apply(p3, 2, sd), apply(p6[, 1:ncol(p3)], 2, sd), tolerance = 0.05) # multiple groups lfit <- lmer(diameter ~ (1|plate) + (1|sample), Penicillin) @@ -129,7 +129,7 @@ test_that("lme4 tests work similarly", { # spaces in factor levels ------------------------------------------------- -context("posterior_linpred/predict with spaces in factor levels") + test_that("posterior_linpred not sensitive to spaces in factor levels", { df <- data.frame( @@ -175,7 +175,7 @@ test_that("posterior_linpred not sensitive to spaces in factor levels", { ) ans2 <- posterior_linpred(fit1, newdata = nd2) # should be same as ans1 except for cols 3:4 with new levels - expect_equal(ans2[, 1:2], ans1, check.attributes = FALSE) + expect_equal(ans2[, 1:2], ans1, ignore_attr = TRUE) expect_equal(ans2, posterior_linpred(fit2, newdata = nd2)) expect_equal(ans2, posterior_linpred(fit3, newdata = nd2)) expect_equal(ans2, posterior_linpred(fit4, newdata = nd2)) @@ -256,7 +256,7 @@ test_that("posterior_predict can handle empty interaction levels", { # helper functions -------------------------------------------------------- -context("posterior_predict helper functions") + test_that("pp_binomial_trials works", { ppbt <- rstanarm:::pp_binomial_trials diff --git a/tests/testthat/test_pp_check.R b/tests/testthat/test_pp_check.R index b2c9720a9..72479a228 100644 --- a/tests/testthat/test_pp_check.R +++ b/tests/testthat/test_pp_check.R @@ -15,7 +15,6 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -context("pp_check") suppressPackageStartupMessages(library(rstanarm)) SEED <- 123 diff --git a/tests/testthat/test_pp_validate.R b/tests/testthat/test_pp_validate.R index 3e1a9f8cb..5d01d771d 100644 --- a/tests/testthat/test_pp_validate.R +++ b/tests/testthat/test_pp_validate.R @@ -23,7 +23,6 @@ if (!exists("example_model")) { example_model <- run_example_model() } -context("pp_validate") test_that("pp_validate throws correct errors", { expect_error(pp_validate(example_model$stanfit), "not a stanreg object") expect_error(pp_validate(example_model, nreps = 1), "at least 2") diff --git a/tests/testthat/test_predict.R b/tests/testthat/test_predict.R index b9ae67c39..5746a8384 100644 --- a/tests/testthat/test_predict.R +++ b/tests/testthat/test_predict.R @@ -32,7 +32,6 @@ plink <- function(fit, nd = NULL, sef = TRUE) presp <- function(fit, nd = NULL, sef = TRUE) predict(fit, newdata = nd, type = "response", se.fit = sef) -context("predict") test_that("predict recommends posterior_predict for glmer models", { expect_error(predict(example_model), @@ -60,11 +59,11 @@ test_that("predict ok for binomial", { pg <- plink(glmfit) ps <- plink(stanfit) pso <- plink(stanfit_opt) - expect_equal(pg$fit, ps$fit, tol = 0.1) - expect_equal(pg$fit, pso$fit, tol = 0.05) - expect_equal(pg$se.fit, ps$se.fit, tol = 0.2) - expect_equal(pg$se.fit, pso$se.fit, tol = 0.1) - expect_equal(presp(glmfit)[1:2], presp(stanfit_opt), tol = 0.05) + expect_equal(pg$fit, ps$fit, tolerance = 0.1) + expect_equal(pg$fit, pso$fit, tolerance = 0.05) + expect_equal(pg$se.fit, ps$se.fit, tolerance = 0.2) + expect_equal(pg$se.fit, pso$se.fit, tolerance = 0.1) + expect_equal(presp(glmfit)[1:2], presp(stanfit_opt), tolerance = 0.05) ld <- seq(0, 5, 0.1) newd <- data.frame(ldose = ld, sex = factor(rep("M", length(ld)), @@ -73,10 +72,10 @@ test_that("predict ok for binomial", { ps <- plink(stanfit, newd) pso <- plink(stanfit_opt, newd) # expect_equal(pg$fit, ps$fit, tol = 0.05) - expect_equal(pg$fit, pso$fit, tol = 0.05) - expect_equal(pg$se.fit, ps$se.fit, tol = 0.2) - expect_equal(pg$se.fit, pso$se.fit, tol = 0.1) - expect_equal(presp(glmfit, newd)[1:2], presp(stanfit_opt, newd), tol = 0.1) + expect_equal(pg$fit, pso$fit, tolerance = 0.05) + expect_equal(pg$se.fit, ps$se.fit, tolerance = 0.2) + expect_equal(pg$se.fit, pso$se.fit, tolerance = 0.1) + expect_equal(presp(glmfit, newd)[1:2], presp(stanfit_opt, newd), tolerance = 0.1) }) test_that("predict ok for gaussian", { @@ -93,21 +92,21 @@ test_that("predict ok for gaussian", { pg <- plink(glmfit) ps <- plink(stanfit) pso <- plink(stanfit_opt) - expect_equal(pg$fit, ps$fit, tol = 0.05) - expect_equal(pg$fit, pso$fit, tol = 0.05) - expect_equal(pg$se.fit, ps$se.fit, tol = 0.3) - expect_equal(pg$se.fit, pso$se.fit, tol = 0.1) - expect_equal(presp(glmfit)[1:2], presp(stanfit_opt), tol = 0.1) + expect_equal(pg$fit, ps$fit, tolerance = 0.05) + expect_equal(pg$fit, pso$fit, tolerance = 0.05) + expect_equal(pg$se.fit, ps$se.fit, tolerance = 0.3) + expect_equal(pg$se.fit, pso$se.fit, tolerance = 0.1) + expect_equal(presp(glmfit)[1:2], presp(stanfit_opt), tolerance = 0.1) newd <- data.frame(wt = c(1,5)) pg <- plink(glmfit, newd) ps <- plink(stanfit, newd) pso <- plink(stanfit_opt, newd) - expect_equal(pg$fit, ps$fit, tol = 0.05) - expect_equal(pg$fit, pso$fit, tol = 0.05) - expect_equal(pg$se.fit, ps$se.fit, tol = 0.3) - expect_equal(pg$se.fit, pso$se.fit, tol = 0.1) - expect_equal(presp(glmfit, newd)[1:2], presp(stanfit_opt, newd), tol = 0.1) + expect_equal(pg$fit, ps$fit, tolerance = 0.05) + expect_equal(pg$fit, pso$fit, tolerance = 0.05) + expect_equal(pg$se.fit, ps$se.fit, tolerance = 0.3) + expect_equal(pg$se.fit, pso$se.fit, tolerance = 0.1) + expect_equal(presp(glmfit, newd)[1:2], presp(stanfit_opt, newd), tolerance = 0.1) }) test_that("predict ok for Poisson", { @@ -124,22 +123,22 @@ test_that("predict ok for Poisson", { pg <- plink(glmfit) ps <- plink(stanfit) pso <- plink(stanfit_opt) - expect_equal(pg$fit, ps$fit, tol = 0.05) - expect_equal(pg$fit, pso$fit, tol = 0.05) - expect_equal(pg$se.fit, ps$se.fit, tol = 0.1) - expect_equal(pg$se.fit, pso$se.fit, tol = 0.1) - expect_equal(presp(glmfit)[1:2], presp(stanfit_opt), tol = 0.1) + expect_equal(pg$fit, ps$fit, tolerance = 0.05) + expect_equal(pg$fit, pso$fit, tolerance = 0.05) + expect_equal(pg$se.fit, ps$se.fit, tolerance = 0.1) + expect_equal(pg$se.fit, pso$se.fit, tolerance = 0.1) + expect_equal(presp(glmfit)[1:2], presp(stanfit_opt), tolerance = 0.1) - expect_equal(plink(stanfit, sef = FALSE), plink(glmfit, sef = FALSE), tol = 0.05) - expect_equal(presp(stanfit, sef = FALSE), presp(glmfit, sef = FALSE), tol = 0.05) + expect_equal(plink(stanfit, sef = FALSE), plink(glmfit, sef = FALSE), tolerance = 0.05) + expect_equal(presp(stanfit, sef = FALSE), presp(glmfit, sef = FALSE), tolerance = 0.05) newd <- dat[1:2, ] pg <- plink(glmfit, newd) ps <- plink(stanfit, newd) pso <- plink(stanfit_opt, newd) - expect_equal(pg$fit, ps$fit, tol = 0.05) - expect_equal(pg$fit, pso$fit, tol = 0.05) - expect_equal(pg$se.fit, ps$se.fit, tol = 0.1) - expect_equal(pg$se.fit, pso$se.fit, tol = 0.1) - expect_equal(presp(glmfit, newd)[1:2], presp(stanfit_opt, newd), tol = 0.1) + expect_equal(pg$fit, ps$fit, tolerance = 0.05) + expect_equal(pg$fit, pso$fit, tolerance = 0.05) + expect_equal(pg$se.fit, ps$se.fit, tolerance = 0.1) + expect_equal(pg$se.fit, pso$se.fit, tolerance = 0.1) + expect_equal(presp(glmfit, newd)[1:2], presp(stanfit_opt, newd), tolerance = 0.1) }) diff --git a/tests/testthat/test_stan_betareg.R b/tests/testthat/test_stan_betareg.R index ccc964f26..f48c26bf6 100644 --- a/tests/testthat/test_stan_betareg.R +++ b/tests/testthat/test_stan_betareg.R @@ -22,8 +22,7 @@ if (.Platform$OS.type != "windows" && require(betareg)) { ITER <- 10 CHAINS <- 2 REFRESH <- 0 - - context("stan_betareg") + simple_betareg_data <- function(N, draw_z = FALSE) { x <- rnorm(N, 2, 1) @@ -80,7 +79,7 @@ if (.Platform$OS.type != "windows" && require(betareg)) { expect_stanreg(fit) val <- coef(fit) ans <- coef(betareg(y ~ x, link = link1[i], data = dat)) - expect_equal(val, ans, tol = 0.1, info = link1[i]) + expect_equal(val, ans, tolerance = 0.1, info = link1[i]) } }) @@ -92,7 +91,7 @@ if (.Platform$OS.type != "windows" && require(betareg)) { expect_stanreg(fit) val <- coef(fit) ans <- coef(betareg(y ~ x + z, link = "logit", data = dat)) - expect_equal(val, ans, tol = 0.1, info = "logit") + expect_equal(val, ans, tolerance = 0.1, info = "logit") }) test_that("stan_betareg works with QR = TRUE and algorithm = 'sampling'", { @@ -103,7 +102,7 @@ if (.Platform$OS.type != "windows" && require(betareg)) { expect_stanreg(fit) val <- coef(fit) ans <- coef(betareg(y ~ x + z, link = "logit", data = dat)) - expect_equal(val, ans, tol = 0.1) + expect_equal(val, ans, tolerance = 0.1) }) test_that("QR recommended if VB and at least 2 predictors", { @@ -149,7 +148,7 @@ if (.Platform$OS.type != "windows" && require(betareg)) { val <- coef(fit) ans <- coef(betareg(y ~ x | z, link = link1[i], link.phi = link2[1], data = dat)) - expect_equal(val, ans, tol = 0.1, info = c(link1[i], link2[1])) + expect_equal(val, ans, tolerance = 0.1, info = c(link1[i], link2[1])) } }) @@ -169,7 +168,7 @@ if (.Platform$OS.type != "windows" && require(betareg)) { expect_stanreg(fit) val <- coef(fit) ans <- coef(betareg(y ~ x | z, link = link1[i], link.phi = link2[2], data = dat)) - expect_equal(val, ans, tol = 0.15, info = c(link1[i], link2[2])) + expect_equal(val, ans, tolerance = 0.15, info = c(link1[i], link2[2])) } }) @@ -206,7 +205,7 @@ if (.Platform$OS.type != "windows" && require(betareg)) { expect_stanreg(fit) val <- coef(fit) ans <- coef(betareg(y ~ x, link = "logit", weights = weights, offset = offset, data = dat)) - expect_equal(val, ans, tol = 0.3, info = "logit") + expect_equal(val, ans, tolerance = 0.3, info = "logit") }) test_that("heavy tailed priors work with stan_betareg", { diff --git a/tests/testthat/test_stan_clogit.R b/tests/testthat/test_stan_clogit.R index 2f719bffa..5fa9d6813 100644 --- a/tests/testthat/test_stan_clogit.R +++ b/tests/testthat/test_stan_clogit.R @@ -27,7 +27,6 @@ REFRESH <- 0 threshold <- 0.03 -context("stan_clogit") SW(fit <- stan_clogit(case ~ spontaneous + induced, strata = stratum, prior = NULL, data = infert[order(infert$stratum), ], @@ -36,7 +35,7 @@ SW(fit <- stan_clogit(case ~ spontaneous + induced, strata = stratum, prior = NU test_that("stan_clogit is similar to survival::clogit", { ref_vals <- c(spontaneous = 1.985876, induced = 1.409012) - expect_equal(ref_vals, coef(fit), tol = threshold) + expect_equal(ref_vals, coef(fit), tolerance = threshold) }) test_that("stan_clogit runs for infert example", { @@ -64,7 +63,6 @@ test_that("loo/waic for stan_clogit works", { expect_identical(ll_fun(fit), rstanarm:::.ll_clogit_i) }) -context("posterior_predict (stan_clogit)") test_that("compatible with stan_clogit", { PPD1 <- posterior_predict(fit) PPD2 <- posterior_predict(fit, newdata = infert) # order irrelevant diff --git a/tests/testthat/test_stan_functions.R b/tests/testthat/test_stan_functions.R index a75a35f6f..108afbcad 100644 --- a/tests/testthat/test_stan_functions.R +++ b/tests/testthat/test_stan_functions.R @@ -21,7 +21,6 @@ set.seed(12345) MODELS_HOME <- system.file("stan", package = "rstanarm", mustWork = TRUE) INCLUDE_DIR <- system.file("include", package = "rstanarm", mustWork = TRUE) -context("setup") test_that("Stan programs are available", { expect_true(file.exists(MODELS_HOME)) }) @@ -69,7 +68,6 @@ N <- 99L # bernoulli links <- c("logit", "probit", "cauchit", "log", "cloglog") -context("Bernoulli") test_that("linkinv_bern returns expected results", { for (i in 1:length(links)) { eta <- -abs(rnorm(N)) @@ -78,7 +76,7 @@ test_that("linkinv_bern returns expected results", { linkinv_bern(eta, i)), info = links[i]) } }) -context("Bernoulli") + test_that("pw_bern and ll_bern_lp return expected results", { for (i in 1:length(links)) { eta0 <- -abs(rnorm(N)) @@ -96,7 +94,7 @@ test_that("pw_bern and ll_bern_lp return expected results", { # Binomial trials <- 10L -context("Binomial") + test_that("linkinv_binom returns expected results", { for (i in 1:length(links)) { eta <- -abs(rnorm(N)) @@ -105,7 +103,7 @@ test_that("linkinv_binom returns expected results", { linkinv_binom(eta, i)), info = links[i]) } }) -context("Bernoulli") + test_that("pw_binom and ll_binom_lp return expected results", { for (i in 1:length(links)) { eta <- -abs(rnorm(N)) @@ -120,7 +118,6 @@ test_that("pw_binom and ll_binom_lp return expected results", { # Count GLM links <- c("log", "identity", "sqrt") -context("Poisson") test_that("linkinv_count returns expected results", { for (i in 1:length(links)) { eta <- abs(rnorm(N)) @@ -129,7 +126,7 @@ test_that("linkinv_count returns expected results", { linkinv_count(eta, i)), info = links[i]) } }) -context("Poisson") + test_that("pw_pois return expected results", { for (i in 1:length(links)) { y <- sample.int(10, size = N, replace = TRUE) @@ -141,7 +138,7 @@ test_that("pw_pois return expected results", { }) # Negative Binomial -context("Negative Binomial") + test_that("pw_nb return expected results", { for (i in 1:length(links)) { y <- sample.int(10, size = N, replace = TRUE) @@ -156,7 +153,6 @@ test_that("pw_nb return expected results", { # Gaussian GLM links <- c("identity", "log", "inverse") -context("Gaussian") test_that("linkinv_gauss returns expected results", { for (i in 1:length(links)) { eta <- rnorm(N) @@ -164,7 +160,7 @@ test_that("linkinv_gauss returns expected results", { expect_true(all.equal(linkinv(eta), linkinv_gauss(eta, i)), info = links[i]) } }) -context("Gaussian") + test_that("pw_gauss returns expected results", { for (i in 1:length(links)) { eta <- rnorm(N) @@ -275,7 +271,7 @@ test_that("inv_gaussian returns expected results", { # lm N <- 99L -context("lm") + test_that("ll_mvn_ols... returns expected results", { X <- matrix(rnorm(2 * N), N, 2) X <- sweep(X, MARGIN = 2, STATS = colMeans(X), FUN = "-") @@ -302,7 +298,7 @@ test_that("ll_mvn_ols... returns expected results", { # polr links <- c("logistic", "probit", "loglog", "cloglog", "cauchit") -context("polr") + test_that("CDF_polr returns expected results", { for (i in 1:length(links)) { x <- rnorm(1) @@ -312,7 +308,7 @@ test_that("CDF_polr returns expected results", { expect_true(all.equal(linkinv(x), CDF_polr(x, i))) } }) -context("polr") + test_that("pw_polr returns expected results", { J <- 3 for (i in 1:length(links)) { @@ -339,7 +335,7 @@ rdirichlet <- function(n, alpha) { sm <- x %*% rep(1, l) return(x/as.vector(sm)) } -context("polr") + test_that("make_cutpoints returns expected results", { J <- 5L for (i in 1:length(links)) { @@ -350,7 +346,7 @@ test_that("make_cutpoints returns expected results", { } } }) -context("polr") + test_that("draw_ystar_rng returns expected results", { l <- -0.1 u <- 0.1 @@ -363,7 +359,7 @@ test_that("draw_ystar_rng returns expected results", { }) # glmer -context("glmer") + if (require(lme4) && require(HSAUR3)) test_that("the Stan equivalent of lme4's Z %*% b works", { stopifnot(require(Matrix)) test_lme4 <- function(group) { @@ -394,7 +390,7 @@ if (require(lme4) && require(HSAUR3)) test_that("the Stan equivalent of lme4's Z b <- make_b(z_b, theta_L, p, l) mark <- colnames(Z) == "" expect_equal(b[!mark], as.vector(Matrix::t(Lambdati) %*% z_b[!mark]), - tol = 1e-14) + tolerance = 1e-14) parts <- extract_sparse_parts(Z) Zb <- Z %*% b @@ -427,14 +423,12 @@ if (require(lme4) && require(HSAUR3)) test_that("the Stan equivalent of lme4's Z test_lme4(glFormula(diameter ~ (1|plate) + (1|sample), data = Penicillin)$reTrms) }) -context("glmer") test_that("the Cornish-Fisher expansion from standard normal to Student t works", { df <- exp(1) / pi approx_t <- sapply(rnorm(1000), FUN = CFt, df = df) expect_true(ks.test(approx_t, "pt", df = df, exact = TRUE)$p.value > 0.05) }) -context("nlmer") test_that("SSasymp works", { Lob.329 <- Loblolly[ Loblolly$Seed == "329", ] Asym <- 100 @@ -448,7 +442,6 @@ test_that("SSasymp works", { SS_asymp( Lob.329$age, Phi ), check.attributes = FALSE)) }) -context("nlmer") test_that("SSasympOff works", { CO2.Qn1 <- CO2[CO2$Plant == "Qn1", ] Asym <- 32; lrc <- -4; c0 <- 43 @@ -460,7 +453,6 @@ test_that("SSasympOff works", { SS_asympOff(CO2.Qn1$conc, Phi), check.attributes = FALSE)) }) -context("nlmer") test_that("SSasympOrig works", { Lob.329 <- Loblolly[ Loblolly$Seed == "329", ] Asym <- 100; lrc <- -3.2 @@ -472,7 +464,6 @@ test_that("SSasympOrig works", { SS_asympOrig(Lob.329$age, Phi), check.attributes = FALSE)) }) -context("nlmer") test_that("SSbiexp works", { Indo.1 <- Indometh[Indometh$Subject == 1, ] A1 <- 3; lrc1 <- 1; A2 <- 0.6; lrc2 <- -1.3 @@ -484,7 +475,6 @@ test_that("SSbiexp works", { SS_biexp( Indo.1$time, Phi ), check.attributes = FALSE)) }) -context("nlmer") test_that("SSfol works", { Theoph.1 <- Theoph[ Theoph$Subject == 1, ] lKe <- -2.5; lKa <- 0.5; lCl <- -3 @@ -496,7 +486,6 @@ test_that("SSfol works", { SS_fol(Theoph.1$Dose, Theoph.1$Time, Phi), check.attributes = FALSE)) }) -context("nlmer") test_that("SSfpl works", { Chick.1 <- ChickWeight[ChickWeight$Chick == 1, ] A <- 13; B <- 368; xmid <- 14; scal <- 6 @@ -508,7 +497,6 @@ test_that("SSfpl works", { SS_fpl(Chick.1$Time, Phi), check.attributes = FALSE)) }) -context("nlmer") test_that("SSgompertz works", { DNase.1 <- subset(DNase, Run == 1) Asym <- 4.5; b2 <- 2.3; b3 <- 0.7 @@ -520,7 +508,6 @@ test_that("SSgompertz works", { SS_gompertz(log(DNase.1$conc), Phi), check.attributes = FALSE)) }) -context("nlmer") test_that("SSlogis works", { Chick.1 <- ChickWeight[ChickWeight$Chick == 1, ] Asym <- 368; xmid <- 14; scal <- 6 @@ -532,7 +519,6 @@ test_that("SSlogis works", { SS_logis(Chick.1$Time, Phi), check.attributes = FALSE)) }) -context("nlmer") test_that("SSmicmen works", { PurTrt <- Puromycin[ Puromycin$state == "treated", ] Vm <- 200; K <- 0.05 @@ -544,7 +530,6 @@ test_that("SSmicmen works", { SS_micmen(PurTrt$conc, Phi), check.attributes = FALSE)) }) -context("nlmer") test_that("SSweibull works", { Chick.6 <- subset(ChickWeight, (Chick == 6) & (Time > 0)) Asym <- 160; Drop <- 115; lrc <- -5.5; pwr <- 2.5 @@ -556,7 +541,6 @@ test_that("SSweibull works", { SS_weibull(Chick.6$Time, Phi) , check.attributes = FALSE)) }) -context("nlmer") test_that("reshape works", { x <- as.double(1:10) expect_true(all(matrix(x, 5, 2) == reshape_vec(x, 5L, 2L))) @@ -565,7 +549,6 @@ test_that("reshape works", { # betareg links <- c("logit", "probit", "cloglog", "cauchit", "log") -context("betareg") test_that("linkinv_beta returns expected results", { for (i in 1:length(links)) { eta <- -abs(rnorm(N)) @@ -574,7 +557,7 @@ test_that("linkinv_beta returns expected results", { linkinv_beta(eta, i)), info = links[i]) } }) -context("betareg") + test_that("pw_beta and ll_beta_lp return expected results", { for (i in 1:length(links)) { eta <- -abs(rnorm(N)) @@ -586,7 +569,6 @@ test_that("pw_beta and ll_beta_lp return expected results", { } }) -context("clogit") test_that("ll_clogit_lp (which calls log_clogit_denom) returns the expected results", { data(infert) infert <- infert[order(infert$stratum, !infert$case),] diff --git a/tests/testthat/test_stan_glm.R b/tests/testthat/test_stan_glm.R index 533558ec1..4c08bc41d 100644 --- a/tests/testthat/test_stan_glm.R +++ b/tests/testthat/test_stan_glm.R @@ -15,7 +15,6 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -context("stan_glm") suppressPackageStartupMessages(library(rstanarm)) SEED <- 12345 @@ -161,7 +160,7 @@ test_that("gaussian returns expected result for trees example", { ans <- glm(Volume ~ log(Girth) + log(Height),data = trees, family = gaussian(link = links[i])) - expect_equal(coef(fit), coef(ans), tol = 0.021) + expect_equal(coef(fit), coef(ans), tolerance = 0.021) } expect_error(update(fit, prior = dnorm), @@ -186,13 +185,13 @@ test_that("stan_glm returns expected result for glm poisson example", { ans <- glm(counts ~ outcome + treatment, data = d.AD, family = poisson(links[i]), start = coef(fit)) - if (links[i] == "log") expect_equal(coef(fit), coef(ans), tol = 0.03) + if (links[i] == "log") expect_equal(coef(fit), coef(ans), tolerance = 0.03) # if (links[i] == "identity") expect_equal(coef(fit)[-1], coef(ans)[-1], tol = 0.03) if (links[i] == "sqrt") { # this is weird if (coef(ans)[1] > 0) - expect_equal(coef(fit)[-1], coef(ans)[-1], tol = 0.1) + expect_equal(coef(fit)[-1], coef(ans)[-1], tolerance = 0.1) else - expect_equal(-coef(fit)[-1], coef(ans)[-1], tol = 0.04) + expect_equal(-coef(fit)[-1], coef(ans)[-1], tolerance = 0.04) } } }) @@ -225,18 +224,18 @@ test_that("stan_glm returns expected result for cars example", { expect_stanreg(fit) ans <- glm(log(dist) ~ log(speed), data = cars, family = gaussian(link = "identity")) - expect_equal(coef(fit), coef(ans), tol = 0.1) + expect_equal(coef(fit), coef(ans), tolerance = 0.1) }) test_that("stan_glm returns expected result with no intercept for mtcars example", { f <- as.formula(mpg ~ -1 + wt + cyl + disp + am + carb) - fit <- stan_glm(f, data = mtcars, refresh = 0, + SW(fit <- stan_glm(f, data = mtcars, refresh = 0, prior = NULL, prior_intercept = NULL, tol_rel_obj = .Machine$double.eps, algorithm = "optimizing", - seed = SEED, sparse = TRUE) + seed = SEED, sparse = TRUE)) expect_stanreg(fit) ans <- glm(f, data = mtcars, family = gaussian(link = "identity")) - expect_equal(coef(fit), coef(ans), tol = 0.04) + expect_equal(coef(fit), coef(ans), tolerance = 0.04) }) links <- c("logit", "probit", "cauchit", "log", "cloglog") @@ -261,7 +260,7 @@ test_that("stan_glm returns expected result for bernoulli", { val <- coef(fit) if (links[i] != "log") { ans <- coef(glm(y ~ x, family = fam, etastart = theta)) - expect_equal(val, ans, 0.09, info = links[i]) + expect_equal(val, ans, tolerance = 0.09, info = links[i]) } # else expect_equal(val[-1], ans[-1], 0.06, info = links[i]) } @@ -294,7 +293,7 @@ test_that("stan_glm returns expected result for binomial example", { val <- coef(fit) ans <- coef(glm(y ~ x1 + x2 + x3, data = dat, family = fam, start = b)) - if (links[i] != "log") expect_equal(val, ans, 0.02, info = links[i]) + if (links[i] != "log") expect_equal(val, ans, tolerance = 0.02, info = links[i]) # else expect_equal(val[-1], ans[-1], 0.02, info = links[i]) # unstable prop <- yes / trials @@ -307,8 +306,8 @@ test_that("stan_glm returns expected result for binomial example", { expect_stanreg(fit2) val2 <- coef(fit2) - if (links[i] != "log") expect_equal(val2, ans, 0.02, info = links[i]) - else expect_equal(val2[-1], ans[-1], 0.02, info = links[i]) + if (links[i] != "log") expect_equal(val2, ans, tolerance = 0.02, info = links[i]) + else expect_equal(val2[-1], ans[-1], tolerance = 0.02, info = links[i]) } }) @@ -389,10 +388,10 @@ test_that("prior_options is deprecated", { ops <- prior_options(scaled = FALSE, prior_scale_for_dispersion = 3), "deprecated and will be removed" ) - expect_warning( + suppressWarnings(expect_warning( capture.output(fit <- stan_glm(mpg ~ wt, data = mtcars, iter = 5, prior_ops = ops)), "Setting prior scale for aux to value specified in 'prior_options'" - ) + )) expect_output( print(prior_summary(fit)), "~ exponential(rate = 0.33)", @@ -406,8 +405,9 @@ test_that("empty interaction levels dropped", { x1[x2 == 1] <- 1 x1[x2 == 2] <- 1 y <- rnorm(100) - expect_warning(stan_glm(y ~ x1*x2, chains = 1, iter = 20, refresh = 0), - regexp = "Dropped empty interaction levels") + suppressWarnings(expect_warning( + stan_glm(y ~ x1*x2, chains = 1, iter = 20, refresh = 0), + regexp = "Dropped empty interaction levels")) }) @@ -480,12 +480,12 @@ test_that("returns something with collinear predictors", { x1 <- rnorm(N) x2 <- 2*x1 - fit_1 <- stan_glm( + SW(fit_1 <- stan_glm( y ~ z * (x1 + x2), data = data.frame(y, z, x1, x2), prior = normal(location = 0, scale = 0.1), prior_intercept = normal(location = 0, scale = 0.1), chains = CHAINS, iter = ITER, refresh = REFRESH - ) + )) expect_stanreg(fit_1) }) diff --git a/tests/testthat/test_stan_glmer.R b/tests/testthat/test_stan_glmer.R index 6800ffaea..1794fd231 100644 --- a/tests/testthat/test_stan_glmer.R +++ b/tests/testthat/test_stan_glmer.R @@ -35,7 +35,6 @@ SW(fit <- stan_lmer(Reaction / 10 ~ Days + (Days | Subject), data = sleepstudy, refresh = 0, init_r = 0.05, chains = CHAINS, iter = ITER, seed = SEED)) -context("stan_glmer") test_that("draws from stan_glmer (gaussian) same as from stan_lmer", { SW(fit1 <- stan_glmer(mpg ~ wt + (1|cyl), data = mtcars, iter = 10, chains = 1, seed = SEED, refresh = 0)) @@ -53,13 +52,12 @@ test_that("stan_glmer returns expected result for binomial cbpp example", { expect_stanreg(fit) ans <- glmer(fmla, data = cbpp, family = binomial(links[i])) - expect_equal(fixef(fit), fixef(ans), tol = FIXEF_tol) - expect_equal(ranef(fit), ranef(ans), tol = RANEF_tol, check.attributes = FALSE) + expect_equal(fixef(fit), fixef(ans), tolerance = FIXEF_tol) + expect_equal(ranef(fit), ranef(ans), tolerance = RANEF_tol, ignore_attr = TRUE) expect_equal(ngrps(fit), ngrps(ans)) # } }) -context("stan_glmer.nb") test_that("stan_glmer.nb ok", { dd <- expand.grid(f1 = factor(1:3), f2 = LETTERS[1:2], g=1:9, rep=1:15, @@ -78,13 +76,12 @@ test_that("stan_glmer.nb ok", { expect_equal(ngrps(fit), ngrps(ans)) }) -context("stan_lmer") test_that("stan_lmer returns expected result for slepstudy example", { fmla <- formula(fit) expect_stanreg(fit) ans <- lmer(fmla, data = sleepstudy) - expect_equal(fixef(fit), fixef(ans), tol = FIXEF_tol) + expect_equal(fixef(fit), fixef(ans), tolerance = FIXEF_tol) # expect_equal(ranef(fit), ranef(ans), tol = RANEF_tol) expect_equal(ngrps(fit), ngrps(ans)) }) @@ -95,8 +92,8 @@ test_that("stan_lmer returns expected result for Penicillin example", { expect_stanreg(fit) ans <- lmer(fmla, data = Penicillin) - expect_equal(fixef(fit), fixef(ans), tol = FIXEF_tol) - expect_equal(ranef(fit), ranef(ans), tol = RANEF_tol, check.attributes = FALSE) + expect_equal(fixef(fit), fixef(ans), tolerance = FIXEF_tol) + expect_equal(ranef(fit), ranef(ans), tolerance = RANEF_tol, ignore_attr = TRUE) expect_identical(ngrps(fit), ngrps(ans)) }) test_that("stan_lmer ok if global intercept forced to 0", { @@ -128,8 +125,6 @@ test_that("error if y is character", { ) }) - -context("stan_gamm4") test_that("stan_gamm4 returns stanreg object", { skip_if_not_installed("mgcv") sleepstudy$y <- sleepstudy$Reaction / 10 @@ -139,7 +134,7 @@ test_that("stan_gamm4 returns stanreg object", { expect_stanreg(fit) # ans <- gamm4(Reaction / 10 ~ s(Days), data = sleepstudy, # random = ~(1|Subject))$mer - # expect_equal(fixef(fit)[-1], fixef(ans)[-1], tol = FIXEF_tol, check.attributes = FALSE) + # expect_equal(fixef(fit)[-1], fixef(ans)[-1], tol = FIXEF_tol, ignore_attr = TRUE) # expect_equal(ranef(fit), ranef(ans), tol = RANEF_tol) # expect_identical(ngrps(fit), ngrps(ans)) @@ -196,7 +191,6 @@ test_that("loo/waic for stan_glmer works", { expect_identical(ll_fun(example_model), rstanarm:::.ll_binomial_i) }) -context("posterior_predict (stan_gamm4)") test_that("stan_gamm4 returns expected result for sleepstudy example", { skip_if_not_installed("mgcv") sleepstudy$y <- sleepstudy$Reaction / 10 @@ -210,8 +204,6 @@ test_that("stan_gamm4 returns expected result for sleepstudy example", { expect_silent(posterior_predict(fit, newdata = sleepstudy)) }) - -context("posterior_predict (stan_(g)lmer)") test_that("compatible with stan_lmer", { check_for_pp_errors(fit) expect_linpred_equal(fit) @@ -262,7 +254,7 @@ test_that("predition with family mgcv::betar doesn't error", { }) # compare to lme4 --------------------------------------------------------- -context("posterior_predict (compare to lme4)") + test_that("posterior_predict close to predict.merMod for gaussian", { mod1 <- as.formula(mpg ~ wt + (1|cyl) + (1|gear)) mod2 <- as.formula(mpg ~ log1p(wt) + I(disp/100) + (1|cyl)) @@ -290,17 +282,17 @@ test_that("posterior_predict close to predict.merMod for gaussian", { expect_equal( colMeans(posterior_predict(get(paste0("sfit", j)), newdata = nd, seed = SEED)), unname(predict(get(paste0("lfit", j)), newdata = nd)), - tol = tol, check.attributes = FALSE) + tolerance = tol, ignore_attr = TRUE) expect_equal( colMeans(posterior_predict(get(paste0("sfit", j)), newdata = nd2, seed = SEED, allow.new.levels = TRUE)), unname(predict(get(paste0("lfit", j)), newdata = nd2, allow.new.levels = TRUE)), - tol = tol, check.attributes = FALSE) + tolerance = tol, ignore_attr = TRUE) expect_equal( colMeans(posterior_predict(get(paste0("sfit", j)), newdata = nd3, seed = SEED, allow.new.levels = TRUE)), unname(predict(get(paste0("lfit", j)), newdata = nd3, allow.new.levels = TRUE)), - tol = tol, check.attributes = FALSE) + tolerance = tol, ignore_attr = TRUE) } }) @@ -320,5 +312,5 @@ test_that("posterior_predict close to predict.merMod for binomial", { seed = SEED) spred <- sweep(spred, 2, rowSums(get_y(sfit)), "/") expect_equal(colMeans(spred), unname(colMeans(lpred)), - tol = .125, check.attributes = FALSE) + tolerance = .125, ignore_attr = TRUE) }) diff --git a/tests/testthat/test_stan_jm.R b/tests/testthat/test_stan_jm.R index e5d075fad..6342dc502 100644 --- a/tests/testthat/test_stan_jm.R +++ b/tests/testthat/test_stan_jm.R @@ -33,7 +33,6 @@ TOLSCALES <- list( event = 0.3 # how many SEs can stan_jm fixefs be from coxph fixefs ) -context("stan_jm") #---- Data (for non-Gaussian families) @@ -354,11 +353,11 @@ compare_glmer <- function(fmLong, fam = gaussian, ...) { pars <- recover_pars(y1, s1) parsjm <- recover_pars(j1) for (i in names(tols$fixef)) - expect_equal(pars$fixef[[i]], parsjm$fixef[[i]], tol = tols$fixef[[i]], info = fam) + expect_equal(pars$fixef[[i]], parsjm$fixef[[i]], tolerance = tols$fixef[[i]], info = fam) for (i in names(tols$ranef)) - expect_equal(pars$ranef[[i]], parsjm$ranef[[i]], tol = tols$ranef[[i]], info = fam) + expect_equal(pars$ranef[[i]], parsjm$ranef[[i]], tolerance = tols$ranef[[i]], info = fam) for (i in names(tols$event)) - expect_equal(pars$event[[i]], parsjm$event[[i]], tol = tols$event[[i]], info = fam) + expect_equal(pars$event[[i]], parsjm$event[[i]], tolerance = tols$event[[i]], info = fam) } # test_that("coefs same for stan_jm and stan_lmer/coxph", { diff --git a/tests/testthat/test_stan_lm.R b/tests/testthat/test_stan_lm.R index 49c953232..6a232c25f 100644 --- a/tests/testthat/test_stan_lm.R +++ b/tests/testthat/test_stan_lm.R @@ -15,7 +15,6 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -context("stan_lm|aov|biglm") suppressPackageStartupMessages(library(rstanarm)) SEED <- 12345 @@ -43,7 +42,7 @@ test_that("stan_aov returns expected result for npk example", { fit_sigma <- fit$stan_summary["sigma", "mean"] lm_sigma <- summary(lm(yield ~ block + N*P*K, data = npk, contrasts = contrasts_list))$sigma - expect_equal(fit_sigma, lm_sigma, tol = threshold) + expect_equal(fit_sigma, lm_sigma, tolerance = threshold) expect_output(print(fit), regexp = "stan_aov") expect_output(print(fit), regexp = "ANOVA-like table") }) @@ -73,7 +72,7 @@ test_that("stan_biglm returns expected result", { SW(post <- stan_biglm(biglm, xbar, ybar, s_y, prior = R2(0.5), chains = CHAINS, iter = ITER, seed = SEED, refresh = 0)) expect_equal(coef(lm(mpg ~ wt + qsec + am, data = mtcars)), - rstan::summary(post)$summary[1:4, "mean"], tol = threshold) + rstan::summary(post)$summary[1:4, "mean"], tolerance = threshold) }) test_that("stan_lm returns expected result for mtcars example", { @@ -82,7 +81,7 @@ test_that("stan_lm returns expected result for mtcars example", { fit_sigma <- fit$stan_summary["sigma", "mean"] lm_sigma <- summary(lm(mpg ~ ., data = mtcars))$sigma - expect_equal(fit_sigma, lm_sigma, tol = threshold) + expect_equal(fit_sigma, lm_sigma, tolerance = threshold) }) test_that("stan_lm returns expected result for trees example", { # example using trees dataset @@ -93,7 +92,7 @@ test_that("stan_lm returns expected result for trees example", { fit_sigma <- fit$stan_summary["sigma", "mean"] lm_sigma <- summary(lm(log(Volume) ~ log(Girth) + log(Height),data = trees))$sigma - expect_equal(fit_sigma, lm_sigma, tol = threshold) + expect_equal(fit_sigma, lm_sigma, tolerance = threshold) }) test_that("stan_lm doesn't break with less common priors", { @@ -158,5 +157,8 @@ test_that("loo/waic for stan_lm works", { test_that("posterior_predict compatible with stan_lm", { skip_on_os("mac") check_for_pp_errors(fit) - expect_linpred_equal(fit) + # Scale relative error by the posterior medians. + expect_true(all.equal(apply(posterior_linpred(fit), 2, median), + fit$linear.predictors, tolerance = 0.1, + check.attributes = FALSE)) }) diff --git a/tests/testthat/test_stan_mvmer.R b/tests/testthat/test_stan_mvmer.R index 43cc1b5b0..2275006ea 100644 --- a/tests/testthat/test_stan_mvmer.R +++ b/tests/testthat/test_stan_mvmer.R @@ -31,7 +31,6 @@ TOLSCALES <- list( glmer_ranef = 0.1 # how many SDs can stan_jm ranefs be from glmer ranefs ) -context("stan_mvmer") #---- Data (for non-Gaussian families) @@ -167,14 +166,14 @@ if (interactive()) { pars <- recover_pars(y1) pars2 <- recover_pars(y2) for (i in names(tols$fixef)) - expect_equal(pars$fixef[[i]], pars2$fixef[[i]], tol = tols$fixef[[i]]) + expect_equal(pars$fixef[[i]], pars2$fixef[[i]], tolerance = tols$fixef[[i]]) for (i in names(tols$ranef)) - expect_equal(pars$ranef[[i]], pars2$ranef[[i]], tol = tols$ranef[[i]]) + expect_equal(pars$ranef[[i]], pars2$ranef[[i]], tolerance = tols$ranef[[i]]) expect_equal(colMeans(log_lik(y1)), - colMeans(log_lik(y2)), tol = 0.15) + colMeans(log_lik(y2)), tolerance = 0.15) nd <- pbcLong[stats::complete.cases(pbcLong), , drop = FALSE] expect_equal(colMeans(log_lik(y1, newdata = nd)), - colMeans(log_lik(y2, newdata = nd)), tol = 0.15) + colMeans(log_lik(y2, newdata = nd)), tolerance = 0.15) } test_that("coefs same for stan_jm and stan_lmer/coxph", { # fails in many cases @@ -287,14 +286,14 @@ for (j in 1:5) { fm <- formula(mod) fam <- family(mod) sig <- sigma(mod) - expect_is(fe, "list"); expect_identical(length(fe), M) - expect_is(re, "list"); expect_identical(length(re), M) - expect_is(ce, "list"); expect_identical(length(re), M) - expect_is(mf, "list"); expect_identical(length(mf), M); lapply(mf, function(x) expect_is(x, "data.frame")) - expect_is(tt, "list"); expect_identical(length(tt), M); lapply(tt, function(x) expect_is(x, "terms")) - expect_is(fm, "list"); expect_identical(length(fm), M); lapply(fm, function(x) expect_is(x, "formula")) - expect_is(fam,"list"); expect_identical(length(fam),M); lapply(fam, function(x) expect_is(x, "family")) - expect_is(sig, "numeric"); + expect_type(fe, "list"); expect_identical(length(fe), M) + expect_type(re, "list"); expect_identical(length(re), M) + expect_type(ce, "list"); expect_identical(length(re), M) + expect_type(mf, "list"); expect_identical(length(mf), M); lapply(mf, function(x) expect_s3_class(x, "data.frame")) + expect_type(tt, "list"); expect_identical(length(tt), M); lapply(tt, function(x) expect_s3_class(x, "terms")) + expect_type(fm, "list"); expect_identical(length(fm), M); lapply(fm, function(x) expect_s3_class(x, "formula")) + expect_type(fam, "list"); expect_identical(length(fam),M); lapply(fam, function(x) expect_s3_class(x, "family")) + expect_type(sig, "double"); }) test_that("these extraction methods are currently disallowed", { diff --git a/tests/testthat/test_stan_nlmer.R b/tests/testthat/test_stan_nlmer.R index 5448155d6..e955a2df6 100644 --- a/tests/testthat/test_stan_nlmer.R +++ b/tests/testthat/test_stan_nlmer.R @@ -26,7 +26,6 @@ REFRESH <- 0 threshold <- 0.05 -context("stan_nlmer") data("Orange", package = "datasets") Orange$circumference <- Orange$circumference / 100 @@ -44,7 +43,7 @@ test_that("stan_nlmer runs for Orange example", { }) test_that("stan_nlmer is similar to nlmer on Orange example", { - expect_equal(fixef(ml), fixef(fit), tol = threshold) + expect_equal(fixef(ml), fixef(fit), tolerance = threshold) }) test_that("stan_nlmer throws error if formula includes an unknown function", { @@ -57,7 +56,6 @@ test_that("loo/waic for stan_nlmer works", { expect_equivalent_loo(fit) }) -context("posterior_predict (stan_nlmer)") test_that("compatible with stan_nlmer", { check_for_pp_errors(fit) }) diff --git a/tests/testthat/test_stan_polr.R b/tests/testthat/test_stan_polr.R index 89972bf97..796a8da62 100644 --- a/tests/testthat/test_stan_polr.R +++ b/tests/testthat/test_stan_polr.R @@ -26,7 +26,6 @@ REFRESH <- 0 threshold <- 0.03 -context("stan_polr") f <- tobgp ~ agegp + alcgp @@ -82,10 +81,10 @@ test_that("gumbel functions ok", { # formulas are correct # just test a few cases so they're flagged if anything changes by accident # maybe should compare to corresponding functions in ordinal package? - expect_equal(rstanarm:::dgumbel(0), 0.3678794, tol = 0.00001) + expect_equal(rstanarm:::dgumbel(0), 0.3678794, tolerance = 0.00001) expect_equal(rstanarm:::qgumbel(0), -Inf) - expect_equal(rstanarm:::qgumbel(0.5), 0.3665129, tol = 0.00001) - expect_equal(rstanarm:::pgumbel(0.3665129), 0.5, tol = 0.00001) + expect_equal(rstanarm:::qgumbel(0.5), 0.3665129, tolerance = 0.00001) + expect_equal(rstanarm:::pgumbel(0.3665129), 0.5, tolerance = 0.00001) expect_equal(rstanarm:::qgumbel(1), Inf) }) @@ -101,7 +100,6 @@ test_that("loo/waic for stan_polr works", { expect_identical(ll_fun(fit3), rstanarm:::.ll_polr_i) }) -context("posterior_predict (stan_polr)") test_that("compatible with stan_polr", { check_for_pp_errors(fit1) check_for_pp_errors(fit2) From 7d643d3206020c34c41c7bd6fba46aaf1e74def5 Mon Sep 17 00:00:00 2001 From: Andrew Johnson Date: Mon, 14 Sep 2026 15:24:20 +0800 Subject: [PATCH 14/19] Test updated action --- .github/workflows/R-CMD-check.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/R-CMD-check.yaml b/.github/workflows/R-CMD-check.yaml index a3611c0e9..51984d4a8 100644 --- a/.github/workflows/R-CMD-check.yaml +++ b/.github/workflows/R-CMD-check.yaml @@ -34,7 +34,7 @@ jobs: steps: - uses: actions/checkout@v7 - - uses: r-lib/actions/setup-r@v2 + - uses: andrjohns/actions/setup-r@flang-mac-devel with: r-version: ${{ matrix.r }} From ab6a99c884c697586a968f0cb2975b6f31dba34a Mon Sep 17 00:00:00 2001 From: Andrew Johnson Date: Fri, 18 Sep 2026 15:41:31 +0800 Subject: [PATCH 15/19] Force source build --- .github/workflows/R-CMD-check.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/R-CMD-check.yaml b/.github/workflows/R-CMD-check.yaml index 51984d4a8..b7dac72b2 100644 --- a/.github/workflows/R-CMD-check.yaml +++ b/.github/workflows/R-CMD-check.yaml @@ -50,6 +50,6 @@ jobs: - uses: r-lib/actions/setup-r-dependencies@v2 with: dependencies: "TRUE" - extra-packages: any::rcmdcheck + extra-packages: any::rcmdcheck, any::rstan=?source - uses: r-lib/actions/check-r-package@v2 From 5d93d840750d284270c7c9094ce180a928fe2262 Mon Sep 17 00:00:00 2001 From: Andrew Johnson Date: Fri, 18 Sep 2026 15:48:13 +0800 Subject: [PATCH 16/19] Pak syntax --- .github/workflows/R-CMD-check.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/R-CMD-check.yaml b/.github/workflows/R-CMD-check.yaml index b7dac72b2..c681e1c96 100644 --- a/.github/workflows/R-CMD-check.yaml +++ b/.github/workflows/R-CMD-check.yaml @@ -50,6 +50,6 @@ jobs: - uses: r-lib/actions/setup-r-dependencies@v2 with: dependencies: "TRUE" - extra-packages: any::rcmdcheck, any::rstan=?source + extra-packages: any::rcmdcheck, any::rstan?source - uses: r-lib/actions/check-r-package@v2 From fd97b84178606d568014cd80c17945dab51b9861 Mon Sep 17 00:00:00 2001 From: Andrew Johnson Date: Fri, 18 Sep 2026 16:08:06 +0800 Subject: [PATCH 17/19] Force source build --- .github/workflows/R-CMD-check.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/R-CMD-check.yaml b/.github/workflows/R-CMD-check.yaml index c681e1c96..bdf4de2bc 100644 --- a/.github/workflows/R-CMD-check.yaml +++ b/.github/workflows/R-CMD-check.yaml @@ -50,6 +50,6 @@ jobs: - uses: r-lib/actions/setup-r-dependencies@v2 with: dependencies: "TRUE" - extra-packages: any::rcmdcheck, any::rstan?source + extra-packages: any::rcmdcheck, rstan?source - uses: r-lib/actions/check-r-package@v2 From 5bb077621905357657ac9fd6f921fddd9e4e9dd2 Mon Sep 17 00:00:00 2001 From: Andrew Johnson Date: Sat, 19 Sep 2026 15:54:33 +0800 Subject: [PATCH 18/19] Remove CI testing changes --- .github/workflows/R-CMD-check.yaml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/R-CMD-check.yaml b/.github/workflows/R-CMD-check.yaml index bdf4de2bc..47197c8f2 100644 --- a/.github/workflows/R-CMD-check.yaml +++ b/.github/workflows/R-CMD-check.yaml @@ -4,7 +4,6 @@ on: push: branches: - master - - ci-fixes pull_request: branches: - master @@ -34,7 +33,7 @@ jobs: steps: - uses: actions/checkout@v7 - - uses: andrjohns/actions/setup-r@flang-mac-devel + - uses: r-lib/actions/setup-r@v2 with: r-version: ${{ matrix.r }} From b3a76f09e92fabf7451fcd8b219f8e6ddc7dc043 Mon Sep 17 00:00:00 2001 From: jgabry Date: Mon, 21 Sep 2026 10:16:20 -0600 Subject: [PATCH 19/19] add @andrjohns to DESCRIPTION --- DESCRIPTION | 1 + 1 file changed, 1 insertion(+) diff --git a/DESCRIPTION b/DESCRIPTION index 93243271a..53d7d7791 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -7,6 +7,7 @@ Encoding: UTF-8 Authors@R: c(person("Jonah", "Gabry", email = "jgabry@gmail.com", role = "aut"), person("Imad", "Ali", role = "ctb"), person("Sam", "Brilleman", role = "ctb"), + person("Andrew", "Johnson", role = "ctb"), person(given = "Jacqueline Buros", family = "Novik", role = "ctb", comment = "R/stan_jm.R"), person("AstraZeneca", role = "ctb", comment = "R/stan_jm.R"),