Skip to content
Merged
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: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -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.2.3
RoxygenNote: 7.3.2
2 changes: 1 addition & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,6 @@ importFrom(ggplot2,scale_x_discrete)
importFrom(ggplot2,theme)
importFrom(ggplot2,theme_bw)
importFrom(ggplot2,xlab)
importFrom(reformulas,findbars)
importFrom(lme4,fixef)
importFrom(lme4,glFormula)
importFrom(lme4,glmer)
Expand Down Expand Up @@ -262,6 +261,7 @@ importFrom(posterior,as_draws_df)
importFrom(posterior,as_draws_list)
importFrom(posterior,as_draws_matrix)
importFrom(posterior,as_draws_rvars)
importFrom(reformulas,findbars)
importFrom(rstan,constrain_pars)
importFrom(rstan,extract)
importFrom(rstan,extract_sparse_parts)
Expand Down
5 changes: 1 addition & 4 deletions R/doc-rstanarm-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@

#' Applied Regression Modeling via RStan
#'
#' @docType package
#' @name rstanarm-package
#' @aliases rstanarm
#' @useDynLib rstanarm, .registration = TRUE
#'
#' @import methods
Expand Down Expand Up @@ -104,4 +101,4 @@
#' @template reference-bayesvis
#' @template reference-muth
#'
NULL
"_PACKAGE"
3 changes: 3 additions & 0 deletions R/jm_make_assoc_terms.R
Original file line number Diff line number Diff line change
Expand Up @@ -388,9 +388,11 @@ get_element <- function(parts, m = 1, which = "eta", ...) {
# @param grp_assoc Character string, the function to use to collapse
# across the lower level units clustered within individuals.
# @return A vector or matrix, depending on the method called.
#' @noRd
collapse_within_groups <- function(eta, grp_idx, grp_assoc = "sum") {
UseMethod("collapse_within_groups")
}
#' @exportS3Method NULL
collapse_within_groups.default <- function(eta, grp_idx, grp_assoc) {
N <- nrow(grp_idx)
val <- rep(NA, N)
Expand All @@ -400,6 +402,7 @@ collapse_within_groups.default <- function(eta, grp_idx, grp_assoc) {
}
val
}
#' @exportS3Method NULL
collapse_within_groups.matrix <- function(eta, grp_idx, grp_assoc) {
N <- nrow(grp_idx)
val <- matrix(NA, nrow = nrow(eta), ncol = N)
Expand Down
2 changes: 1 addition & 1 deletion R/launch_shinystan.R
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
#' 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-package]{shinystan}} package documentation for more
#' \pkg{\link[shinystan:shinystan-package]{shinystan}} package documentation for more
#' information.
#'
#' @section Faster launch times:
Expand Down
6 changes: 6 additions & 0 deletions R/log_lik.R
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,9 @@ ll_fun <- function(x, m = NULL) {
# just a single MCMC draw).
# @return a named list with elements data, draws, S (posterior sample size) and
# N = number of observations
#' @noRd
ll_args <- function(object, ...) UseMethod("ll_args")
#' @exportS3Method NULL
ll_args.stanreg <- function(object, newdata = NULL, offset = NULL, m = NULL,
reloo_or_kfold = FALSE, ...) {
validate_stanreg_object(object)
Expand Down Expand Up @@ -511,6 +513,7 @@ ll_args.stanreg <- function(object, newdata = NULL, offset = NULL, m = NULL,
# @param pars Output from extract_pars
# @param m Integer specifying which submodel
# @param reloo_or_kfold logical. TRUE if ll_args is for reloo or kfold
#' @exportS3Method NULL
ll_args.stanjm <- function(object, data, pars, m = 1,
reloo_or_kfold = FALSE, ...) {
validate_stanjm_object(object)
Expand Down Expand Up @@ -863,10 +866,12 @@ evaluate_log_basehaz <- function(times, basehaz, coefs) {
# at which the log hazard was evaluated for each individual.
# @param qwts A vector of unstandardised GK quadrature weights.
# @return A vector or matrix of log survival probabilities.
#' @noRd
evaluate_log_survival <- function(log_haz, qnodes, qwts) {
UseMethod("evaluate_log_survival")
}

#' @exportS3Method NULL
evaluate_log_survival.default <- function(log_haz, qnodes, qwts) {
# convert log hazard to hazard
haz <- exp(log_haz)
Expand All @@ -879,6 +884,7 @@ evaluate_log_survival.default <- function(log_haz, qnodes, qwts) {
-cum_haz
}

#' @exportS3Method NULL
evaluate_log_survival.matrix <- function(log_haz, qnodes, qwts) {
# convert log hazard to hazard
haz <- exp(log_haz)
Expand Down
1 change: 1 addition & 0 deletions R/loo-prediction.R
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ loo_predictive_interval.stanreg <-

# internal ----------------------------------------------------------------

#' @exportS3Method NULL
psis.stanreg <- function(log_ratios, ...) {
object <- log_ratios
message("Running PSIS to compute weights...")
Expand Down
6 changes: 3 additions & 3 deletions R/loo.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#'
#' @description For models fit using MCMC, compute approximate leave-one-out
#' cross-validation (LOO, LOOIC) or, less preferably, the Widely Applicable
#' Information Criterion (WAIC) using the \pkg{\link[=loo-package]{loo}}
#' Information Criterion (WAIC) using the \pkg{\link[loo:loo-package]{loo}}
#' package. (For \eqn{K}-fold cross-validation see \code{\link{kfold.stanreg}}.)
#' Functions for model comparison, and model weighting/averaging are also
#' provided.
Expand Down Expand Up @@ -74,7 +74,7 @@
#' package).
#'
#' @section Approximate LOO CV: The \code{loo} method for stanreg objects
#' provides an interface to the \pkg{\link[=loo-package]{loo}} package for
#' provides an interface to the \pkg{\link[loo:loo-package]{loo}} package for
#' approximate leave-one-out cross-validation (LOO). The LOO Information
#' Criterion (LOOIC) has the same purpose as the Akaike Information Criterion
#' (AIC) that is used by frequentists. Both are intended to estimate the
Expand All @@ -96,7 +96,7 @@
#' observations. Warnings about Pareto \eqn{k} estimates indicate observations
#' for which the approximation to LOO is problematic (this is described in
#' detail in Vehtari, Gelman, and Gabry (2017) and the
#' \pkg{\link[=loo-package]{loo}} package documentation). The
#' \pkg{\link[loo:loo-package]{loo}} package documentation). The
#' \code{k_threshold} argument can be used to set the \eqn{k} value above
#' which an observation is flagged. If \code{k_threshold} is not \code{NULL}
#' and there are \eqn{J} observations with \eqn{k} estimates above
Expand Down
10 changes: 9 additions & 1 deletion R/misc.R
Original file line number Diff line number Diff line change
Expand Up @@ -545,16 +545,19 @@ set_prior_scale <- function(scale, default, link) {
# @param x Predictor matrix.
# @param offset Optional offset vector.
# @return A vector or matrix.
#' @noRd
linear_predictor <- function(beta, x, offset = NULL) {
UseMethod("linear_predictor")
}
#' @exportS3Method NULL
linear_predictor.default <- function(beta, x, offset = NULL) {
eta <- as.vector(if (NCOL(x) == 1L) x * beta else x %*% beta)
if (length(offset))
eta <- eta + offset

return(eta)
}
#' @exportS3Method NULL
linear_predictor.matrix <- function(beta, x, offset = NULL) {
if (NCOL(beta) == 1L)
beta <- as.matrix(beta)
Expand Down Expand Up @@ -630,19 +633,24 @@ get_z.stanmvreg <- function(object, m = NULL, ...) {
# @param x A stanreg object, family object, or string.
# @param ... Other arguments passed to methods. For a \code{stanmvreg} object
# this can be an integer \code{m} specifying the submodel.
# @return The inverse link function associated with x.
# @return The inverse link function associated with x
#' @noRd
linkinv <- function(x, ...) UseMethod("linkinv")
#' @exportS3Method NULL
linkinv.stanreg <- function(x, ...) {
if (is(x, "polr")) polr_linkinv(x) else family(x)$linkinv
}
#' @exportS3Method NULL
linkinv.stanmvreg <- function(x, m = NULL, ...) {
ret <- lapply(family(x), `[[`, "linkinv")
stub <- get_stub(x)
if (!is.null(m)) ret[[m]] else list_nms(ret, stub = stub)
}
#' @exportS3Method NULL
linkinv.family <- function(x, ...) {
x$linkinv
}
#' @exportS3Method NULL
linkinv.character <- function(x, ...) {
stopifnot(length(x) == 1)
polr_linkinv(x)
Expand Down
2 changes: 1 addition & 1 deletion R/plots.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#'
#' The \code{plot} method for \link{stanreg-objects} provides a convenient
#' interface to the \link[bayesplot:MCMC-overview]{MCMC} module in the
#' \pkg{\link{bayesplot}} package for plotting MCMC draws and diagnostics. It is also
#' \pkg{\link[bayesplot:bayesplot-package]{bayesplot}} package for plotting MCMC draws and diagnostics. It is also
#' straightforward to use the functions from the \pkg{bayesplot} package directly rather than
#' via the \code{plot} method. Examples of both methods of plotting are given
#' below.
Expand Down
4 changes: 2 additions & 2 deletions R/pp_check.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#' Graphical posterior predictive checks
#'
#' Interface to the \link[bayesplot:PPC-overview]{PPC} (posterior predictive checking) module
#' in the \pkg{\link{bayesplot}} package, providing various plots comparing the
#' in the \pkg{\link[bayesplot:bayesplot-package]{bayesplot}} package, providing various plots comparing the
#' observed outcome variable \eqn{y} to simulated datasets \eqn{y^{rep}}{yrep}
#' from the posterior predictive distribution. The \code{pp_check} method for
#' \link{stanreg-objects} prepares the arguments required for the specified
Expand Down Expand Up @@ -51,7 +51,7 @@
#' overlay many \code{yrep} datasets (e.g., \code{ppc_dens_overlay}) a larger
#' number is used by default, and for other functions (e.g. \code{ppc_stat})
#' the default is to set \code{nreps} equal to the posterior sample size.
#' @param ... Additonal arguments passed to the \pkg{\link{bayesplot}} function
#' @param ... Additonal arguments passed to the \pkg{\link[bayesplot:bayesplot-package]{bayesplot}} function
#' called. For many plotting functions \code{...} is optional, however for
#' functions that require a \code{group} or \code{x} argument, these arguments
#' should be specified in \code{...}. If specifying \code{group} and/or
Expand Down
1 change: 1 addition & 0 deletions R/predictive_error.R
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ predictive_error.ppd <- function(object, y, ...) {
# is available. The argument \code{u} specifies the time at which the
# prediction error should be calculated (i.e. the time horizon).
#
#' @exportS3Method NULL
predictive_error.stanmvreg <-
function(object,
newdataLong = NULL,
Expand Down
2 changes: 1 addition & 1 deletion R/stan_biglm.R
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
#' outcome, such observations do not contribute to these statistics.
#'
#' @return The output of both \code{stan_biglm} and \code{stan_biglm.fit} is an
#' object of \code{\link[rstan]{stanfit-class}} rather than
#' object of \code{\link[rstan:stanfit-class]{stanfit-class}} rather than
#' \code{\link{stanreg-objects}}, which is more limited and less convenient
#' but necessitated by the fact that \code{stan_biglm} does not bring the full
#' design matrix into memory. Without the full design matrix,some of the
Expand Down
6 changes: 5 additions & 1 deletion R/stan_glm.fit.R
Original file line number Diff line number Diff line change
Expand Up @@ -902,14 +902,18 @@ pad_reTrms <- function(Ztlist, cnms, flist) {
# stats)
# @param columns Do the columns (TRUE) or rows (FALSE) correspond to the
# variables?

#' @noRd
unpad_reTrms <- function(x, ...) UseMethod("unpad_reTrms")
#' @exportS3Method NULL
unpad_reTrms.default <- function(x, ...) {
if (is.matrix(x) || is.array(x))
return(unpad_reTrms.array(x, ...))
keep <- !grepl("_NEW_", names(x), fixed = TRUE)
x[keep]
}

#' @exportS3Method NULL
unpad_reTrms.array <- function(x, columns = TRUE, ...) {
ndim <- length(dim(x))
if (ndim > 3)
Expand Down Expand Up @@ -943,7 +947,7 @@ make_b_nms <- function(group, m = NULL, stub = "Long") {
levels(group$flist[[nm]])))))
}
}
return(b_nms)
return(b_nms)
}


Expand Down
2 changes: 1 addition & 1 deletion R/stanreg-objects.R
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
#' A list with information about the prior distributions used.
#' }
#' \item{\code{stanfit,stan_summary}}{
#' The object of \code{\link[rstan]{stanfit-class}} returned by RStan and a
#' The object of \code{\link[rstan:stanfit-class]{stanfit-class}} returned by RStan and a
#' matrix of various summary statistics from the stanfit object.
#' }
#' \item{\code{rstan_version}}{
Expand Down
3 changes: 3 additions & 0 deletions R/stanreg_list.R
Original file line number Diff line number Diff line change
Expand Up @@ -277,9 +277,11 @@ stanreg_list_families <- function(mods) {
# when a stanreg_list is created those attributes should be changed to match
# the names of the models used for the stanreg_list in case user has specified
# the model_names argument
#' @noRd
rename_loos <- function(x,...) UseMethod("rename_loos")

# Change model_name attributes of a loo/waic/kfold object stored in a stanreg object,
#' @exportS3Method NULL
rename_loos.stanreg <- function(x, new_model_name,...) {
for (criterion in c("loo", "waic", "kfold")) {
if (!is.null(x[[criterion]])) {
Expand All @@ -291,6 +293,7 @@ rename_loos.stanreg <- function(x, new_model_name,...) {

# Change model_name attributes of loo/waic/kfold objects to correspond to
# model names used for stanreg_list
#' @exportS3Method NULL
rename_loos.stanreg_list <- function(x, ...) {
for (j in seq_along(x)) {
x[[j]] <- rename_loos.stanreg(x[[j]], new_model_name = names(x)[j])
Expand Down
2 changes: 1 addition & 1 deletion man-roxygen/return-stanfit-object.R
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#' @return A \link[=stanfit-class]{stanfit} object (or a slightly modified
#' @return A \link[rstan:stanfit-class]{stanfit} object (or a slightly modified
#' stanfit object) is returned if \code{<%= fitfun %>} is called directly.
Loading