Skip to content

Commit 4cb1185

Browse files
committed
Added ACO plot example and modified SA plot example
1 parent c870a13 commit 4cb1185

File tree

6 files changed

+67
-20
lines changed

6 files changed

+67
-20
lines changed

README-ACO example-1.png

9.65 KB
Loading

README-ACO example-2.png

7.9 KB
Loading

README-ACO example-3.png

7.66 KB
Loading
952 Bytes
Loading

README.Rmd

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ summaryfile = NULL,
7474
feedbackfile = NULL,
7575
max.run = 50, verbose = FALSE)
7676
abilityShortForm[[1]] # print the results of the final short form
77+
antcolony_plot(abilityShortForm) # the plots available
7778
```
7879

7980
A similar example can be found in the `antcolony.mplus` function, but requires you to have a valid Mplus installation on the computer. It took a total of `r round(as.difftime(Sys.time() - start.time.ACO, units = "mins"),2)` minutes to run this example.
@@ -138,8 +139,9 @@ lavaan.model.specs = list(model.type = "cfa",
138139
139140
# perform the SA algorithm
140141
set.seed(1)
141-
SA_example <- simulatedAnnealing(initialModel = saModel, originalData = saData, maxSteps = 1000, fitStatistic = 'cfi', maximize = FALSE, temperature = "logistic", items = paste0("Item", 1:10), lavaan.model.specs = lavaan.model.specs, maxChanges = 3, maxItems = 5, progress = F)
142-
plot(SA_example$allFit, type = "l") # plot showing how the fit value changes at each step
142+
SA_example <- simulatedAnnealing(initialModel = saModel, originalData = saData, maxSteps = 500, fitStatistic = 'cfi', maximize = FALSE, temperature = "logistic", items = paste0("Item", 1:10), lavaan.model.specs = lavaan.model.specs, maxChanges = 3, maxItems = 5, progress = F)
143+
plot(SA_example$allFit, type = "b") # plot showing how the fit value changes at each step
144+
SA_example$bestSyntax # the model syntax that had the best fit found by the algorithm
143145
```
144146

145147
It took a total of `r round(as.difftime(Sys.time() - start.time.SA, units = "mins"),2)` minutes to run the SA example, and a total of `r round(as.difftime(Sys.time() - start.time.ACO, units = "mins"),2)` minutes to run all three together.

README.md

Lines changed: 63 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,41 @@
11

2-
ShortForm
3-
=========
2+
# ShortForm
43

