Skip to contents

Converts the output from a dynamite() call to a draws_df format of the posterior package, enabling the use of diagnostics and plotting methods of posterior and bayesplot packages. Note that this function returns variables in a wide format, whereas as.data.frame() uses the long format.

Usage

# S3 method for dynamitefit
as_draws_df(
  x,
  parameters = NULL,
  responses = NULL,
  types = NULL,
  times = NULL,
  groups = NULL,
  ...
)

# S3 method for dynamitefit
as_draws(x, parameters = NULL, responses = NULL, types = NULL, ...)

Arguments

x

[dynamitefit]
The model fit object.

parameters

[character()]
Parameter(s) for which the samples should be extracted. Possible options can be found with function get_parameter_names(). Default is all parameters of specific type for all responses. This argument is mutually exclusive with types.

responses

[character()]
Response(s) for which the samples should be extracted. Possible options are elements of unique(x$priors$response), and the default is this entire vector. Ignored if the argument parameters is supplied. omega_alpha, and omega_psi. See also get_parameter_types().

types

[character()]
Type(s) of the parameters for which the samples should be extracted. See details of possible values. Default is all values listed in details except spline coefficients omega. This argument is mutually exclusive with parameters.

times

[double()]
Time point(s) to keep. If NULL (the default), all time points are kept.

groups

[character()] Group name(s) to keep. If NULL (the default), all groups are kept.

...

Ignored.

Value

A draws_df object.

A draws_df object.

Details

You can use the arguments parameters, responses and types to extract only a subset of the model parameters (i.e., only certain types of parameters related to a certain response variable).

See potential values for the types argument in as.data.frame.dynamitefit() and get_parameter_names() for potential values for parameters argument.

Examples

data.table::setDTthreads(1) # For CRAN
as_draws(gaussian_example_fit, types = c("sigma", "beta"))
#> # A draws_df: 100 iterations, 2 chains, and 2 variables
#>    beta_y_z sigma_y
#> 1       2.0    0.20
#> 2       2.0    0.20
#> 3       2.0    0.20
#> 4       1.9    0.19
#> 5       2.0    0.19
#> 6       2.0    0.20
#> 7       2.0    0.20
#> 8       2.0    0.20
#> 9       2.0    0.20
#> 10      2.0    0.20
#> # ... with 190 more draws
#> # ... hidden reserved variables {'.chain', '.iteration', '.draw'}

# Compute MCMC diagnostics using the posterior package
posterior::summarise_draws(as_draws(gaussian_example_fit))
#> # A tibble: 143 × 10
#>    variable      mean median     sd    mad      q5   q95  rhat ess_bulk ess_tail
#>    <chr>        <dbl>  <dbl>  <dbl>  <dbl>   <dbl> <dbl> <dbl>    <dbl>    <dbl>
#>  1 alpha_y[2]  0.0587 0.0604 0.0309 0.0286 0.00452 0.103 1.00      156.     188.
#>  2 alpha_y[3]  0.0951 0.0955 0.0411 0.0424 0.0336  0.160 1.01      206.     168.
#>  3 alpha_y[4]  0.171  0.169  0.0392 0.0317 0.103   0.233 1.01      252.     181.
#>  4 alpha_y[5]  0.264  0.263  0.0410 0.0438 0.199   0.326 0.998     229.     191.
#>  5 alpha_y[6]  0.304  0.298  0.0383 0.0370 0.250   0.372 1.00      246.     151.
#>  6 alpha_y[7]  0.336  0.334  0.0390 0.0400 0.276   0.400 1.02      153.     109.
#>  7 alpha_y[8]  0.422  0.424  0.0366 0.0349 0.365   0.481 1.00      119.     177.
#>  8 alpha_y[9]  0.458  0.456  0.0390 0.0417 0.392   0.520 1.00      157.     187.
#>  9 alpha_y[10] 0.418  0.419  0.0443 0.0435 0.350   0.492 1.01      178.     185.
#> 10 alpha_y[11] 0.407  0.409  0.0409 0.0426 0.340   0.473 1.00      247.     185.
#> # ℹ 133 more rows