compare_gvar {tsnet}R Documentation

Compare two Bayesian GVAR models

Description

This function compares two Bayesian Graphical Vector Autoregressive models using matrix norms to test if the observed differences between two models is reliable. It computes the empirical distance between two models based on their point estimates and compares them using reference distributions created from their posterior distributions. Returns the p-value for the comparison based on a decision rule specified by the user. Details are available in Siepe, Kloft & Heck (2024) <doi:10.31234/osf.io/uwfjc>.

Usage

compare_gvar(
  fit_a,
  fit_b,
  cutoff = 5,
  dec_rule = "or",
  n_draws = 1000,
  comp = "frob",
  return_all = FALSE,
  sampling_method = "random",
  indices = NULL,
  burnin = 0
)

Arguments

fit_a

Fitted model object for Model A. This can be a tsnet_fit object (obtained from [stan_gvar()]), a BGGM object (obtained from [BGGM::var_estimate()]), or extracted posterior samples (obtained from [stan_fit_convert()).

fit_b

Fitted model object for Model B. This can be a tsnet_fit object (obtained from [stan_gvar()]), a BGGM object (obtained from [BGGM::var_estimate()]), or extracted posterior samples (obtained from [stan_fit_convert()).

cutoff

The percentage level of the test (default: 5%) as integer.

dec_rule

The decision rule to be used. Currently supports default "or" (comparing against two reference distributions) and "comb" (combining the reference distributions). The use of "or" is recommended, as "comb" is less stable.

n_draws

The number of draws to use for reference distributions (default: 1000).

comp

The distance metric to use. Should be one of "frob" (Frobenius norm), "maxdiff" (maximum difference), or "l1" (L1 norm) (default: "frob"). The use of the Frobenius norm is recommended.

return_all

Logical indicating whether to return all distributions (default: FALSE). Has to be set to TRUE for plotting the results.

sampling_method

Draw sequential pairs of samples from the posterior, with certain distance between them ("sequential") or randomly from two halves of the posterior ("random"). The "random" method is preferred to account for potential autocorrelation between subsequent samples. Default: "random".

indices

A list of "beta" and "pcor" indices specifying which elements of the matrices to consider when calculating distances. If NULL (default), all elements of both matrices are considered. If provided, only the elements at these indices are considered. If only one of the matrices should have indices, the other one should be NULL. This can be useful if you want to calculate distances based on a subset of the elements in the matrices.

burnin

The number of burn-in iterations to discard (default: 0).

Value

A list (of class "compare_gvar") containing the results of the comparison. The list includes:

sig_beta

Binary decision on whether there is a significant difference between the temporal networks of A and B

sig_pcor

Binary decision on whether there is a significant difference between the contemporaneous networks of A and B

res_beta

The null distribution for the temporal networks for both models

res_pcor

The null distribution for the contemporaneous networks for both models

emp_beta

The empirical distance between the two temporal networks

emp_pcor

The empirical distance between the two contemporaneous networks

larger_beta

The number of reference distances larger than the empirical distance for the temporal network

larger_pcor

The number of reference distances larger than the empirical distance for the temporal network

arguments

The arguments used in the function call

Examples

# use internal fit data of two individuals
data(fit_data)
test_res <- compare_gvar(fit_data[[1]],
fit_data[[2]],
n_draws = 100,
return_all = TRUE)
print(test_res)

[Package tsnet version 0.1.0 Index]