| optim_model_space | R Documentation |
This function calculates model space, values of the maximized likelihood function, BICs, and standard deviations of the parameters that will be used in Bayesian model averaging. Moreover, it provides a vector with the names of the variables for bma function and the number of observations.
optim_model_space(
df,
timestamp_col,
entity_col,
dep_var_col,
init_value,
nested = TRUE,
exact_value = FALSE,
cl = NULL,
control = list(trace = 0, maxit = 10000, fnscale = -1, REPORT = 100, scale = 0.05),
max_restarts = 5,
restart_tol = 0.001,
max_reoptimizations = 5,
max_init_attempts = 100
)
df |
Data frame with data for the analysis. |
timestamp_col |
The name of the column with time stamps |
entity_col |
Column with entities (e.g. countries) |
dep_var_col |
Column with the dependent variable |
init_value |
Function of one argument |
nested |
Logical. If |
exact_value |
Whether the exact value of the likelihood should be
computed ( |
cl |
An optional cluster object. If supplied, the function will use this
cluster for parallel processing. If |
control |
a list of control parameters for the optimization which are
passed to optim. Default is
|
max_restarts |
Maximum number of times the BFGS optimization is
restarted from its previous solution for a single model. A restart resets
the internal curvature approximation of BFGS, which often makes further
progress on ill-conditioned likelihood ridges where a single run stalls.
Default is |
restart_tol |
Log-likelihood improvement between restarts below which
the optimization is considered converged. Improvements of this size are
immaterial for posterior model probabilities. Default is |
max_reoptimizations |
Maximum number of times a model is re-optimized
from a fresh starting point drawn from |
max_init_attempts |
Maximum number of starting points drawn from
|
An object of class badp_model_space, which is a list with the following elements:
params - table with parameters of all estimated models
stats - table with the value of maximized likelihood function, BIC, and
standard errors for all estimated models
reg_names - vector with the names of the variables
observations_num - number of observations
df - data frame used in estimation
is_nested - logical indicating whether nested approach was used
convergence - matrix of per-model convergence diagnostics with rows
converged (1 if the likelihood value stalled across restarts at a
solution standard errors can be computed from, 0 if the restart budget was
exhausted while the value was still improving or every re-optimization
ended in a degenerate region),
optim_code (the optim convergence code of the final
run), n_restarts, max_abs_gradient and n_init_draws
(the number of starting points drawn from init_value before one at
which the likelihood is defined was found). A large final
gradient with converged = 1 indicates parameters on a degenerate
(nearly collinear) likelihood ridge; the likelihood value is trustworthy
but the standard errors of the affected coordinates are not.
The robust standard errors stored in the statistics, and the columns
PSDR and PSDRcon that bma derives from them, come
from the sandwich H^{-1} J H^{-1} with
J = \sum_{i=1}^{N} s_i s_i' formed from the entity-level score
vectors. J depends only on the variation of those scores across
entities, so parameters entering the log-likelihood solely through terms
common to every entity contribute nothing and J is rank deficient
regardless of N; see score_rank. The fraction of
parameter directions the scores span is reported by
summary.badp_model_space. The standard errors that are
reported remain well defined, as the sandwich restricted to the spanned
block is the profile sandwich on that block, but the score covariance
involving the remaining directions is discarded. The likelihood, the
parameter estimates and the Hessian-based standard errors are unaffected.
Objects of class badp_model_space have the following methods available:
print.badp_model_space - Display model space information
library(magrittr)
data_prepared <- badp::economic_growth[, 1:5] %>%
badp::feature_standardization(
excluded_cols = c(country, year, gdp)
) %>%
badp::feature_standardization(
group_by_col = year,
excluded_cols = country,
scale = FALSE
)
optim_model_space(
df = data_prepared,
dep_var_col = gdp,
timestamp_col = year,
entity_col = country,
init_value = function(n) runif(n, 0.1, 1)
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.