From 0fec72bc5d44852b306cc829d9d660294b716366 Mon Sep 17 00:00:00 2001 From: Jouni Helske Date: Thu, 29 Aug 2024 13:09:16 +0300 Subject: [PATCH] to CRAN --- DESCRIPTION | 4 ++-- NAMESPACE | 1 + R/pp_check.R | 6 +++--- man/pp_check.walker_fit.Rd | 4 ++-- vignettes/walker.Rmd | 5 ++--- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 5dabe01..a392691 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -24,7 +24,8 @@ Suggests: testthat Depends: bayesplot, - R (>= 3.4.0) + R (>= 3.4.0), + rstan (>= 2.26.0) Imports: coda, dplyr, @@ -36,7 +37,6 @@ Imports: Rcpp (>= 0.12.9), RcppParallel, rlang, - rstan (>= 2.26.0), rstantools (>= 2.0.0) LinkingTo: BH (>= 1.66.0), diff --git a/NAMESPACE b/NAMESPACE index 80f06d8..7b178d9 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -34,6 +34,7 @@ importFrom(RcppParallel,CxxFlags) importFrom(RcppParallel,RcppParallelLibs) importFrom(bayesplot,color_scheme_get) importFrom(bayesplot,pp_check) +importFrom(bayesplot,ppc_ribbon) importFrom(bayesplot,theme_default) importFrom(coda,spectrum0.ar) importFrom(dplyr,group_by) diff --git a/R/pp_check.R b/R/pp_check.R index f2f24b7..e15246d 100644 --- a/R/pp_check.R +++ b/R/pp_check.R @@ -6,7 +6,7 @@ #' For other types of posterior predictive checks for example with `bayesplot`, #' you can extract the variable `yrep` from the output, see examples. #' -#' @importFrom bayesplot pp_check +#' @importFrom bayesplot pp_check ppc_ribbon #' @param object An output from [walker()]. #' @param ... Further parameters to [bayesplot::ppc_ribbon()]. #' @export @@ -14,10 +14,10 @@ #' \dontrun{ #' # Extracting the yrep variable for general use: #' # extract yrep -#' y_rep <- rstan::extract(object$stanfit, pars = "y_rep", permuted = TRUE)$y_rep +#' y_rep <- extract(object$stanfit, pars = "y_rep", permuted = TRUE)$y_rep #' #' # For non-gaussian model: -#' weights <- rstan::extract(object$stanfit, +#' weights <- extract(object$stanfit, #' pars = "weights", permuted = TRUE)$weights #' y_rep <- y_rep[sample(1:nrow(y_rep), #' size = nrow(y_rep), replace = TRUE, prob = weights), , drop = FALSE] diff --git a/man/pp_check.walker_fit.Rd b/man/pp_check.walker_fit.Rd index 845ff0c..45e3a2f 100644 --- a/man/pp_check.walker_fit.Rd +++ b/man/pp_check.walker_fit.Rd @@ -22,10 +22,10 @@ you can extract the variable \code{yrep} from the output, see examples. \dontrun{ # Extracting the yrep variable for general use: # extract yrep -y_rep <- rstan::extract(object$stanfit, pars = "y_rep", permuted = TRUE)$y_rep +y_rep <- extract(object$stanfit, pars = "y_rep", permuted = TRUE)$y_rep # For non-gaussian model: -weights <- rstan::extract(object$stanfit, +weights <- extract(object$stanfit, pars = "weights", permuted = TRUE)$weights y_rep <- y_rep[sample(1:nrow(y_rep), size = nrow(y_rep), replace = TRUE, prob = weights), , drop = FALSE] diff --git a/vignettes/walker.Rmd b/vignettes/walker.Rmd index 7aca624..e52ef46 100644 --- a/vignettes/walker.Rmd +++ b/vignettes/walker.Rmd @@ -72,14 +72,13 @@ The output of `walker` is `walker_fit` object, which is essentially a list with ```{r pars} print(fit$stanfit, pars = c("sigma_y", "sigma_rw1")) -library(bayesplot) mcmc_areas(as.matrix(fit$stanfit), regex_pars = c("sigma_y", "sigma_rw1")) ``` Let's check how well our estimates of $\beta$ coincide with the true values (the solid lines correspond to true values): ```{r plot_with_true_betas} -betas <- summary(fit$stanfit, "beta_rw")$summary[, "mean"] +betas <- rstan::summary(fit$stanfit, "beta_rw")$summary[, "mean"] ts.plot(cbind(rw, beta1, beta2, matrix(betas, ncol = 3)), col = rep(1:3, 2), lty = rep(1:2, each = 3)) @@ -138,7 +137,7 @@ $$ This is essentially local linear trend model [@harvey] with restriction that there is no noise on the $\beta$ level. This model can be estimated by switching `rw1` function inside of the walker formula to `rw2`, with almost identical interface, but now $\sigma$ correspond to the standard deviations of the slope terms $\nu$. The Gaussian prior for $\nu_1$ most also be defined. Using RW2 model, the coefficient estimates of our example model are clearly smoother: ```{r walker_rw2} -fit_rw2 <-walker(y ~ -1 + +fit_rw2 <- walker(y ~ -1 + rw2(~ x1 + x2, beta = c(0, 10), sigma = c(2, 0.001), nu = c(0, 10)), refresh = 0, init = 0, chains = 1, sigma_y = c(2, 0.001)) plot_coefs(fit_rw2, scales = "free") + ggplot2::theme_bw()