This is the main function used to run a psychonetrics model.
runmodel(x, level = c("gradient", "fitfunction"), addfit =
TRUE, addMIs = TRUE, addSEs = TRUE, addInformation =
TRUE, log = TRUE, verbose, optim.control,
analyticFisher = TRUE, warn_improper = FALSE,
warn_gradient = TRUE, warn_bounds = TRUE,
return_improper = TRUE, bounded = TRUE,
approximate_SEs = FALSE,
criterion = "ebic.5",
beta_min = c("numerical", "theoretical"),
saturated = c("default", "analytic", "model"))An object of the class psychonetrics (psychonetrics-class)
A psychonetrics model.
Level at which the model should be estimated. Defaults to "gradient" to indicate the analytic gradient should be used.
Logical, should fit measures be added?
Logical, should modification indices be added?
Logical, should standard errors be added?
Logical, should the Fisher information be added?
Logical, should the log be updated?
Logical, should messages be printed?
A list with options for optimr
Logical, should the analytic Fisher information be used? If FALSE, numeric information is used instead.
Should a result in which improper computation was used be return? Improper computation can mean that a pseudoinverse of small spectral shift was used in computing the inverse of a matrix.
Logical. Should a warning be given when at some point in the estimation a pseudoinverse was used?
Logical. Should a warning be given when the average absolute gradient is > 1?
Logical. Should bounded estimation be used (e.g., variances should be positive)?
Logical, should standard errors be approximated? If true, an approximate matrix inverse of the Fisher information is used to obtain the standard errors.
Should a warning be given when a parameter is estimated near its bounds?
Character string specifying the information criterion for automatic lambda selection in PML/PFIML models. One of "bic", "ebic.25", "ebic.5" (default), "ebic.75", or "ebic1". Only used when the model contains auto-select penalty parameters (penalty_lambda = NA). See find_penalized_lambda for details.
Threshold for zeroing out small penalized parameters during automatic lambda selection. Can be "numerical" (default; uses 1e-05), "theoretical" (uses sqrt(log(p)/n)), or a numeric value. See find_penalized_lambda for details.
Method for computing the saturated model log-likelihood. "default" runs the saturated varcov model numerically, with automatic fallback to the analytical formula if the optimizer fails (saturated LL < model LL). "analytic" skips the saturated model optimization and uses the analytical pattern-specific formula directly (fast, useful for high-dimensional panel data where optimization is slow or fails). "model" always runs the saturated varcov model numerically with no fallback. The method that was ultimately used is recorded in the result: x@baseline_saturated$satMethodUsed is "numeric", "analytic", or "analytic_fallback", and the fit measure satLL_analytic is a 0/1 indicator of whether the analytic formula was used (forced or as fallback), which is retained by aggregate_bootstraps (its bootstrap average is the proportion of samples using the analytic saturated log-likelihood).
Sacha Epskamp
For penalized models (PML or PFIML) with auto-select penalty parameters (penalty_lambda = NA, the default), runmodel automatically calls find_penalized_lambda to select the optimal penalty strength via EBIC grid search before fitting. The criterion and beta_min arguments control this search. After the lambda search, use refit for post-selection inference with standard errors.
For the robust maximum likelihood estimators ("MLM", "MLMV",
"MLMVS", "MLR"; see setestimator), the point
estimates are obtained by plain maximum likelihood, while runmodel
additionally computes robust (sandwich) standard errors, a scaled test
statistic (Satorra-Bentler family or Yuan-Bentler) and robust RMSEA/CFI/TLI.
These are stored in the model fit measures (chisq.scaled,
chisq.scaling.factor, df.scaled, chisq.shift.parameters,
rmsea.robust, cfi.robust, tli.robust). The
Satorra-Bentler family ("MLM"/"MLMV"/"MLMVS") requires
complete (continuous) raw data. "MLR" additionally supports missing
data through full-information maximum likelihood (FIML): when the raw data
contain missing values, point estimation uses FIML and the robust standard
errors (Huber-White), the Yuan-Bentler-Mplus scaled test statistic and the
FIML-corrected robust RMSEA/CFI/TLI are computed under missingness.
find_penalized_lambda for manual control over the lambda search,
penalize for setting penalty parameters,
refit for post-selection inference after penalized estimation.
# Load bfi data from psych package:
library("psychTools")
data(bfi)
# Also load dplyr for the pipe operator:
library("dplyr")
# Let's take the agreeableness items, and gender:
ConsData <- bfi %>%
select(A1:A5, gender) %>%
na.omit # Let's remove missingness (otherwise use Estimator = "FIML)
# Define variables:
vars <- names(ConsData)[1:5]
# Let's fit a full GGM:
mod <- ggm(ConsData, vars = vars, omega = "full")
# Run model:
mod <- mod %>% runmodel
Run the code above in your browser using DataLab