Extract posterior draws in conventional formats as data.frames, matrices, or arrays.
Usage
# S3 method for class 'mvgam'
as.data.frame(
x,
row.names = NULL,
optional = TRUE,
variable = "betas",
use_alias = TRUE,
regex = FALSE,
...
)
# S3 method for class 'mvgam'
as.matrix(x, variable = "betas", regex = FALSE, use_alias = TRUE, ...)
# S3 method for class 'mvgam'
as.array(x, variable = "betas", regex = FALSE, use_alias = TRUE, ...)
# S3 method for class 'mvgam'
as_draws(
x,
variable = NULL,
regex = FALSE,
inc_warmup = FALSE,
use_alias = TRUE,
...
)
# S3 method for class 'mvgam'
as_draws_matrix(
x,
variable = NULL,
regex = FALSE,
inc_warmup = FALSE,
use_alias = TRUE,
...
)
# S3 method for class 'mvgam'
as_draws_df(
x,
variable = NULL,
regex = FALSE,
inc_warmup = FALSE,
use_alias = TRUE,
...
)
# S3 method for class 'mvgam'
as_draws_array(
x,
variable = NULL,
regex = FALSE,
inc_warmup = FALSE,
use_alias = TRUE,
...
)
# S3 method for class 'mvgam'
as_draws_list(
x,
variable = NULL,
regex = FALSE,
inc_warmup = FALSE,
use_alias = TRUE,
...
)
# S3 method for class 'mvgam'
as_draws_rvars(x, variable = NULL, regex = FALSE, inc_warmup = FALSE, ...)
Arguments
- x
list
object of classmvgam
- row.names
Ignored
- optional
Ignored
- variable
A character specifying which parameters to extract. Can either be one of the following options:
obs_params
(other parameters specific to the observation model, such as overdispsersions for negative binomial models or observation error SD for gaussian / student-t models)betas
(beta coefficients from the GAM observation model linear predictor; default)smooth_params
(smoothing parameters from the GAM observation model)linpreds
(estimated linear predictors on whatever link scale was used in the model)trend_params
(parameters governing the trend dynamics, such as AR parameters, trend SD parameters or Gaussian Process parameters)trend_betas
(beta coefficients from the GAM latent process model linear predictor; only available if atrend_formula
was supplied in the original model)trend_smooth_params
(process model GAM smoothing parameters; only available if atrend_formula
was supplied in the original model)trend_linpreds
(process model linear predictors on the identity scale; only available if atrend_formula
was supplied in the original model)
OR can be a character vector providing the variables to extract
- use_alias
Logical. If more informative names for parameters are available (i.e. for beta coefficients
b
or for smoothing parametersrho
), replace the uninformative names with the more informative alias. Defaults toTRUE
- regex
Logical. If not using one of the prespecified options for extractions, should
variable
be treated as a (vector of) regular expressions? Any variable in x matching at least one of the regular expressions will be selected. Defaults toFALSE
.- ...
Ignored
- inc_warmup
Should warmup draws be included? Defaults to
FALSE
.
Examples
# \donttest{
sim <- sim_mvgam(family = Gamma())
mod1 <- mvgam(y ~ s(season, bs = 'cc'),
trend_model = 'AR1',
data = sim$data_train,
family = Gamma(),
chains = 2,
silent = 2)
#> Warning: Supplying trend_model as a character string is deprecated
#> Please use the dedicated functions (i.e. RW() or ZMVN()) instead
#> This warning is displayed once per session.
#> 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-9e8c33d43f8.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
beta_draws_df <- as.data.frame(mod1, variable = 'betas')
head(beta_draws_df)
#> (Intercept) s(season).1 s(season).2 s(season).3 s(season).4 s(season).5 s(season).6 s(season).7 s(season).8
#> 1 0.319726 -0.972376 -1.148710 -0.734276 0.462118 1.59223 0.934666 0.399375 0.176647
#> 2 0.180193 -1.616300 -1.036090 -0.768414 0.655170 1.20669 0.844760 0.243960 0.868440
#> 3 0.304901 -1.073380 -1.322890 -0.503359 0.964529 1.30952 1.059640 0.516082 0.115212
#> 4 0.268791 -1.224270 -0.946018 -0.636852 0.379731 1.22659 0.803573 0.351586 0.719370
#> 5 0.245721 -0.968587 -1.256310 -0.893110 0.591861 1.64159 1.097970 0.255019 0.607658
#> 6 0.135226 -1.155560 -1.011880 -0.336560 0.623057 1.02631 0.844620 0.643441 0.583991
str(beta_draws_df)
#> 'data.frame': 1000 obs. of 9 variables:
#> $ (Intercept): num 0.32 0.18 0.305 0.269 0.246 ...
#> $ s(season).1: num -0.972 -1.616 -1.073 -1.224 -0.969 ...
#> $ s(season).2: num -1.149 -1.036 -1.323 -0.946 -1.256 ...
#> $ s(season).3: num -0.734 -0.768 -0.503 -0.637 -0.893 ...
#> $ s(season).4: num 0.462 0.655 0.965 0.38 0.592 ...
#> $ s(season).5: num 1.59 1.21 1.31 1.23 1.64 ...
#> $ s(season).6: num 0.935 0.845 1.06 0.804 1.098 ...
#> $ s(season).7: num 0.399 0.244 0.516 0.352 0.255 ...
#> $ s(season).8: num 0.177 0.868 0.115 0.719 0.608 ...
beta_draws_mat <- as.matrix(mod1, variable = 'betas')
head(beta_draws_mat)
#> variable
#> draw (Intercept) s(season).1 s(season).2 s(season).3 s(season).4 s(season).5 s(season).6 s(season).7
#> 1 0.319726 -0.972376 -1.148710 -0.734276 0.462118 1.59223 0.934666 0.399375
#> 2 0.180193 -1.616300 -1.036090 -0.768414 0.655170 1.20669 0.844760 0.243960
#> 3 0.304901 -1.073380 -1.322890 -0.503359 0.964529 1.30952 1.059640 0.516082
#> 4 0.268791 -1.224270 -0.946018 -0.636852 0.379731 1.22659 0.803573 0.351586
#> 5 0.245721 -0.968587 -1.256310 -0.893110 0.591861 1.64159 1.097970 0.255019
#> 6 0.135226 -1.155560 -1.011880 -0.336560 0.623057 1.02631 0.844620 0.643441
#> variable
#> draw s(season).8
#> 1 0.176647
#> 2 0.868440
#> 3 0.115212
#> 4 0.719370
#> 5 0.607658
#> 6 0.583991
str(beta_draws_mat)
#> num [1:1000, 1:9] 0.32 0.18 0.305 0.269 0.246 ...
#> - attr(*, "dimnames")=List of 2
#> ..$ draw : chr [1:1000] "1" "2" "3" "4" ...
#> ..$ variable: chr [1:9] "(Intercept)" "s(season).1" "s(season).2" "s(season).3" ...
#> - attr(*, "nchains")= int 2
shape_pars <- as.matrix(mod1, variable = 'shape', regex = TRUE)
head(shape_pars)# }
#> variable
#> draw shape[1] shape[2] shape[3]
#> 1 1.365670 0.973384 1.237680
#> 2 0.869383 1.512070 0.948521
#> 3 0.790533 1.020250 1.035100
#> 4 0.957937 1.139440 1.354040
#> 5 0.981846 0.952409 1.087680
#> 6 0.967652 1.438820 1.650290