From d0f06f1d363ad23b2bbaa00f89697f47c0d31f88 Mon Sep 17 00:00:00 2001 From: VisruthSK Date: Fri, 24 Jul 2026 02:32:56 -0700 Subject: [PATCH 1/6] Moved shinystan to imports --- .gitattributes | 2 + DESCRIPTION | 158 +++++------ NAMESPACE | 2 +- R/launch_shinystan.R | 266 ++++++++++-------- ...inystan.stanreg.Rd => launch_shinystan.Rd} | 50 ++-- 5 files changed, 249 insertions(+), 229 deletions(-) create mode 100644 .gitattributes rename man/{launch_shinystan.stanreg.Rd => launch_shinystan.Rd} (92%) diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 000000000..dfe077042 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,2 @@ +# Auto detect text files and perform LF normalization +* text=auto diff --git a/DESCRIPTION b/DESCRIPTION index 5a5a8fde3..01a0d101b 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,79 +1,79 @@ -Package: rstanarm -Type: Package -Title: Bayesian Applied Regression Modeling via Stan -Version: 2.32.2 -Date: 2025-09-29 -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(given = "Jacqueline Buros", family = "Novik", - role = "ctb", comment = "R/stan_jm.R"), - person("AstraZeneca", role = "ctb", comment = "R/stan_jm.R"), - person("Trustees of", "Columbia University", role = "cph"), - person("Simon", "Wood", role = "cph", comment = "R/stan_gamm4.R"), - person("R Core", "Deveopment Team", role = "cph", - comment = "R/stan_aov.R"), - person("Douglas", "Bates", role = "cph", comment = "R/pp_data.R"), - person("Martin", "Maechler", role = "cph", comment = "R/pp_data.R"), - person("Ben", "Bolker", role = "cph", comment = "R/pp_data.R"), - person("Steve", "Walker", role = "cph", comment = "R/pp_data.R"), - person("Brian", "Ripley", role = "cph", - comment = "R/stan_aov.R, R/stan_polr.R"), - person("William", "Venables", role = "cph", comment = "R/stan_polr.R"), - person("Paul-Christian", "Burkner", email = "paul.buerkner@gmail.com", - role = "cph", comment = "R/misc.R"), - person("Ben", "Goodrich", email = "benjamin.goodrich@columbia.edu", - role = c("cre", "aut"))) -Description: Estimates previously compiled regression models using the 'rstan' - package, which provides the R interface to the Stan C++ library for Bayesian - estimation. Users specify models via the customary R syntax with a formula and - data.frame plus some additional arguments for priors. -License: GPL (>=3) -Depends: - R (>= 3.4.0), - Rcpp (>= 0.12.0), - methods -Imports: - bayesplot (>= 1.7.0), - ggplot2 (>= 2.2.1), - lme4 (>= 1.1-8), - loo (>= 2.1.0), - Matrix (>= 1.2-13), - nlme (>= 3.1-124), - posterior, - rstan (>= 2.32.0), - rstantools (>= 2.1.0), - shinystan (>= 2.3.0), - stats, - survival (>= 2.40.1), - RcppParallel (>= 5.0.1), - utils, - reformulas -Suggests: - biglm, - betareg, - data.table (>= 1.10.0), - digest, - gridExtra, - HSAUR3, - knitr (>= 1.15.1), - MASS, - mgcv (>= 1.8-13), - rmarkdown, - roxygen2, - StanHeaders (>= 2.21.0), - testthat (>= 1.0.2), - gamm4, - shiny, - V8 -LinkingTo: StanHeaders (>= 2.32.0), rstan (>= 2.32.0), BH (>= 1.72.0-2), Rcpp (>= - 0.12.0), RcppEigen (>= 0.3.3.3.0), RcppParallel (>= 5.0.1) -SystemRequirements: GNU make, pandoc (>= 1.12.3), pandoc-citeproc -VignetteBuilder: knitr -LazyData: true -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 +Package: rstanarm +Type: Package +Title: Bayesian Applied Regression Modeling via Stan +Version: 2.32.2 +Date: 2025-09-29 +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(given = "Jacqueline Buros", family = "Novik", + role = "ctb", comment = "R/stan_jm.R"), + person("AstraZeneca", role = "ctb", comment = "R/stan_jm.R"), + person("Trustees of", "Columbia University", role = "cph"), + person("Simon", "Wood", role = "cph", comment = "R/stan_gamm4.R"), + person("R Core", "Deveopment Team", role = "cph", + comment = "R/stan_aov.R"), + person("Douglas", "Bates", role = "cph", comment = "R/pp_data.R"), + person("Martin", "Maechler", role = "cph", comment = "R/pp_data.R"), + person("Ben", "Bolker", role = "cph", comment = "R/pp_data.R"), + person("Steve", "Walker", role = "cph", comment = "R/pp_data.R"), + person("Brian", "Ripley", role = "cph", + comment = "R/stan_aov.R, R/stan_polr.R"), + person("William", "Venables", role = "cph", comment = "R/stan_polr.R"), + person("Paul-Christian", "Burkner", email = "paul.buerkner@gmail.com", + role = "cph", comment = "R/misc.R"), + person("Ben", "Goodrich", email = "benjamin.goodrich@columbia.edu", + role = c("cre", "aut"))) +Description: Estimates previously compiled regression models using the 'rstan' + package, which provides the R interface to the Stan C++ library for Bayesian + estimation. Users specify models via the customary R syntax with a formula and + data.frame plus some additional arguments for priors. +License: GPL (>=3) +Depends: + R (>= 3.4.0), + Rcpp (>= 0.12.0), + methods +Imports: + bayesplot (>= 1.7.0), + ggplot2 (>= 2.2.1), + lme4 (>= 1.1-8), + loo (>= 2.1.0), + Matrix (>= 1.2-13), + nlme (>= 3.1-124), + posterior, + rstan (>= 2.32.0), + rstantools (>= 2.1.0), + stats, + survival (>= 2.40.1), + RcppParallel (>= 5.0.1), + utils, + reformulas +Suggests: + biglm, + betareg, + data.table (>= 1.10.0), + digest, + gridExtra, + HSAUR3, + knitr (>= 1.15.1), + MASS, + mgcv (>= 1.8-13), + rmarkdown, + roxygen2, + shinystan (>= 2.3.0), + StanHeaders (>= 2.21.0), + testthat (>= 1.0.2), + gamm4, + shiny, + V8 +LinkingTo: StanHeaders (>= 2.32.0), rstan (>= 2.32.0), BH (>= 1.72.0-2), Rcpp (>= + 0.12.0), RcppEigen (>= 0.3.3.3.0), RcppParallel (>= 5.0.1) +SystemRequirements: GNU make, pandoc (>= 1.12.3), pandoc-citeproc +VignetteBuilder: knitr +LazyData: true +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 diff --git a/NAMESPACE b/NAMESPACE index 1f93e3581..a4d188135 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -33,7 +33,6 @@ S3method(get_y,stanmvreg) S3method(get_z,lmerMod) S3method(get_z,stanmvreg) S3method(kfold,stanreg) -S3method(launch_shinystan,stanreg) S3method(log_lik,stanjm) S3method(log_lik,stanmvreg) S3method(log_lik,stanreg) @@ -87,6 +86,7 @@ S3method(residuals,stanmvreg) S3method(residuals,stanreg) S3method(se,stanmvreg) S3method(se,stanreg) +S3method(shinystan::launch_shinystan,stanreg) S3method(sigma,stanmvreg) S3method(sigma,stanreg) S3method(summary,stanmvreg) diff --git a/R/launch_shinystan.R b/R/launch_shinystan.R index 39d6acf05..b55882b87 100644 --- a/R/launch_shinystan.R +++ b/R/launch_shinystan.R @@ -1,125 +1,141 @@ -# Part of the rstanarm package for estimating model parameters -# Copyright (C) 2015, 2016, 2017 Trustees of Columbia University -# -# This program is free software; you can redistribute it and/or -# modify it under the terms of the GNU General Public License -# as published by the Free Software Foundation; either version 3 -# of the License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - -#' Using the ShinyStan GUI with rstanarm models -#' -#' The ShinyStan interface provides visual and numerical summaries of model -#' parameters and convergence diagnostics. -#' -#' @aliases launch_shinystan -#' @export -#' -#' @templateVar stanregArg object -#' @template args-stanreg-object -#' @inheritParams shinystan::launch_shinystan -#' @param ppd Should \pkg{rstanarm} draw from the posterior predictive -#' distribution before launching ShinyStan? The default is \code{TRUE}, -#' although for very large objects it can be convenient to set it to -#' \code{FALSE} as drawing from the posterior predictive distribution can be -#' time consuming. If \code{ppd} is \code{TRUE} then graphical posterior -#' predictive checks are available when ShinyStan is launched. -#' @param seed Passed to \link[=pp_check]{pp_check} if -#' \code{ppd} is \code{TRUE}. -#' @param model_name,note Optional arguments passed to -#' \code{\link[shinystan]{as.shinystan}}. -#' -#' @details The \code{\link[shinystan]{launch_shinystan}} function will accept a -#' \code{\link[=stanreg-objects]{stanreg}} object as input. Currently, almost -#' any model fit using one of \pkg{rstanarm}'s model-fitting functions can be -#' used with ShinyStan. The only exception is that ShinyStan does not -#' currently support \pkg{rstanarm} models fit using -#' \code{algorithm='optimizing'}. See the -#' \pkg{\link[shinystan:shinystan-package]{shinystan}} package documentation for more -#' information. -#' -#' @section Faster launch times: -#' For some \pkg{rstanarm} models ShinyStan may take a very long time to launch. -#' If this is the case with one of your models you may be able to speed up -#' \code{launch_shinystan} in one of several ways: -#' \describe{ -#' \item{Prevent ShinyStan from preparing graphical posterior predictive -#' checks:}{ -#' When used with a \code{\link[=stanreg-objects]{stanreg}} object -#' (\pkg{rstanarm} model object) ShinyStan will draw from the posterior -#' predictive distribution and prepare graphical posterior predictive checks -#' before launching. That way when you go to the PPcheck page the plots are -#' immediately available. This can be time consuming for models fit to very -#' large datasets and you can prevent this behavior by creating a shinystan -#' object before calling \code{launch_shinystan}. To do this use -#' \code{\link[shinystan]{as.shinystan}} with optional argument \code{ppd} set -#' to \code{FALSE} (see the Examples section below). When you then launch -#' ShinyStan and go to the PPcheck page the plots will no longer be -#' automatically generated and you will be presented with the standard -#' interface requiring you to first specify the appropriate \eqn{y} and -#' \eqn{yrep}, which can be done for many but not all \pkg{rstanarm} models. -#' } -#' \item{Use a shinystan object:}{ -#' Even if you don't want to prevent ShinyStan from preparing graphical -#' posterior predictive checks, first creating a shinystan object using -#' \code{\link[shinystan]{as.shinystan}} can reduce \emph{future} launch -#' times. That is, \code{launch_shinystan(sso)} will be faster than -#' \code{launch_shinystan(fit)}, where \code{sso} is a shinystan object and -#' \code{fit} is a stanreg object. It still may take some time for -#' \code{as.shinystan} to create \code{sso} initially, but each time you -#' subsequently call \code{launch_shinystan(sso)} it will reuse \code{sso} -#' instead of internally creating a shinystan object every time. See the -#' Examples section below.} -#' } -#' -#' @template reference-bayesvis -#' @template reference-muth -#' -#' @examples -#' if (.Platform$OS.type != "windows" || .Platform$r_arch != "i386") { -#' \dontrun{ -#' if (!exists("example_model")) example(example_model) -#' -#' # Launch the ShinyStan app without saving the resulting shinystan object -#' if (interactive()) launch_shinystan(example_model) -#' -#' # Launch the ShinyStan app (saving resulting shinystan object as sso) -#' if (interactive()) sso <- launch_shinystan(example_model) -#' -#' # First create shinystan object then call launch_shinystan -#' sso <- shinystan::as.shinystan(example_model) -#' if (interactive()) launch_shinystan(sso) -#' -#' # Prevent ShinyStan from preparing graphical posterior predictive checks that -#' # can be time consuming. example_model is small enough that it won't matter -#' # much here but in general this can help speed up launch_shinystan -#' sso <- shinystan::as.shinystan(example_model, ppd = FALSE) -#' if (interactive()) launch_shinystan(sso) -#' } -#' } -launch_shinystan.stanreg <- - function(object, - ppd = TRUE, - seed = 1234, - model_name = NULL, - note = NULL, - rstudio = getOption("shinystan.rstudio"), - ...) { - sso <- - shinystan::as.shinystan( - object, - ppd = ppd, - seed = seed, - model_name = model_name, - note = note - ) - shinystan::launch_shinystan(sso, rstudio = rstudio, ...) - } +# Part of the rstanarm package for estimating model parameters +# Copyright (C) 2015, 2016, 2017 Trustees of Columbia University +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 3 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +#' Using the ShinyStan GUI with rstanarm models +#' +#' The ShinyStan interface provides visual and numerical summaries of model +#' parameters and convergence diagnostics. +#' +#' @aliases launch_shinystan +#' @export +#' +#' @templateVar stanregArg object +#' @template args-stanreg-object +#' @inheritParams shinystan::launch_shinystan +#' @param ppd Should \pkg{rstanarm} draw from the posterior predictive +#' distribution before launching ShinyStan? The default is \code{TRUE}, +#' although for very large objects it can be convenient to set it to +#' \code{FALSE} as drawing from the posterior predictive distribution can be +#' time consuming. If \code{ppd} is \code{TRUE} then graphical posterior +#' predictive checks are available when ShinyStan is launched. +#' @param seed Passed to \link[=pp_check]{pp_check} if +#' \code{ppd} is \code{TRUE}. +#' @param model_name,note Optional arguments passed to +#' \code{\link[shinystan]{as.shinystan}}. +#' +#' @details The \code{\link[shinystan]{launch_shinystan}} function will accept a +#' \code{\link[=stanreg-objects]{stanreg}} object as input. Currently, almost +#' any model fit using one of \pkg{rstanarm}'s model-fitting functions can be +#' used with ShinyStan. The only exception is that ShinyStan does not +#' currently support \pkg{rstanarm} models fit using +#' \code{algorithm='optimizing'}. See the +#' \pkg{\link[shinystan:shinystan-package]{shinystan}} package documentation for more +#' information. +#' +#' @section Faster launch times: +#' For some \pkg{rstanarm} models ShinyStan may take a very long time to launch. +#' If this is the case with one of your models you may be able to speed up +#' \code{launch_shinystan} in one of several ways: +#' \describe{ +#' \item{Prevent ShinyStan from preparing graphical posterior predictive +#' checks:}{ +#' When used with a \code{\link[=stanreg-objects]{stanreg}} object +#' (\pkg{rstanarm} model object) ShinyStan will draw from the posterior +#' predictive distribution and prepare graphical posterior predictive checks +#' before launching. That way when you go to the PPcheck page the plots are +#' immediately available. This can be time consuming for models fit to very +#' large datasets and you can prevent this behavior by creating a shinystan +#' object before calling \code{launch_shinystan}. To do this use +#' \code{\link[shinystan]{as.shinystan}} with optional argument \code{ppd} set +#' to \code{FALSE} (see the Examples section below). When you then launch +#' ShinyStan and go to the PPcheck page the plots will no longer be +#' automatically generated and you will be presented with the standard +#' interface requiring you to first specify the appropriate \eqn{y} and +#' \eqn{yrep}, which can be done for many but not all \pkg{rstanarm} models. +#' } +#' \item{Use a shinystan object:}{ +#' Even if you don't want to prevent ShinyStan from preparing graphical +#' posterior predictive checks, first creating a shinystan object using +#' \code{\link[shinystan]{as.shinystan}} can reduce \emph{future} launch +#' times. That is, \code{launch_shinystan(sso)} will be faster than +#' \code{launch_shinystan(fit)}, where \code{sso} is a shinystan object and +#' \code{fit} is a stanreg object. It still may take some time for +#' \code{as.shinystan} to create \code{sso} initially, but each time you +#' subsequently call \code{launch_shinystan(sso)} it will reuse \code{sso} +#' instead of internally creating a shinystan object every time. See the +#' Examples section below.} +#' } +#' +#' @template reference-bayesvis +#' @template reference-muth +#' +#' @examples +#' if (.Platform$OS.type != "windows" || .Platform$r_arch != "i386") { +#' \dontrun{ +#' if (!exists("example_model")) example(example_model) +#' +#' # Launch the ShinyStan app without saving the resulting shinystan object +#' if (interactive()) launch_shinystan(example_model) +#' +#' # Launch the ShinyStan app (saving resulting shinystan object as sso) +#' if (interactive()) sso <- launch_shinystan(example_model) +#' +#' # First create shinystan object then call launch_shinystan +#' sso <- shinystan::as.shinystan(example_model) +#' if (interactive()) launch_shinystan(sso) +#' +#' # Prevent ShinyStan from preparing graphical posterior predictive checks that +#' # can be time consuming. example_model is small enough that it won't matter +#' # much here but in general this can help speed up launch_shinystan +#' sso <- shinystan::as.shinystan(example_model, ppd = FALSE) +#' if (interactive()) launch_shinystan(sso) +#' } +#' } +launch_shinystan <- function(object, ...) { + if (!requireNamespace("shinystan", quietly = TRUE)) { + stop( + "Package 'shinystan' is not installed but is required in order to use `launch_shinystan()`.", + call. = FALSE + ) + } + + shinystan::launch_shinystan(object, ...) +} + +#' @rdname launch_shinystan +#' @exportS3Method shinystan::launch_shinystan +launch_shinystan.stanreg <- + function( + object, + ppd = TRUE, + seed = 1234, + model_name = NULL, + note = NULL, + rstudio = getOption("shinystan.rstudio"), + ... + ) { + sso <- + shinystan::as.shinystan( + object, + ppd = ppd, + seed = seed, + model_name = model_name, + note = note + ) + + shinystan::launch_shinystan(sso, rstudio = rstudio, ...) + } diff --git a/man/launch_shinystan.stanreg.Rd b/man/launch_shinystan.Rd similarity index 92% rename from man/launch_shinystan.stanreg.Rd rename to man/launch_shinystan.Rd index ca26635f2..fff74939c 100644 --- a/man/launch_shinystan.stanreg.Rd +++ b/man/launch_shinystan.Rd @@ -1,10 +1,12 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/launch_shinystan.R -\name{launch_shinystan.stanreg} -\alias{launch_shinystan.stanreg} +\name{launch_shinystan} \alias{launch_shinystan} +\alias{launch_shinystan.stanreg} \title{Using the ShinyStan GUI with rstanarm models} \usage{ +launch_shinystan(object, ...) + \method{launch_shinystan}{stanreg}( object, ppd = TRUE, @@ -19,14 +21,16 @@ \item{object}{A fitted model object returned by one of the \pkg{rstanarm} modeling functions. See \code{\link{stanreg-objects}}.} -\item{ppd}{Should \pkg{rstanarm} draw from the posterior predictive -distribution before launching ShinyStan? The default is \code{TRUE}, -although for very large objects it can be convenient to set it to -\code{FALSE} as drawing from the posterior predictive distribution can be -time consuming. If \code{ppd} is \code{TRUE} then graphical posterior +\item{...}{Optional arguments passed to \code{\link[shiny]{runApp}}.} + +\item{ppd}{Should \pkg{rstanarm} draw from the posterior predictive +distribution before launching ShinyStan? The default is \code{TRUE}, +although for very large objects it can be convenient to set it to +\code{FALSE} as drawing from the posterior predictive distribution can be +time consuming. If \code{ppd} is \code{TRUE} then graphical posterior predictive checks are available when ShinyStan is launched.} -\item{seed}{Passed to \link[=pp_check]{pp_check} if +\item{seed}{Passed to \link[=pp_check]{pp_check} if \code{ppd} is \code{TRUE}.} \item{model_name, note}{Optional arguments passed to @@ -37,8 +41,6 @@ is to launch the app in the user's default web browser rather than the pop-up Viewer provided by 'RStudio'. Users can change the default to \code{TRUE} by setting the global option \code{options(shinystan.rstudio = TRUE)}.} - -\item{...}{Optional arguments passed to \code{\link[shiny]{runApp}}.} } \description{ The ShinyStan interface provides visual and numerical summaries of model @@ -46,12 +48,12 @@ parameters and convergence diagnostics. } \details{ The \code{\link[shinystan]{launch_shinystan}} function will accept a - \code{\link[=stanreg-objects]{stanreg}} object as input. Currently, almost - any model fit using one of \pkg{rstanarm}'s model-fitting functions can be - used with ShinyStan. The only exception is that ShinyStan does not - currently support \pkg{rstanarm} models fit using - \code{algorithm='optimizing'}. See the - \pkg{\link[shinystan:shinystan-package]{shinystan}} package documentation for more + \code{\link[=stanreg-objects]{stanreg}} object as input. Currently, almost + any model fit using one of \pkg{rstanarm}'s model-fitting functions can be + used with ShinyStan. The only exception is that ShinyStan does not + currently support \pkg{rstanarm} models fit using + \code{algorithm='optimizing'}. See the + \pkg{\link[shinystan:shinystan-package]{shinystan}} package documentation for more information. } \section{Faster launch times}{ @@ -62,16 +64,16 @@ If this is the case with one of your models you may be able to speed up \describe{ \item{Prevent ShinyStan from preparing graphical posterior predictive checks:}{ - When used with a \code{\link[=stanreg-objects]{stanreg}} object - (\pkg{rstanarm} model object) ShinyStan will draw from the posterior - predictive distribution and prepare graphical posterior predictive checks - before launching. That way when you go to the PPcheck page the plots are + When used with a \code{\link[=stanreg-objects]{stanreg}} object + (\pkg{rstanarm} model object) ShinyStan will draw from the posterior + predictive distribution and prepare graphical posterior predictive checks + before launching. That way when you go to the PPcheck page the plots are immediately available. This can be time consuming for models fit to very large datasets and you can prevent this behavior by creating a shinystan - object before calling \code{launch_shinystan}. To do this use + object before calling \code{launch_shinystan}. To do this use \code{\link[shinystan]{as.shinystan}} with optional argument \code{ppd} set to \code{FALSE} (see the Examples section below). When you then launch - ShinyStan and go to the PPcheck page the plots will no longer be + ShinyStan and go to the PPcheck page the plots will no longer be automatically generated and you will be presented with the standard interface requiring you to first specify the appropriate \eqn{y} and \eqn{yrep}, which can be done for many but not all \pkg{rstanarm} models. @@ -82,7 +84,7 @@ If this is the case with one of your models you may be able to speed up \code{\link[shinystan]{as.shinystan}} can reduce \emph{future} launch times. That is, \code{launch_shinystan(sso)} will be faster than \code{launch_shinystan(fit)}, where \code{sso} is a shinystan object and - \code{fit} is a stanreg object. It still may take some time for + \code{fit} is a stanreg object. It still may take some time for \code{as.shinystan} to create \code{sso} initially, but each time you subsequently call \code{launch_shinystan(sso)} it will reuse \code{sso} instead of internally creating a shinystan object every time. See the @@ -93,7 +95,7 @@ If this is the case with one of your models you may be able to speed up \examples{ if (.Platform$OS.type != "windows" || .Platform$r_arch != "i386") { \dontrun{ -if (!exists("example_model")) example(example_model) +if (!exists("example_model")) example(example_model) # Launch the ShinyStan app without saving the resulting shinystan object if (interactive()) launch_shinystan(example_model) From c87d17e300e1ffd680f9c4785f288912f965ad43 Mon Sep 17 00:00:00 2001 From: VisruthSK Date: Fri, 24 Jul 2026 02:33:06 -0700 Subject: [PATCH 2/6] Roxygen 8.0.0 redoc --- DESCRIPTION | 158 ++++++++++++++++++++-------------------- 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 +- 14 files changed, 93 insertions(+), 92 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 01a0d101b..13d1f25a9 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,79 +1,79 @@ -Package: rstanarm -Type: Package -Title: Bayesian Applied Regression Modeling via Stan -Version: 2.32.2 -Date: 2025-09-29 -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(given = "Jacqueline Buros", family = "Novik", - role = "ctb", comment = "R/stan_jm.R"), - person("AstraZeneca", role = "ctb", comment = "R/stan_jm.R"), - person("Trustees of", "Columbia University", role = "cph"), - person("Simon", "Wood", role = "cph", comment = "R/stan_gamm4.R"), - person("R Core", "Deveopment Team", role = "cph", - comment = "R/stan_aov.R"), - person("Douglas", "Bates", role = "cph", comment = "R/pp_data.R"), - person("Martin", "Maechler", role = "cph", comment = "R/pp_data.R"), - person("Ben", "Bolker", role = "cph", comment = "R/pp_data.R"), - person("Steve", "Walker", role = "cph", comment = "R/pp_data.R"), - person("Brian", "Ripley", role = "cph", - comment = "R/stan_aov.R, R/stan_polr.R"), - person("William", "Venables", role = "cph", comment = "R/stan_polr.R"), - person("Paul-Christian", "Burkner", email = "paul.buerkner@gmail.com", - role = "cph", comment = "R/misc.R"), - person("Ben", "Goodrich", email = "benjamin.goodrich@columbia.edu", - role = c("cre", "aut"))) -Description: Estimates previously compiled regression models using the 'rstan' - package, which provides the R interface to the Stan C++ library for Bayesian - estimation. Users specify models via the customary R syntax with a formula and - data.frame plus some additional arguments for priors. -License: GPL (>=3) -Depends: - R (>= 3.4.0), - Rcpp (>= 0.12.0), - methods -Imports: - bayesplot (>= 1.7.0), - ggplot2 (>= 2.2.1), - lme4 (>= 1.1-8), - loo (>= 2.1.0), - Matrix (>= 1.2-13), - nlme (>= 3.1-124), - posterior, - rstan (>= 2.32.0), - rstantools (>= 2.1.0), - stats, - survival (>= 2.40.1), - RcppParallel (>= 5.0.1), - utils, - reformulas -Suggests: - biglm, - betareg, - data.table (>= 1.10.0), - digest, - gridExtra, - HSAUR3, - knitr (>= 1.15.1), - MASS, - mgcv (>= 1.8-13), - rmarkdown, - roxygen2, - shinystan (>= 2.3.0), - StanHeaders (>= 2.21.0), - testthat (>= 1.0.2), - gamm4, - shiny, - V8 -LinkingTo: StanHeaders (>= 2.32.0), rstan (>= 2.32.0), BH (>= 1.72.0-2), Rcpp (>= - 0.12.0), RcppEigen (>= 0.3.3.3.0), RcppParallel (>= 5.0.1) -SystemRequirements: GNU make, pandoc (>= 1.12.3), pandoc-citeproc -VignetteBuilder: knitr -LazyData: true -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 +Package: rstanarm +Type: Package +Title: Bayesian Applied Regression Modeling via Stan +Version: 2.32.2 +Date: 2025-09-29 +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(given = "Jacqueline Buros", family = "Novik", + role = "ctb", comment = "R/stan_jm.R"), + person("AstraZeneca", role = "ctb", comment = "R/stan_jm.R"), + person("Trustees of", "Columbia University", role = "cph"), + person("Simon", "Wood", role = "cph", comment = "R/stan_gamm4.R"), + person("R Core", "Deveopment Team", role = "cph", + comment = "R/stan_aov.R"), + person("Douglas", "Bates", role = "cph", comment = "R/pp_data.R"), + person("Martin", "Maechler", role = "cph", comment = "R/pp_data.R"), + person("Ben", "Bolker", role = "cph", comment = "R/pp_data.R"), + person("Steve", "Walker", role = "cph", comment = "R/pp_data.R"), + person("Brian", "Ripley", role = "cph", + comment = "R/stan_aov.R, R/stan_polr.R"), + person("William", "Venables", role = "cph", comment = "R/stan_polr.R"), + person("Paul-Christian", "Burkner", email = "paul.buerkner@gmail.com", + role = "cph", comment = "R/misc.R"), + person("Ben", "Goodrich", email = "benjamin.goodrich@columbia.edu", + role = c("cre", "aut"))) +Description: Estimates previously compiled regression models using the 'rstan' + package, which provides the R interface to the Stan C++ library for Bayesian + estimation. Users specify models via the customary R syntax with a formula and + data.frame plus some additional arguments for priors. +License: GPL (>=3) +Depends: + R (>= 3.4.0), + Rcpp (>= 0.12.0), + methods +Imports: + bayesplot (>= 1.7.0), + ggplot2 (>= 2.2.1), + lme4 (>= 1.1-8), + loo (>= 2.1.0), + Matrix (>= 1.2-13), + nlme (>= 3.1-124), + posterior, + rstan (>= 2.32.0), + rstantools (>= 2.1.0), + stats, + survival (>= 2.40.1), + RcppParallel (>= 5.0.1), + utils, + reformulas +Suggests: + biglm, + betareg, + data.table (>= 1.10.0), + digest, + gridExtra, + HSAUR3, + knitr (>= 1.15.1), + MASS, + mgcv (>= 1.8-13), + rmarkdown, + roxygen2, + shinystan (>= 2.3.0), + StanHeaders (>= 2.21.0), + testthat (>= 1.0.2), + gamm4, + shiny, + V8 +LinkingTo: StanHeaders (>= 2.32.0), rstan (>= 2.32.0), BH (>= 1.72.0-2), Rcpp (>= + 0.12.0), RcppEigen (>= 0.3.3.3.0), RcppParallel (>= 5.0.1) +SystemRequirements: GNU make, pandoc (>= 1.12.3), pandoc-citeproc +VignetteBuilder: knitr +LazyData: true +UseLTO: true +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.0.0 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 32eeb91a1bcef9a838849390997b14eb9a958e76 Mon Sep 17 00:00:00 2001 From: VisruthSK Date: Fri, 24 Jul 2026 02:46:35 -0700 Subject: [PATCH 3/6] Deleted uneccessary rplots pdf file from testthat dir --- tests/testthat/Rplots.pdf | Bin 292 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 tests/testthat/Rplots.pdf diff --git a/tests/testthat/Rplots.pdf b/tests/testthat/Rplots.pdf deleted file mode 100644 index ffd79fdd4b3ce054dbadc7fc4090496dbbe7e6c6..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 292 zcmZ{eu?~VT7=-se#lMiqAT3ZLF@y!8laUZcmkJGH2qmQqjy$1*Z=f$?ON=HO$N%oW z`_IbK&C+!!vZnj=n6A_9Adw3M#PN)x2;oF>rW({J zy`oXArgGRy)}NYkfc>cYQE4obq8dvsjY}Qk_*$EP2_xAkjuG!Fv%-6?0bE>q4me?o twW0=`v6>Iy>p%`4VD$r-oJmXGsaG5)qEq@DAe?cW^FfTV)P3};?+HCcQ=$L> From af040d53d3cd410a3d97f2b62fe86861b7892aa4 Mon Sep 17 00:00:00 2001 From: VisruthSK Date: Fri, 24 Jul 2026 02:50:21 -0700 Subject: [PATCH 4/6] Renormed file --- R/launch_shinystan.R | 282 +++++++++++++++++++++---------------------- 1 file changed, 141 insertions(+), 141 deletions(-) diff --git a/R/launch_shinystan.R b/R/launch_shinystan.R index b55882b87..79e135ac9 100644 --- a/R/launch_shinystan.R +++ b/R/launch_shinystan.R @@ -1,141 +1,141 @@ -# Part of the rstanarm package for estimating model parameters -# Copyright (C) 2015, 2016, 2017 Trustees of Columbia University -# -# This program is free software; you can redistribute it and/or -# modify it under the terms of the GNU General Public License -# as published by the Free Software Foundation; either version 3 -# of the License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - -#' Using the ShinyStan GUI with rstanarm models -#' -#' The ShinyStan interface provides visual and numerical summaries of model -#' parameters and convergence diagnostics. -#' -#' @aliases launch_shinystan -#' @export -#' -#' @templateVar stanregArg object -#' @template args-stanreg-object -#' @inheritParams shinystan::launch_shinystan -#' @param ppd Should \pkg{rstanarm} draw from the posterior predictive -#' distribution before launching ShinyStan? The default is \code{TRUE}, -#' although for very large objects it can be convenient to set it to -#' \code{FALSE} as drawing from the posterior predictive distribution can be -#' time consuming. If \code{ppd} is \code{TRUE} then graphical posterior -#' predictive checks are available when ShinyStan is launched. -#' @param seed Passed to \link[=pp_check]{pp_check} if -#' \code{ppd} is \code{TRUE}. -#' @param model_name,note Optional arguments passed to -#' \code{\link[shinystan]{as.shinystan}}. -#' -#' @details The \code{\link[shinystan]{launch_shinystan}} function will accept a -#' \code{\link[=stanreg-objects]{stanreg}} object as input. Currently, almost -#' any model fit using one of \pkg{rstanarm}'s model-fitting functions can be -#' used with ShinyStan. The only exception is that ShinyStan does not -#' currently support \pkg{rstanarm} models fit using -#' \code{algorithm='optimizing'}. See the -#' \pkg{\link[shinystan:shinystan-package]{shinystan}} package documentation for more -#' information. -#' -#' @section Faster launch times: -#' For some \pkg{rstanarm} models ShinyStan may take a very long time to launch. -#' If this is the case with one of your models you may be able to speed up -#' \code{launch_shinystan} in one of several ways: -#' \describe{ -#' \item{Prevent ShinyStan from preparing graphical posterior predictive -#' checks:}{ -#' When used with a \code{\link[=stanreg-objects]{stanreg}} object -#' (\pkg{rstanarm} model object) ShinyStan will draw from the posterior -#' predictive distribution and prepare graphical posterior predictive checks -#' before launching. That way when you go to the PPcheck page the plots are -#' immediately available. This can be time consuming for models fit to very -#' large datasets and you can prevent this behavior by creating a shinystan -#' object before calling \code{launch_shinystan}. To do this use -#' \code{\link[shinystan]{as.shinystan}} with optional argument \code{ppd} set -#' to \code{FALSE} (see the Examples section below). When you then launch -#' ShinyStan and go to the PPcheck page the plots will no longer be -#' automatically generated and you will be presented with the standard -#' interface requiring you to first specify the appropriate \eqn{y} and -#' \eqn{yrep}, which can be done for many but not all \pkg{rstanarm} models. -#' } -#' \item{Use a shinystan object:}{ -#' Even if you don't want to prevent ShinyStan from preparing graphical -#' posterior predictive checks, first creating a shinystan object using -#' \code{\link[shinystan]{as.shinystan}} can reduce \emph{future} launch -#' times. That is, \code{launch_shinystan(sso)} will be faster than -#' \code{launch_shinystan(fit)}, where \code{sso} is a shinystan object and -#' \code{fit} is a stanreg object. It still may take some time for -#' \code{as.shinystan} to create \code{sso} initially, but each time you -#' subsequently call \code{launch_shinystan(sso)} it will reuse \code{sso} -#' instead of internally creating a shinystan object every time. See the -#' Examples section below.} -#' } -#' -#' @template reference-bayesvis -#' @template reference-muth -#' -#' @examples -#' if (.Platform$OS.type != "windows" || .Platform$r_arch != "i386") { -#' \dontrun{ -#' if (!exists("example_model")) example(example_model) -#' -#' # Launch the ShinyStan app without saving the resulting shinystan object -#' if (interactive()) launch_shinystan(example_model) -#' -#' # Launch the ShinyStan app (saving resulting shinystan object as sso) -#' if (interactive()) sso <- launch_shinystan(example_model) -#' -#' # First create shinystan object then call launch_shinystan -#' sso <- shinystan::as.shinystan(example_model) -#' if (interactive()) launch_shinystan(sso) -#' -#' # Prevent ShinyStan from preparing graphical posterior predictive checks that -#' # can be time consuming. example_model is small enough that it won't matter -#' # much here but in general this can help speed up launch_shinystan -#' sso <- shinystan::as.shinystan(example_model, ppd = FALSE) -#' if (interactive()) launch_shinystan(sso) -#' } -#' } -launch_shinystan <- function(object, ...) { - if (!requireNamespace("shinystan", quietly = TRUE)) { - stop( - "Package 'shinystan' is not installed but is required in order to use `launch_shinystan()`.", - call. = FALSE - ) - } - - shinystan::launch_shinystan(object, ...) -} - -#' @rdname launch_shinystan -#' @exportS3Method shinystan::launch_shinystan -launch_shinystan.stanreg <- - function( - object, - ppd = TRUE, - seed = 1234, - model_name = NULL, - note = NULL, - rstudio = getOption("shinystan.rstudio"), - ... - ) { - sso <- - shinystan::as.shinystan( - object, - ppd = ppd, - seed = seed, - model_name = model_name, - note = note - ) - - shinystan::launch_shinystan(sso, rstudio = rstudio, ...) - } +# Part of the rstanarm package for estimating model parameters +# Copyright (C) 2015, 2016, 2017 Trustees of Columbia University +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 3 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +#' Using the ShinyStan GUI with rstanarm models +#' +#' The ShinyStan interface provides visual and numerical summaries of model +#' parameters and convergence diagnostics. +#' +#' @aliases launch_shinystan +#' @export +#' +#' @templateVar stanregArg object +#' @template args-stanreg-object +#' @inheritParams shinystan::launch_shinystan +#' @param ppd Should \pkg{rstanarm} draw from the posterior predictive +#' distribution before launching ShinyStan? The default is \code{TRUE}, +#' although for very large objects it can be convenient to set it to +#' \code{FALSE} as drawing from the posterior predictive distribution can be +#' time consuming. If \code{ppd} is \code{TRUE} then graphical posterior +#' predictive checks are available when ShinyStan is launched. +#' @param seed Passed to \link[=pp_check]{pp_check} if +#' \code{ppd} is \code{TRUE}. +#' @param model_name,note Optional arguments passed to +#' \code{\link[shinystan]{as.shinystan}}. +#' +#' @details The \code{\link[shinystan]{launch_shinystan}} function will accept a +#' \code{\link[=stanreg-objects]{stanreg}} object as input. Currently, almost +#' any model fit using one of \pkg{rstanarm}'s model-fitting functions can be +#' used with ShinyStan. The only exception is that ShinyStan does not +#' currently support \pkg{rstanarm} models fit using +#' \code{algorithm='optimizing'}. See the +#' \pkg{\link[shinystan:shinystan-package]{shinystan}} package documentation for more +#' information. +#' +#' @section Faster launch times: +#' For some \pkg{rstanarm} models ShinyStan may take a very long time to launch. +#' If this is the case with one of your models you may be able to speed up +#' \code{launch_shinystan} in one of several ways: +#' \describe{ +#' \item{Prevent ShinyStan from preparing graphical posterior predictive +#' checks:}{ +#' When used with a \code{\link[=stanreg-objects]{stanreg}} object +#' (\pkg{rstanarm} model object) ShinyStan will draw from the posterior +#' predictive distribution and prepare graphical posterior predictive checks +#' before launching. That way when you go to the PPcheck page the plots are +#' immediately available. This can be time consuming for models fit to very +#' large datasets and you can prevent this behavior by creating a shinystan +#' object before calling \code{launch_shinystan}. To do this use +#' \code{\link[shinystan]{as.shinystan}} with optional argument \code{ppd} set +#' to \code{FALSE} (see the Examples section below). When you then launch +#' ShinyStan and go to the PPcheck page the plots will no longer be +#' automatically generated and you will be presented with the standard +#' interface requiring you to first specify the appropriate \eqn{y} and +#' \eqn{yrep}, which can be done for many but not all \pkg{rstanarm} models. +#' } +#' \item{Use a shinystan object:}{ +#' Even if you don't want to prevent ShinyStan from preparing graphical +#' posterior predictive checks, first creating a shinystan object using +#' \code{\link[shinystan]{as.shinystan}} can reduce \emph{future} launch +#' times. That is, \code{launch_shinystan(sso)} will be faster than +#' \code{launch_shinystan(fit)}, where \code{sso} is a shinystan object and +#' \code{fit} is a stanreg object. It still may take some time for +#' \code{as.shinystan} to create \code{sso} initially, but each time you +#' subsequently call \code{launch_shinystan(sso)} it will reuse \code{sso} +#' instead of internally creating a shinystan object every time. See the +#' Examples section below.} +#' } +#' +#' @template reference-bayesvis +#' @template reference-muth +#' +#' @examples +#' if (.Platform$OS.type != "windows" || .Platform$r_arch != "i386") { +#' \dontrun{ +#' if (!exists("example_model")) example(example_model) +#' +#' # Launch the ShinyStan app without saving the resulting shinystan object +#' if (interactive()) launch_shinystan(example_model) +#' +#' # Launch the ShinyStan app (saving resulting shinystan object as sso) +#' if (interactive()) sso <- launch_shinystan(example_model) +#' +#' # First create shinystan object then call launch_shinystan +#' sso <- shinystan::as.shinystan(example_model) +#' if (interactive()) launch_shinystan(sso) +#' +#' # Prevent ShinyStan from preparing graphical posterior predictive checks that +#' # can be time consuming. example_model is small enough that it won't matter +#' # much here but in general this can help speed up launch_shinystan +#' sso <- shinystan::as.shinystan(example_model, ppd = FALSE) +#' if (interactive()) launch_shinystan(sso) +#' } +#' } +launch_shinystan <- function(object, ...) { + if (!requireNamespace("shinystan", quietly = TRUE)) { + stop( + "Package 'shinystan' is not installed but is required in order to use `launch_shinystan()`.", + call. = FALSE + ) + } + + shinystan::launch_shinystan(object, ...) +} + +#' @rdname launch_shinystan +#' @exportS3Method shinystan::launch_shinystan +launch_shinystan.stanreg <- + function( + object, + ppd = TRUE, + seed = 1234, + model_name = NULL, + note = NULL, + rstudio = getOption("shinystan.rstudio"), + ... + ) { + sso <- + shinystan::as.shinystan( + object, + ppd = ppd, + seed = seed, + model_name = model_name, + note = note + ) + + shinystan::launch_shinystan(sso, rstudio = rstudio, ...) + } From 8d0bae0f227517c02fcce505e2019e503768fec9 Mon Sep 17 00:00:00 2001 From: VisruthSK Date: Fri, 24 Jul 2026 12:58:51 -0700 Subject: [PATCH 5/6] Don't import shinystan --- NAMESPACE | 1 - R/doc-rstanarm-package.R | 4 +--- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/NAMESPACE b/NAMESPACE index a4d188135..6ea051150 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -195,7 +195,6 @@ import(Rcpp) import(bayesplot) import(methods) import(rstantools) -import(shinystan) import(stats) importFrom(Matrix,Matrix) importFrom(Matrix,t) diff --git a/R/doc-rstanarm-package.R b/R/doc-rstanarm-package.R index 9abc30957..48b9a9907 100644 --- a/R/doc-rstanarm-package.R +++ b/R/doc-rstanarm-package.R @@ -20,14 +20,12 @@ #' @useDynLib rstanarm, .registration = TRUE #' #' @import methods -#' @importFrom rstan optimizing sampling vb constrain_pars extract -#' extract_sparse_parts get_posterior_mean stanc +#' @importFrom rstan optimizing sampling vb constrain_pars extract extract_sparse_parts get_posterior_mean stanc #' @importFrom utils capture.output #' @importFrom RcppParallel RcppParallelLibs #' @import stats #' @import Rcpp #' @import bayesplot -#' @import shinystan #' @import rstantools #' @export log_lik posterior_linpred posterior_epred posterior_predict posterior_interval #' @export predictive_interval predictive_error prior_summary bayes_R2 From d5ad5a07bc5d30261c751e0ed3239ce898977802 Mon Sep 17 00:00:00 2001 From: VisruthSK Date: Fri, 24 Jul 2026 13:00:07 -0700 Subject: [PATCH 6/6] Fixed some roxygen notes --- R/posterior_survfit.R | 3 +-- R/posterior_traj.R | 3 +-- R/posterior_vs_prior.R | 3 +-- 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/R/posterior_survfit.R b/R/posterior_survfit.R index 11cd39473..299119680 100644 --- a/R/posterior_survfit.R +++ b/R/posterior_survfit.R @@ -531,8 +531,7 @@ posterior_survfit <- function(object, newdataLong = NULL, newdataEvent = NULL, #' #' @method plot survfit.stanjm #' @export -#' @importFrom ggplot2 ggplot aes_string geom_line geom_ribbon -#' facet_wrap labs coord_cartesian +#' @importFrom ggplot2 ggplot aes_string geom_line geom_ribbon facet_wrap labs coord_cartesian #' #' @templateVar idsArg ids #' @templateVar labsArg xlab,ylab diff --git a/R/posterior_traj.R b/R/posterior_traj.R index d555fd2e7..171218add 100644 --- a/R/posterior_traj.R +++ b/R/posterior_traj.R @@ -463,8 +463,7 @@ posterior_traj <- function(object, m = 1, newdata = NULL, newdataLong = NULL, #' #' @method plot predict.stanjm #' @export -#' @importFrom ggplot2 ggplot aes aes_string geom_line geom_smooth geom_ribbon -#' geom_point facet_wrap geom_vline labs ggplot_build theme_bw +#' @importFrom ggplot2 ggplot aes aes_string geom_line geom_smooth geom_ribbon geom_point facet_wrap geom_vline labs ggplot_build theme_bw #' #' @templateVar labsArg xlab,ylab #' @templateVar scalesArg facet_scales diff --git a/R/posterior_vs_prior.R b/R/posterior_vs_prior.R index ebcfc73ca..bd488001b 100644 --- a/R/posterior_vs_prior.R +++ b/R/posterior_vs_prior.R @@ -91,8 +91,7 @@ #' gg_polr + ggplot2::coord_flip() #' } #' } -#' @importFrom ggplot2 geom_pointrange facet_wrap aes_string labs -#' scale_x_discrete element_line element_text +#' @importFrom ggplot2 geom_pointrange facet_wrap aes_string labs scale_x_discrete element_line element_text #' posterior_vs_prior <- function(object, ...) { UseMethod("posterior_vs_prior")