as.data.frame.dynamitefit {dynamite}R Documentation

Extract Samples From a dynamitefit Object as a Data Frame

Description

Provides a data.frame representation of the posterior samples of the model parameters.

Usage

## S3 method for class 'dynamitefit'
as.data.frame(
  x,
  row.names = NULL,
  optional = FALSE,
  parameters = NULL,
  responses = NULL,
  types = NULL,
  summary = FALSE,
  probs = c(0.05, 0.95),
  include_fixed = TRUE,
  ...
)

Arguments

x

[dynamitefit]
The model fit object.

row.names

Ignored.

optional

Ignored.

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.

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.

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, omega_alpha, and omega_psi. See also get_parameter_types(). Ignored if the argument parameters is supplied.

summary

[logical(1)]
If TRUE, returns posterior mean, standard deviation, and posterior quantiles (as defined by the probs argument) for all parameters. If FALSE (default), returns the posterior samples instead.

probs

[numeric()]
Quantiles of interest. Default is c(0.05, 0.95).

include_fixed

[logical(1)]
If TRUE (default), time-varying parameters for 1:fixed time points are included in the output as NA values. If FALSE, fixed time points are omitted completely from the output.

...

Ignored.

Details

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

Potential values for the types argument are:

Value

A tibble containing either samples or summary statistics of the model parameters in a long format. For a wide format, see as_draws().

See Also

Model outputs as.data.table.dynamitefit(), as_draws_df.dynamitefit(), coef.dynamitefit(), confint.dynamitefit(), dynamite(), get_code(), get_data(), get_parameter_dims(), get_parameter_names(), get_parameter_types(), ndraws.dynamitefit(), nobs.dynamitefit()

Examples

data.table::setDTthreads(1) # For CRAN
as.data.frame(
  gaussian_example_fit,
  responses = "y",
  types = "beta"
)

# Basic summaries can be obtained automatically with summary = TRUE
as.data.frame(
  gaussian_example_fit,
  responses = "y",
  types = "beta",
  summary = TRUE
)

# Time-varying coefficients "delta"
as.data.frame(
  gaussian_example_fit,
  responses = "y",
  types = "delta",
  summary = TRUE
)

# Obtain summaries for a specific parameters
as.data.frame(
  gaussian_example_fit,
  parameters = c("tau_y_x", "sigma_y"),
  summary = TRUE
)


[Package dynamite version 1.4.9 Index]