Skip to content

Commit c9f38db

Browse files
Merge pull request #7 from AnthonyRaborn/devel
v0.4.4
2 parents 5c80910 + 1efabea commit c9f38db

File tree

7 files changed

+49
-27
lines changed

7 files changed

+49
-27
lines changed

.Rbuildignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ README.Rmd
1010
Tabu_example.R
1111
cran-comments.md
1212
README-*
13+
^CRAN-RELEASE$

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@
55
ShortForm.Rproj
66
iteration.html
77
summary.txt
8-
8+
cran-comments.md

DESCRIPTION

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
Package: ShortForm
22
Type: Package
33
Title: Automatic Short Form Creation
4-
Version: 0.4.3
5-
Date: 2019-8-7
4+
Version: 0.4.4
5+
Date: 2019-10-9
66
Authors@R: c(person("Anthony", "Raborn", email = "anthony.w.raborn@gmail.com", role = c("aut", "cre")), person("Walter", "Leite", email = "Walter.Leite@coe.ufl.edu", role = "aut"))
77
Description: Performs automatic creation of short forms of scales with an
88
ant colony optimization algorithm and a Tabu search. As implemented in the

R/ACO_lavaan.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ antcolony.lavaan = function(data = NULL, sample.cov = NULL, sample.nobs = NULL,
305305

306306

307307
#replaces the lavaan syntax for factor specification.
308-
factor.position = grep(paste(factors[factor],"=~"),input,ignore.case=T)
308+
factor.position = grep(paste(factors[factor],"[ ]{0,}=~"),input,ignore.case=T)
309309
input[factor.position] = paste(factors[factor],"=~", paste(items,collapse =" + "))
310310
all.items = c(all.items, items)
311311
#finishes loop

R/Tabu_shortform.R

Lines changed: 40 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@ tabuShortForm <-
8181

8282
# save the external relationships
8383
vectorModel = unlist(strsplit(x = initialModel, split = "\\n"))
84-
externalRelation = vectorModel[grep(" ~ ", vectorModel)]
85-
factorRelation = vectorModel[grep(" ~~ ", vectorModel)]
84+
externalRelation = vectorModel[grep("[ ]{0,}(?<!=)~ ", vectorModel, perl=T)]
85+
factorRelation = vectorModel[grep("[ ]{0,}~~ ", vectorModel)]
8686

8787
# reduce the number of items for each factor according to maxItems
8888
newItemsPerFactor = list()
@@ -104,7 +104,7 @@ tabuShortForm <-
104104
paste(newItemsPerFactor[[i]], collapse = " + "))
105105
}
106106
newModelSyntax = c(newModelSyntax, externalRelation, factorRelation)
107-
107+
newModelSyntax = paste(newModelSyntax, collapse = "\n")
108108
# fit the new model
109109
newModel = modelWarningCheck(
110110
lavaan::lavaan(
@@ -226,8 +226,7 @@ tabuShortForm <-
226226
)
227227
)
228228

229-
if (fitmodel$lavaan.output@Fit@converged &
230-
!any(is.na(fitmodel$lavaan.output@Fit@se))) {
229+
if (fitmodel$lavaan.output@Fit@converged) {
231230
fit.val <- criterion(fitmodel$lavaan.output)
232231
} else {
233232
fit.val <- NA
@@ -276,8 +275,7 @@ tabuShortForm <-
276275
)
277276
)
278277

279-
if (fitmodel$lavaan.output@Fit@converged &
280-
!any(is.na(fitmodel$lavaan.output@Fit@se))) {
278+
if (fitmodel$lavaan.output@Fit@converged) {
281279
fit.val <- criterion(fitmodel$lavaan.output)
282280
} else {
283281
fit.val <- NA
@@ -322,8 +320,7 @@ tabuShortForm <-
322320
)
323321
)
324322

