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.374777 -0.733198 -1.36907 -0.519307 -0.211382 -0.676882
#> 2 0.427450 -0.425934 -1.32330 -0.617301 -0.201891 -1.480630
#> 3 0.430866 -0.340452 -1.36755 -0.480587 -0.819081 -0.804817
#> 4 0.430781 -0.389531 -1.33819 -0.504064 -0.784152 -0.814420
#> 5 0.424774 -0.397475 -1.40472 -0.586206 -0.706911 -0.805801
#> 6 0.420481 -0.655663 -1.34370 -0.783575 -0.324282 -1.158140
#> s(season).6 s(season).7 s(season).8
#> 1 -0.568080 0.780525 0.362101
#> 2 -0.777516 0.394582 0.780230
#> 3 -0.844599 0.853809 0.354951
#> 4 -0.912800 0.870433 0.341703
#> 5 -0.993340 0.882721 0.342518
#> 6 -0.673337 1.062960 1.102170
str(beta_draws_df)
#> 'data.frame': 1000 obs. of 9 variables:
#> $ (Intercept): num 0.375 0.427 0.431 0.431 0.425 ...
#> $ s(season).1: num -0.733 -0.426 -0.34 -0.39 -0.397 ...
#> $ s(season).2: num -1.37 -1.32 -1.37 -1.34 -1.4 ...
#> $ s(season).3: num -0.519 -0.617 -0.481 -0.504 -0.586 ...
#> $ s(season).4: num -0.211 -0.202 -0.819 -0.784 -0.707 ...
#> $ s(season).5: num -0.677 -1.481 -0.805 -0.814 -0.806 ...
#> $ s(season).6: num -0.568 -0.778 -0.845 -0.913 -0.993 ...
#> $ s(season).7: num 0.781 0.395 0.854 0.87 0.883 ...
#> $ s(season).8: num 0.362 0.78 0.355 0.342 0.343 ...
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.374777 -0.733198 -1.36907 -0.519307 -0.211382 -0.676882
#> 2 0.427450 -0.425934 -1.32330 -0.617301 -0.201891 -1.480630
#> 3 0.430866 -0.340452 -1.36755 -0.480587 -0.819081 -0.804817
#> 4 0.430781 -0.389531 -1.33819 -0.504064 -0.784152 -0.814420
#> 5 0.424774 -0.397475 -1.40472 -0.586206 -0.706911 -0.805801
#> 6 0.420481 -0.655663 -1.34370 -0.783575 -0.324282 -1.158140
#> variable
#> draw s(season).6 s(season).7 s(season).8
#> 1 -0.568080 0.780525 0.362101
#> 2 -0.777516 0.394582 0.780230
#> 3 -0.844599 0.853809 0.354951
#> 4 -0.912800 0.870433 0.341703
#> 5 -0.993340 0.882721 0.342518
#> 6 -0.673337 1.062960 1.102170
str(beta_draws_mat)
#> num [1:1000, 1:9] 0.375 0.427 0.431 0.431 0.425 ...
#> - 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.163980 1.209840 0.851010
#> 2 0.980268 0.826011 0.840381
#> 3 1.003790 1.296510 1.437170
#> 4 1.040720 1.318460 1.451680
#> 5 1.046620 1.356160 1.391470
#> 6 1.068660 0.874556 0.737471