compute_model_space_stats: Approximate standard deviations for the models

View source: R/model_space.R

compute_model_space_statsR Documentation

Approximate standard deviations for the models

Description

Approximate standard deviations are computed for the models in the given model space. Two versions are computed.

Usage

compute_model_space_stats(
  df,
  dep_var_col,
  timestamp_col,
  entity_col,
  params,
  nested = TRUE,
  exact_value = FALSE,
  model_prior = "uniform",
  cl = NULL
)

Arguments

df

Data frame with data for the SEM analysis.

dep_var_col

Column with the dependent variable

timestamp_col

The name of the column with timestamps

entity_col

Column with entities (e.g. countries)

params

A matrix (with named rows) with each column corresponding to a model. Each column specifies model parameters. Compare with optim_model_space_params

nested

Logical. If TRUE (default), compute approximate standard deviations using the nested-model approach via nested_std_dev_from_params(). If FALSE, use the non-nested approach via non_nested_std_dev_from_params(). The choice affects which approximation routine is used for each model in params.

exact_value

Whether the exact value of the likelihood should be computed (TRUE) or just the proportional part (FALSE). Check sem_likelihood for details.

model_prior

Which model prior to use. For now there are two options: 'uniform' and 'binomial-beta'. Default is 'uniform'.

cl

An optional cluster object. If supplied, the function will use this cluster for parallel processing. If NULL (the default), pbapply::pblapply will run sequentially.

Value

Matrix with columns describing likelihood and standard deviations for each model. The first row is the likelihood for the model (computed using the parameters in the provided model space). The second row is the marginal likelihood approximation used to weight the models, namely exp((loglik - (k/2) * log(N * T)) / N); note that it is not a BIC. Then there are rows with standard deviations for each parameter, followed by rows with robust standard deviations. The last three rows hold tr(H^-1 J), where H is the observed information and J the outer product of the entity-level scores, the dimension of the parameter vector, and the numerical rank of J. These are the ingredients of the magnitude adjustment for misspecified likelihoods, whose rate is rank(J) / tr(H^-1 J); see score_rank for why J is typically rank deficient, and bma for why no weighting option is built on it.

Examples


 library(magrittr)
 data_prepared <- badp::economic_growth[, 1:6] %>%
   badp::feature_standardization(
     excluded_cols = c(country, year, gdp)
   ) %>%
   badp::feature_standardization(
     group_by_col  = year,
     excluded_cols = country,
     scale         = FALSE
   )

 compute_model_space_stats(
   df            = data_prepared,
   dep_var_col   = gdp,
   timestamp_col = year,
   entity_col    = country,
   params        = small_model_space$params
 )



badp documentation built on Aug. 20, 2026, 9:08 a.m.