325-
if (fitmodel$lavaan.output@Fit@converged &
326-
!any(is.na(fitmodel$lavaan.output@Fit@se))) {
323+
if (fitmodel$lavaan.output@Fit@converged) {
327324
fit.val <- criterion(fitmodel$lavaan.output)
328325
} else {
329326
fit.val <- NA
@@ -347,6 +344,40 @@ tabuShortForm <-
347344
# Out of valid models, pick model with best objective function value
348345
indx <- which.min(tmp.obj[valid])
349346

347+
# if no valid models, recreate a random short form and start over
348+
if (length(indx)==0) {
349+
cat("Creating initial short form.\n")
350+
initialShortModel <- randomInitialModel()
351+
cat("The initial short form is: \n")
352+
cat(paste(initialShortModel$model.syntax, collapse = "\n"))
353+
best.obj <- all.obj <- current.obj <- criterion(initialShortModel$lavaan.output)
354+
best.model <- current.model <- initialShortModel$lavaan.output
355+
tabu.list <- vector("numeric")
356+
357+
factors = unique(lavaan::lavaanify(initialModel)[lavaan::lavaanify(initialModel)$op ==
358+
"=~", 'lhs'])
359+
externalRelation = unlist(strsplit(x = initialModel, split = "\\n"))[grep(" ~ ", unlist(strsplit(x = initialModel, split = "\\n")))]
360+
factorRelation = unlist(strsplit(x = initialModel, split = "\\n"))[grep(" ~~ ", unlist(strsplit(x = initialModel, split = "\\n")))]
361+
362+
if (is.list(allItems)) {
363+
included.items <-
364+
stringr::str_extract_all(string = initialShortModel$model.syntax,
365+
pattern = paste0("(\\b", paste0(
366+
paste0(unlist(allItems), collapse = "\\b)|(\\b"), "\\b)"
367+
)))
368+
} else {
369+
included.items <-
370+
unlist(as.vector(
371+
stringr::str_extract_all(
372+
string = initialShortModel$model.syntax,
373+
pattern = paste0("(\\b", paste0(
374+
paste0(allItems, collapse = "\\b)|(\\b"), "\\b)"
375+
))
376+
)
377+
))
378+
}
379+
next
380+
}
350381
# Move current state to next model
351382
current.obj <- (tmp.obj[valid])[indx]
352383
all.obj <- c(all.obj, current.obj)

R/simulated_annealing_internals.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ syntaxExtraction = function(initialModelSyntaxFile, items) {
149149
factorSyntax = c()
150150
itemSyntax = c()
151151
for (i in 1:length(factors)) {
152-
chosenFactorLocation = c(1:length(vectorModelSyntax))[grepl(x = vectorModelSyntax, pattern = paste0(factors[i], " =~ "))]
152+
chosenFactorLocation = c(1:length(vectorModelSyntax))[grepl(x = vectorModelSyntax, pattern = paste0(factors[i], "[ ]{0,}=~ "))]
153153
factorSyntax[i] = vectorModelSyntax[chosenFactorLocation]
154154
# remove the factors from the syntax
155155
itemSyntax[i] <-

cran-comments.md

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,11 @@
11
## Resubmission
2-
This is a resubmission. In this version I have:
3-
4-
* Added classes to the results of the major package functions
5-
6-
* Introduced an S3 Plot method
7-
8-
* Fixed bugs related to bifactor models
9-
10-
* Added a loading message that prints the package version when the package is attached
11-
12-
* Updated the simulatedAnnealing documentation so it is easier on the eyes
2+
This is a resubmission. In this version I have fixed a bug that caused the lavaan-based functions to improperly use the initial model syntax instead of building the intermediate model syntax when the initial model syntax was specified in an untested manner.
133

144
## Test Environments
155

16-
* local Windows 10 Home install, R 3.5.0
6+
* local Windows 10 Enterprise install, R 3.6.1
177

18-
* ubuntu 14.04.5 LTS trusty (travis ci), R 3.5.1
8+
* Ubuntu 16.04.5 LTS xenial (travis ci), R 3.6.1
199

2010
## R CMD check results
2111
0 errors | 0 warnings | 0 notes

0 commit comments

Comments
 (0)