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 overdispersions 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 inx
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 = AR(),
data = sim$data_train,
family = Gamma(),
chains = 2,
silent = 2
)
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.5025980 -0.7827030 -1.0268788 -0.33701607 -0.7003113 -1.0724193
#> 2 -0.4240708 -0.7312055 -1.0078061 -0.55077646 -0.6820690 -1.0619843
#> 3 -0.4843125 -1.1989016 -0.8566230 -0.05163683 -0.9025594 -1.0376859
#> 4 -0.4416774 -0.8791651 -0.9803522 -0.30640490 -0.6937490 -1.2859497
#> 5 -0.4733287 -0.9585875 -0.7680642 -0.60853035 -0.7631522 -0.8361333
#> 6 -0.5350380 -1.0103484 -0.8463303 -0.40259092 -0.4542488 -0.8132366
#> s(season).6 s(season).7 s(season).8
#> 1 0.29107993 1.156613 1.090091
#> 2 0.44169062 1.260926 1.218743
#> 3 0.17737118 1.277395 1.139428
#> 4 0.27329722 1.876226 1.319036
#> 5 0.30662501 1.253768 1.356868
#> 6 -0.05937789 1.308004 1.125758
str(beta_draws_df)
#> 'data.frame': 1000 obs. of 9 variables:
#> $ (Intercept): num -0.503 -0.424 -0.484 -0.442 -0.473 ...
#> $ s(season).1: num -0.783 -0.731 -1.199 -0.879 -0.959 ...
#> $ s(season).2: num -1.027 -1.008 -0.857 -0.98 -0.768 ...
#> $ s(season).3: num -0.337 -0.5508 -0.0516 -0.3064 -0.6085 ...
#> $ s(season).4: num -0.7 -0.682 -0.903 -0.694 -0.763 ...
#> $ s(season).5: num -1.072 -1.062 -1.038 -1.286 -0.836 ...
#> $ s(season).6: num 0.291 0.442 0.177 0.273 0.307 ...
#> $ s(season).7: num 1.16 1.26 1.28 1.88 1.25 ...
#> $ s(season).8: num 1.09 1.22 1.14 1.32 1.36 ...
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.5025980 -0.7827030 -1.0268788 -0.33701607 -0.7003113 -1.0724193
#> 2 -0.4240708 -0.7312055 -1.0078061 -0.55077646 -0.6820690 -1.0619843
#> 3 -0.4843125 -1.1989016 -0.8566230 -0.05163683 -0.9025594 -1.0376859
#> 4 -0.4416774 -0.8791651 -0.9803522 -0.30640490 -0.6937490 -1.2859497
#> 5 -0.4733287 -0.9585875 -0.7680642 -0.60853035 -0.7631522 -0.8361333
#> 6 -0.5350380 -1.0103484 -0.8463303 -0.40259092 -0.4542488 -0.8132366
#> variable
#> draw s(season).6 s(season).7 s(season).8
#> 1 0.29107993 1.156613 1.090091
#> 2 0.44169062 1.260926 1.218743
#> 3 0.17737118 1.277395 1.139428
#> 4 0.27329722 1.876226 1.319036
#> 5 0.30662501 1.253768 1.356868
#> 6 -0.05937789 1.308004 1.125758
str(beta_draws_mat)
#> num [1:1000, 1:9] -0.503 -0.424 -0.484 -0.442 -0.473 ...
#> - 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.9286332 1.1323238 1.0660495
#> 2 0.9037884 1.3053858 1.1128424
#> 3 1.0161214 0.8283651 1.4765451
#> 4 0.8281422 1.0210119 0.9772779
#> 5 0.9120305 0.9912393 1.1500921
#> 6 1.3459324 0.7812307 1.4277616
# }