simulatedAnnealing: An adaptation of the simulated annealing algorithm for...

Description Usage Arguments Details Value Examples

View source: R/simulated_annealing.R

Description

Simulated annealing mimics the physical process of annealing metals together. Kirkpatrick et al. (1983) introduces this analogy and demonstrates its use; the implementation here follows this demonstration closely, with some modifications to make it better suited for psychometric models.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
simulatedAnnealing(
  initialModel,
  originalData,
  maxSteps,
  fitStatistic = "cfi",
  temperature = "linear",
  maximize = TRUE,
  Kirkpatrick = TRUE,
  randomNeighbor = TRUE,
  lavaan.model.specs = list(model.type = "cfa", auto.var = TRUE, estimator = "default",
    ordered = NULL, int.ov.free = TRUE, int.lv.free = FALSE, std.lv = TRUE, auto.fix.first
    = FALSE, auto.fix.single = TRUE, auto.cov.lv.x = TRUE, auto.th = TRUE, auto.delta =
    TRUE, auto.cov.y = TRUE),
  maxChanges = 5,
  restartCriteria = "consecutive",
  maximumConsecutive = 25,
  maxItems = NULL,
  items = NULL,
  bifactor = FALSE,
  progress = "bar",
  ...
)

Arguments

initialModel

The initial model as a character vector with lavaan model.syntax.

originalData

The original data frame with variable names.

maxSteps

The number of iterations for which the algorithm will run.

fitStatistic

Either a single model fit statistic produced by lavaan, or a user-defined fit statistic function.

temperature

Either an acceptable character value, or a user-defined temperature function. The acceptable values are "linear", "quadratic", or "logistic".

maximize

Logical indicating if the goal is to maximize (TRUE) the fitStatistic for model selection.

Kirkpatrick

Either TRUE to use Kirkpatrick et al. (1983) acceptance probability, or a user-defined function for accepting proposed models.

randomNeighbor

Either TRUE to use the included function for randomNeighbor selection, or a user-defined function for creating random models.

lavaan.model.specs

A list which contains the specifications for the lavaan model. The default values are the defaults for lavaan to perform a CFA. See lavaan for more details.

maxChanges

An integer value greater than 1 setting the maximum number of parameters to change within randomNeighbor. When creating a short form, should be no greater than the smallest reduction in items loading on one factor; e.g., when reducing a 2-factor scale from 10 items on each factor to 8 items on the first and 6 items on the second, maxChanges should be no greater than 2.

restartCriteria

Either "consecutive" to restart after maxConsecutiveSelection times with the same model chosen in a row, or a user-defined function.

maximumConsecutive

A numeric value used with restartCriteria.

maxItems

When creating a short form, a vector of the number of items per factor you want the short form to contain. Defaults to NULL.

items

A character vector of item names. Defaults to NULL. Ignored if maxItems==FALSE.

bifactor

Logical. Indicates if the latent model is a bifactor model. If TRUE, assumes that the last latent variable in the provided model syntax is the bifactor (i.e., all of the retained items will be set to load on the last latent variable). Ignored if maxItems==FALSE.

progress

Character. If 'bar', the function prints a progress bar indicating how far along it is. If 'text', prints the current step value. Otherwise, nothing is printed to indicate the progress of the function.

...

Further arguments to be passed to other functions. Not implemented for any of the included functions.

Details

Outline of the Pieces of the Simulated Annealing Algorithm

Value

A named list: the 'bestModel' found, the 'bestFit', and 'allFit' values found by the algorithm.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
## Not run: 
data(exampleAntModel)
data(simulated_test_data)
trial1 <- simulatedAnnealing(initialModel = lavaan::cfa(model = exampleAntModel,
                                                        data = simulated_test_data),
                             originalData = simulated_test_data, maxSteps = 3,
                             fitStatistic = 'rmsea', maximize = FALSE)
# lavaan::summary(trial1[[1]]) # shows the resulting model

trial2 <- simulatedAnnealing(initialModel = exampleAntModel,
originalData = simulated_test_data,
maxSteps = 2, maxItems = 30, items = paste0("Item", 1:56))
# lavaan::summary(trial2[[1]]) # shows the resulting model

## End(Not run)

Example output

  #####                             #######                      
 #     # #    #  ####  #####  ##### #        ####  #####  #    # 
 #       #    # #    # #    #   #   #       #    # #    # ##  ## 
  #####  ###### #    # #    #   #   #####   #    # #    # # ## # 
       # #    # #    # #####    #   #       #    # #####  #    # 
 #     # #    # #    # #   #    #   #       #    # #   #  #    # 
  #####  #    #  ####  #    #   #   #        ####  #    # #    # 
 
		 Version 0.4.6
			 (o<
			 //\
			 V_/_ 
Package 'ShortForm' version 0.4.6

 Current Progress:
  |                                                                            
  |===================================                                   |  50%
  |                                                                            
  |                                                                      |   0%
  |                                                                            
  |===================================                                   |  50%
  |                                                                            
  |======================================================================| 100%Initializing short form creation.
The initial short form is:
 Ability =~ Item8 + Item56 + Item40 + Item7 + Item20 + Item17 + Item32 + Item34 + Item41 + Item52 + Item19 + Item1 + Item48 + Item27 + Item45 + Item31 + Item53 + Item4 + Item38 + Item29 + Item26 + Item49 + Item21 + Item42 + Item23 + Item37 + Item35 + Item10 + Item24 + Item28
Ability ~ Outcome
Using the short form randomNeighbor function.
Finished initializing short form options.
 Current Progress:
  |                                                                            
  |======================================================================| 100%
  |                                                                            
  |                                                                      |   0%
  |                                                                            
  |======================================================================| 100%

ShortForm documentation built on March 26, 2020, 7:47 p.m.