Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Auto detect text files and perform LF normalization
* text=auto
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ Imports:
posterior,
rstan (>= 2.32.0),
rstantools (>= 2.1.0),
shinystan (>= 2.3.0),
stats,
survival (>= 2.40.1),
RcppParallel (>= 5.0.1),
Expand All @@ -62,6 +61,7 @@ Suggests:
mgcv (>= 1.8-13),
rmarkdown,
roxygen2,
shinystan (>= 2.3.0),
StanHeaders (>= 2.21.0),
testthat (>= 1.0.2),
gamm4,
Expand All @@ -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.0.0
3 changes: 1 addition & 2 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -195,7 +195,6 @@ import(Rcpp)
import(bayesplot)
import(methods)
import(rstantools)
import(shinystan)
import(stats)
importFrom(Matrix,Matrix)
importFrom(Matrix,t)
Expand Down
4 changes: 1 addition & 3 deletions R/doc-rstanarm-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
98 changes: 57 additions & 41 deletions R/launch_shinystan.R
Original file line number Diff line number Diff line change
@@ -1,68 +1,68 @@
# 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
#' @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
#' @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
#' \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
#' 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.
Expand All @@ -73,46 +73,61 @@
#' \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
#' 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)
#'
#' 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, ...) {
Comment thread
VisruthSK marked this conversation as resolved.
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"),
...) {
function(
object,
ppd = TRUE,
seed = 1234,
model_name = NULL,
note = NULL,
rstudio = getOption("shinystan.rstudio"),
...
) {
sso <-
shinystan::as.shinystan(
object,
Expand All @@ -121,5 +136,6 @@ launch_shinystan.stanreg <-
model_name = model_name,
note = note
)

shinystan::launch_shinystan(sso, rstudio = rstudio, ...)
}
3 changes: 1 addition & 2 deletions R/posterior_survfit.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions R/posterior_traj.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions R/posterior_vs_prior.R
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
50 changes: 26 additions & 24 deletions man/launch_shinystan.stanreg.Rd → man/launch_shinystan.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/reexports.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading