Skip to content

Commit

Permalink
to CRAN
Browse files Browse the repository at this point in the history
  • Loading branch information
helske committed Aug 29, 2024
1 parent 6d81eab commit 0fec72b
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 10 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ Suggests:
testthat
Depends:
bayesplot,
R (>= 3.4.0)
R (>= 3.4.0),
rstan (>= 2.26.0)
Imports:
coda,
dplyr,
Expand All @@ -36,7 +37,6 @@ Imports:
Rcpp (>= 0.12.9),
RcppParallel,
rlang,
rstan (>= 2.26.0),
rstantools (>= 2.0.0)
LinkingTo:
BH (>= 1.66.0),
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions R/pp_check.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@
#' 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
#' @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]
Expand Down
4 changes: 2 additions & 2 deletions man/pp_check.walker_fit.Rd

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

5 changes: 2 additions & 3 deletions vignettes/walker.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 0fec72b

Please sign in to comment.