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.576263 -0.442657 -1.277570 -0.941167 -0.454183 0.3173160
#> 2 0.421946 -0.403229 -1.306820 -1.459220 -0.652293 -0.0942556
#> 3 0.427732 -0.511082 -1.396910 -1.436200 -0.741150 -0.0537835
#> 4 0.481900 -0.514655 -0.953897 -1.250180 -0.583693 0.0103624
#> 5 0.557969 -0.605313 -1.500150 -1.241990 -0.713826 -0.0339844
#> 6 0.452181 -0.650946 -1.280080 -1.230980 -0.833795 -0.1681980
#> s(season).6 s(season).7 s(season).8
#> 1 0.824204 0.721980 0.454141
#> 2 0.429512 0.772680 0.717363
#> 3 0.513967 0.830639 0.640509
#> 4 0.657579 1.103670 0.824368
#> 5 0.751659 1.023500 1.008320
#> 6 0.818845 1.260120 0.465691
str(beta_draws_df)
#> 'data.frame': 1000 obs. of 9 variables:
#> $ (Intercept): num 0.576 0.422 0.428 0.482 0.558 ...
#> $ s(season).1: num -0.443 -0.403 -0.511 -0.515 -0.605 ...
#> $ s(season).2: num -1.278 -1.307 -1.397 -0.954 -1.5 ...
#> $ s(season).3: num -0.941 -1.459 -1.436 -1.25 -1.242 ...
#> $ s(season).4: num -0.454 -0.652 -0.741 -0.584 -0.714 ...
#> $ s(season).5: num 0.3173 -0.0943 -0.0538 0.0104 -0.034 ...
#> $ s(season).6: num 0.824 0.43 0.514 0.658 0.752 ...
#> $ s(season).7: num 0.722 0.773 0.831 1.104 1.024 ...
#> $ s(season).8: num 0.454 0.717 0.641 0.824 1.008 ...
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.576263 -0.442657 -1.277570 -0.941167 -0.454183 0.3173160
#> 2 0.421946 -0.403229 -1.306820 -1.459220 -0.652293 -0.0942556
#> 3 0.427732 -0.511082 -1.396910 -1.436200 -0.741150 -0.0537835
#> 4 0.481900 -0.514655 -0.953897 -1.250180 -0.583693 0.0103624
#> 5 0.557969 -0.605313 -1.500150 -1.241990 -0.713826 -0.0339844
#> 6 0.452181 -0.650946 -1.280080 -1.230980 -0.833795 -0.1681980
#> variable
#> draw s(season).6 s(season).7 s(season).8
#> 1 0.824204 0.721980 0.454141
#> 2 0.429512 0.772680 0.717363
#> 3 0.513967 0.830639 0.640509
#> 4 0.657579 1.103670 0.824368
#> 5 0.751659 1.023500 1.008320
#> 6 0.818845 1.260120 0.465691
str(beta_draws_mat)
#> num [1:1000, 1:9] 0.576 0.422 0.428 0.482 0.558 ...
#> - 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.949103 0.676745 1.14757
#> 2 1.062070 0.789662 1.16521
#> 3 1.001270 0.777792 1.04710
#> 4 0.731076 1.121930 1.23934
#> 5 0.949215 1.020530 0.96095
#> 6 0.885994 0.930078 1.27962