modelsearch: Stepwise model search

View source: R/h_modelsearch.R

modelsearchR Documentation

Stepwise model search

Description

This function peforms stepwise model search to find an optimal model that (locally) minimzes some criterion (by default, the BIC).

Usage

modelsearch(x, criterion = "bic", matrices, prunealpha = 0.01,
                    addalpha = 0.01, verbose, ...)

Arguments

x

A psychonetrics model.

criterion

String indicating the criterion to minimize. Any criterion from fit can be used.

matrices

Vector of strings indicating which matrices should be searched. Will default to network structures and factor loadings.

prunealpha

Minimal alpha used to consider edges to be removed

addalpha

Maximum alpha used to consider edges to be added

verbose

Logical, should messages be printed?

...

Arguments sent to runmodel

Details

The full algorithm is as follows:

1. Evaluate all models in which an edge is removed that has p > prunealpha, or an edge is added that has a modification index with p < addalpha

2. If none of these models improve the criterion, return the previous model and stop the algorithm

3. Update the model to the model that improved the criterion the most

4. Evaluate all other considered models that improved the criterion

5. If none of these models improve the criterion, go to 1, else go to 3

Value

An object of the class psychonetrics (psychonetrics-class)

Author(s)

Sacha Epskamp

See Also

prune, stepup

Examples


# 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)

# Run model:
mod <- mod %>% runmodel

# Model search
mod <- mod %>% prune(alpha= 0.01) %>% modelsearch


psychonetrics documentation built on June 22, 2024, 10:29 a.m.