5-
[![CRAN\_Status\_Badge](http://www.r-pkg.org/badges/version/ShortForm)](http://cran.r-project.org/package=ShortForm) [![Travis-CI Build Status](http://travis-ci.org/AnthonyRaborn/ShortForm.svg?branch=master)](http://travis-ci.org/AnthonyRaborn/ShortForm) [![CRAN Downloads Per Month](https://cranlogs.r-pkg.org/badges/ShortForm)](https://cran.r-project.org/package=ShortForm) [![CRAN Downloads Total](https://cranlogs.r-pkg.org/badges/grand-total/ShortForm?color=orange)](https://cran.r-project.org/package=ShortForm)
4+
[![CRAN\_Status\_Badge](http://www.r-pkg.org/badges/version/ShortForm)](http://cran.r-project.org/package=ShortForm)
5+
[![Travis-CI Build
6+
Status](http://travis-ci.org/AnthonyRaborn/ShortForm.svg?branch=master)](http://travis-ci.org/AnthonyRaborn/ShortForm)
7+
[![CRAN Downloads Per
8+
Month](https://cranlogs.r-pkg.org/badges/ShortForm)](https://cran.r-project.org/package=ShortForm)
9+
[![CRAN Downloads
10+
Total](https://cranlogs.r-pkg.org/badges/grand-total/ShortForm?color=orange)](https://cran.r-project.org/package=ShortForm)
611

7-
Automatic Short Form Creation for scales. Currently, the Ant Colony Optimization (ACO) Algorithm and the Tabu search are implemented. The original R implementation for the ACO algorithm is from [Leite, Huang, & Marcoulides (2008)](doi:10.1080/00273170802285743), while the Tabu search function was taken from [Marcoulides & Falk (2018)](doi:10.1080/10705511.2017.1409074). There does not yet seem to be an application of Simulated Annealing (SA) within psychometrics, but Drezner & Marcoulides, 1999 (in *Multiple Linear Regression Viewpoints*, Volume 25(2); not available online) used SA for multiple regression model selection; this package appears to be the first to implement SA for psychometric models.
12+
Automatic Short Form Creation for scales. Currently, the Ant Colony
13+
Optimization (ACO) Algorithm and the Tabu search are implemented. The
14+
original R implementation for the ACO algorithm is from [Leite, Huang, &
15+
Marcoulides (2008)](doi:10.1080/00273170802285743), while the Tabu
16+
search function was taken from [Marcoulides & Falk
17+
(2018)](doi:10.1080/10705511.2017.1409074). There does not yet seem to
18+
be an application of Simulated Annealing (SA) within psychometrics, but
19+
Drezner & Marcoulides, 1999 (in *Multiple Linear Regression Viewpoints*,
20+
Volume 25(2); not available online) used SA for multiple regression
21+
model selection; this package appears to be the first to implement SA
22+
for psychometric models.
823

9-
Installation
10-
------------
24+
## Installation
1125

1226
``` r
1327
# install.packages("devtools")
1428
devtools::install_github("AnthonyRaborn/ShortForm") # the developmental version
1529
install.packages("ShortForm") # the CRAN-approved version
1630
```
1731

18-
Usage
19-
-----
32+
## Usage
2033

21-
Here are some (slightly modified) examples from the help documentation using lavaan. Be warned, the algorithms may take some time to converge, particularly with large forms, multiple dimensions, and different settings. The time for these examples to converge on a low-end laptop is printed at the bottom.
34+
Here are some (slightly modified) examples from the help documentation
35+
using lavaan. Be warned, the algorithms may take some time to converge,
36+
particularly with large forms, multiple dimensions, and different
37+
settings. The time for these examples to converge on a low-end laptop is
38+
printed at the bottom.
2239

2340
### ACO Algorithm
2441

@@ -92,13 +109,31 @@ abilityShortForm[[1]] # print the results of the final short form
92109
## [1,] 1 0 0 0 0 0 0 1 0 0
93110
## Item29 Item30
94111
## [1,] 1 1
112+
antcolony_plot(abilityShortForm) # the plots available
113+
## [[1]]
95114
```
96115

97-
A similar example can be found in the `antcolony.mplus` function, but requires you to have a valid Mplus installation on the computer. It took a total of 5.76 minutes to run this example.
116+
![](README-ACO%20example-1.png)<!-- -->
117+
118+
##
119+
## [[2]]
120+
121+
![](README-ACO%20example-2.png)<!-- -->
122+
123+
##
124+
## [[3]]
125+
126+
![](README-ACO%20example-3.png)<!-- -->
127+
128+
A similar example can be found in the `antcolony.mplus` function, but
129+
requires you to have a valid Mplus installation on the computer. It took
130+
a total of 5.6 minutes to run this example.
98131

99132
### Tabu Search Algorithm
100133

101-
This example demonstrates how to use the Tabu search for model specification searches when the original model may be misspecified in some way.
134+
This example demonstrates how to use the Tabu search for model
135+
specification searches when the original model may be misspecified in
136+
some way.
102137

103138
``` r
104139
start.time.Tabu <- Sys.time()
@@ -153,7 +188,10 @@ Tabu_example <- suppressWarnings(tabu.sem(init.model = init.model, ptab = ptab,
153188

154189
# check the final model
155190
lavaan::summary(Tabu_example$best.mod)
156-
## lavaan (0.6-1) converged normally after 51 iterations
191+
## lavaan 0.6-2 ended normally after 56 iterations
192+
##
193+
## Optimization method NLMINB
194+
## Number of free parameters 20
157195
##
158196
## Number of observations 1000
159197
##
@@ -255,11 +293,12 @@ lavaan::summary(Tabu_example$best.mod)
255293
## .Item8 0.198 0.010 20.542 0.000
256294
```
257295

258-
It took a total of 3.86 minutes to run this example.
296+
It took a total of 4.88 minutes to run this example.
259297

260298
### Simulated Annealing
261299

262-
This example demonstrates the use of simulated annealing for creating short forms.
300+
This example demonstrates the use of simulated annealing for creating
301+
short forms.
263302

264303
``` r
265304
start.time.SA <- Sys.time()
@@ -281,17 +320,23 @@ lavaan.model.specs = list(model.type = "cfa",
281320

282321
# perform the SA algorithm
283322
set.seed(1)
284-
SA_example <- simulatedAnnealing(initialModel = saModel, originalData = saData, maxSteps = 1000, fitStatistic = 'cfi', maximize = FALSE, temperature = "logistic", items = paste0("Item", 1:10), lavaan.model.specs = lavaan.model.specs, maxChanges = 3, maxItems = 5, progress = F)
323+
SA_example <- simulatedAnnealing(initialModel = saModel, originalData = saData, maxSteps = 500, fitStatistic = 'cfi', maximize = FALSE, temperature = "logistic", items = paste0("Item", 1:10), lavaan.model.specs = lavaan.model.specs, maxChanges = 3, maxItems = 5, progress = F)
285324
## Initializing short form creation.
286325
## The initial short form is:
287326
## Ability =~ Item3 + Item4 + Item5 + Item7 + Item2
288327
## Ability ~ Outcome
289328
## Using the short form randomNeighbor function.
290329
## Finished initializing short form options.
291330
## Current Progress:
292-
plot(SA_example$allFit, type = "l") # plot showing how the fit value changes at each step
331+
plot(SA_example$allFit, type = "b") # plot showing how the fit value changes at each step
293332
```
294333

295-
![](README-Simulated%20Annealing%20example-1.png)
334+
![](README-Simulated%20Annealing%20example-1.png)<!-- -->
335+
336+
``` r
337+
SA_example$bestSyntax # the model syntax that had the best fit found by the algorithm
338+
## [1] "Ability =~ Item2 + Item6 + Item4 + Item5 + Item3"
339+
```
296340

297-
It took a total of 2.52 minutes to run the SA example, and a total of 12.15 minutes to run all three together.
341+
It took a total of 1.28 minutes to run the SA example, and a total of
342+
11.76 minutes to run all three together.

0 commit comments

Comments
 (0)