Extract posterior draws in conventional formats as data.frames, matrices, or arrays.
Usage
# S3 method for mvgam
as.data.frame(
x,
row.names = NULL,
optional = TRUE,
variable = "betas",
use_alias = TRUE,
regex = FALSE,
...
)
# S3 method for mvgam
as.matrix(x, variable = "betas", regex = FALSE, use_alias = TRUE, ...)
# S3 method for mvgam
as.array(x, variable = "betas", regex = FALSE, use_alias = TRUE, ...)
# S3 method for mvgam
as_draws(
x,
variable = NULL,
regex = FALSE,
inc_warmup = FALSE,
use_alias = TRUE,
...
)
# S3 method for mvgam
as_draws_matrix(
x,
variable = NULL,
regex = FALSE,
inc_warmup = FALSE,
use_alias = TRUE,
...
)
# S3 method for mvgam
as_draws_df(
x,
variable = NULL,
regex = FALSE,
inc_warmup = FALSE,
use_alias = TRUE,
...
)
# S3 method for mvgam
as_draws_array(
x,
variable = NULL,
regex = FALSE,
inc_warmup = FALSE,
use_alias = TRUE,
...
)
# S3 method for mvgam
as_draws_list(
x,
variable = NULL,
regex = FALSE,
inc_warmup = FALSE,
use_alias = TRUE,
...
)
# S3 method for 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.
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
#> 1 -0.353504 -0.689050 -0.569322 -0.575858 -1.371480 -1.105750
#> 2 -0.232598 -0.960875 -1.254680 -0.607996 -0.485409 -0.927434
#> 3 -0.256430 -0.544463 -0.547713 -0.303771 -0.880145 -1.006270
#> 4 -0.387541 -0.803845 -0.717207 -0.361456 -0.621591 -0.938000
#> 5 -0.362899 -0.894899 -0.987886 -0.296254 -0.601298 -0.850040
#> 6 -0.546862 -1.158410 -0.810319 -0.104869 -0.502544 -0.947640
#> s(season).6 s(season).7 s(season).8
#> 1 -0.0458155 1.322900 1.223280
#> 2 0.6518560 1.589380 1.546970
#> 3 0.0399270 0.888902 1.201810
#> 4 0.2452860 1.235170 1.172150
#> 5 0.3553680 1.343760 1.631200
#> 6 0.1361850 1.176060 0.882254
str(beta_draws_df)
#> 'data.frame': 1000 obs. of 9 variables:
#> $ (Intercept): num -0.354 -0.233 -0.256 -0.388 -0.363 ...
#> $ s(season).1: num -0.689 -0.961 -0.544 -0.804 -0.895 ...
#> $ s(season).2: num -0.569 -1.255 -0.548 -0.717 -0.988 ...
#> $ s(season).3: num -0.576 -0.608 -0.304 -0.361 -0.296 ...
#> $ s(season).4: num -1.371 -0.485 -0.88 -0.622 -0.601 ...
#> $ s(season).5: num -1.106 -0.927 -1.006 -0.938 -0.85 ...
#> $ s(season).6: num -0.0458 0.6519 0.0399 0.2453 0.3554 ...
#> $ s(season).7: num 1.323 1.589 0.889 1.235 1.344 ...
#> $ s(season).8: num 1.22 1.55 1.2 1.17 1.63 ...
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
#> 1 -0.353504 -0.689050 -0.569322 -0.575858 -1.371480 -1.105750
#> 2 -0.232598 -0.960875 -1.254680 -0.607996 -0.485409 -0.927434
#> 3 -0.256430 -0.544463 -0.547713 -0.303771 -0.880145 -1.006270
#> 4 -0.387541 -0.803845 -0.717207 -0.361456 -0.621591 -0.938000
#> 5 -0.362899 -0.894899 -0.987886 -0.296254 -0.601298 -0.850040
#> 6 -0.546862 -1.158410 -0.810319 -0.104869 -0.502544 -0.947640
#> variable
#> draw s(season).6 s(season).7 s(season).8
#> 1 -0.0458155 1.322900 1.223280
#> 2 0.6518560 1.589380 1.546970
#> 3 0.0399270 0.888902 1.201810
#> 4 0.2452860 1.235170 1.172150
#> 5 0.3553680 1.343760 1.631200
#> 6 0.1361850 1.176060 0.882254
str(beta_draws_mat)
#> num [1:1000, 1:9] -0.354 -0.233 -0.256 -0.388 -0.363 ...
#> - 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 0.846726 0.976745 1.13466
#> 2 1.182200 0.897973 1.11273
#> 3 0.921552 0.804747 1.35359
#> 4 0.805043 0.645764 1.54151
#> 5 1.086330 1.192900 1.10186
#> 6 1.122770 0.759956 1.62497