Description Usage Arguments Details Value Examples
View source: R/simulated_annealing.R
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.
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",
...
)

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 userdefined fit statistic function. 
temperature 
Either an acceptable character value, or a userdefined 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 userdefined function for accepting proposed models. 
randomNeighbor 
Either TRUE to use the included function for randomNeighbor selection, or a userdefined 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 2factor 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 userdefined 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 
items 
A character vector of item names. Defaults to 
bifactor 
Logical. Indicates if the latent model is a bifactor model. If 
progress 
Character. If 
... 
Further arguments to be passed to other functions. Not implemented for any of the included functions. 
Outline of the Pieces of the Simulated Annealing Algorithm
initialModel – the initial, full form
currentModel – the model of the current step
maxSteps – the maximum number of steps (iterations)
currentStep – the current step
currentTemp – the current temperature. A function of the number of steps (such that temp = 0 at maxSteps), and values that control the shape of the overall temperature. A part of the function that determines the acceptance probability of newly – generated models
randomNeighbor – a function that determines how the form is changed at each step. Should be able to change one or more parameters, and should have a way to control how many are changed.
goal – a function that determines the "goodness" of the currentModel. Typically in SA goodness is defined as minimization! Sometimes called an energy function
selectionFunction – a function that determines if a randomNeighbor change is accepted. Uses the goal function that determines the "goodness" of the currentModel and the "goodness" of the randomNeighbor, and the currentTemp to generate a probability of acceptance, then compares this probability to a Uniform(0,1) variable to determine if accepted or not. A standard version of this is: (Kirkpatrick et al., 1983)
bestModel – the model with the best value of the goal function achieved so far
bestGoal – the best value of the goal function achieved so far
restartCriteria – if utilized, this would "restart" the SA process by changing currentModel to bestModel and continuing the process. Could be based on (1) the currentStep value, (2) the difference between goal(currentModel) and goal(bestModel), (3) randomness (i.e., could randomly restart, could randomly restart based on some values, etc), (4) other critera.
A named list: the 'bestModel' found, the 'bestFit', and 'allFit' values found by the algorithm.
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)

##### #######
# # # # #### ##### ##### # #### ##### # #
# # # # # # # # # # # # # ## ##
##### ###### # # # # # ##### # # # # # ## #
# # # # # ##### # # # # ##### # #
# # # # # # # # # # # # # # # #
##### # # #### # # # # #### # # # #
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%
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.