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
listobject 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_formulawas supplied in the original model)trend_smooth_params(process model GAM smoothing parameters; only available if atrend_formulawas supplied in the original model)trend_linpreds(process model linear predictors on the identity scale; only available if atrend_formulawas 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
bor 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
variablebe treated as a (vector of) regular expressions? Any variable inxmatching at least one of the regular expressions will be selected. Defaults toFALSE.- ...
Ignored
- inc_warmup
Should warmup draws be included? Defaults to
FALSE.
Examples
# \dontrun{
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.2452890 0.01285524 -0.51776150 -0.2873461 0.4813628 -0.28129175
#> 2 -0.2151249 -0.28179816 -0.40120090 -0.1443851 0.3383181 -0.08195124
#> 3 -0.1834612 -0.42702035 -0.03561481 0.2901251 0.7828352 -0.71300732
#> 4 -0.2489673 -0.42481808 -0.71647388 -0.4567495 0.3048684 -0.21259523
#> 5 -0.2358745 -0.67891666 -0.30294272 0.2001917 0.6541277 -0.13093999
#> 6 -0.3013378 -0.25777654 0.53638336 -0.1614881 0.2968459 0.08606012
#> s(season).6 s(season).7 s(season).8
#> 1 -0.6839039 1.517470 1.329045
#> 2 -0.5933278 1.706649 1.880091
#> 3 -0.6255581 1.214356 1.219581
#> 4 -0.6827657 1.401059 1.416865
#> 5 0.2337904 1.687697 1.528636
#> 6 -0.3030606 1.173501 1.769321
str(beta_draws_df)
#> 'data.frame': 1000 obs. of 9 variables:
#> $ (Intercept): num -0.245 -0.215 -0.183 -0.249 -0.236 ...
#> $ s(season).1: num 0.0129 -0.2818 -0.427 -0.4248 -0.6789 ...
#> $ s(season).2: num -0.5178 -0.4012 -0.0356 -0.7165 -0.3029 ...
#> $ s(season).3: num -0.287 -0.144 0.29 -0.457 0.2 ...
#> $ s(season).4: num 0.481 0.338 0.783 0.305 0.654 ...
#> $ s(season).5: num -0.281 -0.082 -0.713 -0.213 -0.131 ...
#> $ s(season).6: num -0.684 -0.593 -0.626 -0.683 0.234 ...
#> $ s(season).7: num 1.52 1.71 1.21 1.4 1.69 ...
#> $ s(season).8: num 1.33 1.88 1.22 1.42 1.53 ...
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.2452890 0.01285524 -0.51776150 -0.2873461 0.4813628 -0.28129175
#> 2 -0.2151249 -0.28179816 -0.40120090 -0.1443851 0.3383181 -0.08195124
#> 3 -0.1834612 -0.42702035 -0.03561481 0.2901251 0.7828352 -0.71300732
#> 4 -0.2489673 -0.42481808 -0.71647388 -0.4567495 0.3048684 -0.21259523
#> 5 -0.2358745 -0.67891666 -0.30294272 0.2001917 0.6541277 -0.13093999
#> 6 -0.3013378 -0.25777654 0.53638336 -0.1614881 0.2968459 0.08606012
#> variable
#> draw s(season).6 s(season).7 s(season).8
#> 1 -0.6839039 1.517470 1.329045
#> 2 -0.5933278 1.706649 1.880091
#> 3 -0.6255581 1.214356 1.219581
#> 4 -0.6827657 1.401059 1.416865
#> 5 0.2337904 1.687697 1.528636
#> 6 -0.3030606 1.173501 1.769321
str(beta_draws_mat)
#> num [1:1000, 1:9] -0.245 -0.215 -0.183 -0.249 -0.236 ...
#> - 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.0130741 1.569754 1.312474
#> 2 1.0268845 1.283426 1.461180
#> 3 0.7911629 1.083003 1.698872
#> 4 1.0020945 1.216057 1.435758
#> 5 1.1094882 1.196264 1.006714
#> 6 0.6688279 1.020592 1.411370
# }
