Perform unconditional posterior predictive checks with the help of the bayesplot package.
Usage
# S3 method for class 'mvgam'
pp_check(
object,
type,
ndraws = NULL,
prefix = c("ppc", "ppd"),
group = NULL,
x = NULL,
newdata = NULL,
...
)
Arguments
- object
An object of class
mvgam
.- type
Type of the ppc plot as given by a character string. See
PPC
for an overview of currently supported types. You may also use an invalid type (e.g.type = "xyz"
) to get a list of supported types in the resulting error message.- ndraws
Positive integer indicating how many posterior draws should be used. If
NULL
all draws are used. If not specified, the number of posterior draws is chosen automatically. Ignored ifdraw_ids
is notNULL
.- prefix
The prefix of the bayesplot function to be applied. Either `"ppc"` (posterior predictive check; the default) or `"ppd"` (posterior predictive distribution), the latter being the same as the former except that the observed data is not shown for `"ppd"`.
- group
Optional name of a factor variable in the model by which to stratify the ppc plot. This argument is required for ppc
*_grouped
types and ignored otherwise.- x
Optional name of a variable in the model. Only used for ppc types having an
x
argument and ignored otherwise.- newdata
Optional
dataframe
orlist
of test data containing the variables included in the linear predictor offormula
. If not supplied, predictions are generated for the original observations used for the model fit.- ...
Further arguments passed to
predict.mvgam
as well as to the PPC function specified intype
.
Details
Unlike the conditional posterior checks provided by ppc
,
This function computes unconditional posterior predictive checks (i.e. it generates
predictions for fake data without considering the true observations associated with those
fake data). For a detailed explanation of each of the ppc functions,
see the PPC
documentation of the bayesplot
package.
Examples
# \donttest{
simdat <- sim_mvgam(seasonality = 'hierarchical')
mod <- mvgam(y ~ series +
s(season, bs = 'cc', k = 6) +
s(season, series, bs = 'fs', k = 4),
data = simdat$data_train,
chains = 2,
silent = 2)
#> Warning: model has repeated 1-d smooths of same variable.
#> Warning: model has repeated 1-d smooths of same variable.
#> Warning: model has repeated 1-d smooths of same variable.
#> In file included from stan/lib/stan_math/stan/math/prim/prob/von_mises_lccdf.hpp:5,
#> from stan/lib/stan_math/stan/math/prim/prob/von_mises_ccdf_log.hpp:4,
#> from stan/lib/stan_math/stan/math/prim/prob.hpp:359,
#> from stan/lib/stan_math/stan/math/prim.hpp:16,
#> from stan/lib/stan_math/stan/math/rev.hpp:16,
#> from stan/lib/stan_math/stan/math.hpp:19,
#> from stan/src/stan/model/model_header.hpp:4,
#> from C:/Users/uqnclar2/AppData/Local/Temp/RtmpotLup8/model-9e8cfe450a0.hpp:2:
#> stan/lib/stan_math/stan/math/prim/prob/von_mises_cdf.hpp: In function 'stan::return_type_t<T_x, T_sigma, T_l> stan::math::von_mises_cdf(const T_x&, const T_mu&, const T_k&)':
#> stan/lib/stan_math/stan/math/prim/prob/von_mises_cdf.hpp:194: note: '-Wmisleading-indentation' is disabled from this point onwards, since column-tracking was disabled due to the size of the code/headers
#> 194 | if (cdf_n < 0.0)
#> |
#> stan/lib/stan_math/stan/math/prim/prob/von_mises_cdf.hpp:194: note: adding '-flarge-source-files' will allow for more column-tracking support, at the expense of compilation time and memory
# Use pp_check(mod, type = "xyz") for a list of available plot types
# Default is a density overlay for all observations
pp_check(mod)
#> Using 10 posterior draws for ppc type 'dens_overlay' by default.
# Rootograms particularly useful for count data
pp_check(mod, type = "rootogram")
#> Using all posterior draws for ppc type 'rootogram' by default.
# Grouping plots by series is useful
pp_check(mod, type = "bars_grouped",
group = "series", ndraws = 50)
pp_check(mod, type = "ecdf_overlay_grouped",
group = "series", ndraws = 50)
pp_check(mod, type = "stat_freqpoly_grouped",
group = "series", ndraws = 50)
#> Note: in most cases the default test statistic 'mean' is too weak to detect anything of interest.
#> `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
# Custom functions accepted
prop_zero <- function(x) mean(x == 0)
pp_check(mod, type = "stat", stat = "prop_zero")
#> Using all posterior draws for ppc type 'stat' by default.
#> Error in get(as.character(FUN), mode = "function", envir = envir): object 'prop_zero' of mode 'function' was not found
pp_check(mod, type = "stat_grouped",
stat = "prop_zero",
group = "series")
#> Using all posterior draws for ppc type 'stat_grouped' by default.
#> Error in get(as.character(FUN), mode = "function", envir = envir): object 'prop_zero' of mode 'function' was not found
# Some functions accept covariates to set the x-axes
pp_check(mod, x = "season",
type = "ribbon_grouped",
prob = 0.5,
prob_outer = 0.8,
group = "series")
#> Using all posterior draws for ppc type 'ribbon_grouped' by default.
# Many plots can be made without the observed data
pp_check(mod, prefix = "ppd")
#> Using 10 posterior draws for ppc type 'dens_overlay' by default.
# }