Skip to content

Commit 209b240

Browse files
Merge pull request #25 from AnthonyRaborn/lavaan-mode-specs-update
Lavaan mode specs update
2 parents 427c66b + b20b577 commit 209b240

File tree

2 files changed

+44
-20
lines changed

2 files changed

+44
-20
lines changed

R/ACO_lavaan.R

Lines changed: 38 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,12 @@
100100
#' of ants in a row for which the model does not change.
101101
#' @param lavaan.model.specs A list which contains the specifications for the
102102
#' lavaan model. The default values are the defaults for lavaan to perform a
103-
#' CFA. See \link[lavaan]{lavaan} for more details.
103+
#' CFA. These are automatically set internally, then updated by the user-provided
104+
#' values. Note that this drastically affects the algorithm, and care must be
105+
#' taken to ensure that the algorithm can fit valid models as it searches for
106+
#' the best model. See the default arguments for examples of what you can change
107+
#' and \link[lavaan]{lavaan} for more details on what arguments are available
108+
#' to change.
104109
#' @param pheromone.calculation A character string specifying the method for
105110
#' calculating the pheromone strength. Must be one of "\code{gamma}"
106111
#' (standardized latent regression coefficients), "\code{beta}"
@@ -278,6 +283,16 @@ antcolony.lavaan <- function(data = NULL, sample.cov = NULL, sample.nobs = NULL,
278283
step <- 1
279284

280285
# creates objects in the function environment that are fed into the lavaan function in order to fine-tune the model to user specifications
286+
# use a default set of specifications that fits a CFA
287+
default.lavaan.model.specs = list(
288+
model.type = "cfa", auto.var = T, estimator = "default",
289+
ordered = T, int.ov.free = TRUE, int.lv.free = FALSE, auto.fix.first = TRUE,
290+
auto.fix.single = TRUE, auto.var = TRUE, auto.cov.lv.x = TRUE, auto.th = TRUE,
291+
auto.delta = TRUE, auto.cov.y = TRUE, std.lv = F, group = NULL, group.label = NULL,
292+
group.equal = "loadings", group.partial = NULL, group.w.free = FALSE
293+
)
294+
mapply(assign, names(default.lavaan.model.specs), default.lavaan.model.specs, MoreArgs = list(envir = antcolony.lavaan.env))
295+
# overwrite with user-provided definitions
281296
mapply(assign, names(lavaan.model.specs), lavaan.model.specs, MoreArgs = list(envir = antcolony.lavaan.env))
282297

283298
# create values of "bad warnings" and "bad errors" that result in uninterpretable models
@@ -379,25 +394,29 @@ antcolony.lavaan <- function(data = NULL, sample.cov = NULL, sample.nobs = NULL,
379394
warnings <- modelCheck@warnings
380395
errors <- modelCheck@errors
381396
# Check the above messages and set pheromone to zero under 'bad' circumstances
382-
if (any(grepl(bad.errors, errors, ignore.case = T)) || any(grepl(bad.warnings, warnings, ignore.case = T))) {
383-
pheromone <- 0
384-
385-
# writes feedback about non-convergence and non-positive definite.
386-
if (length(summaryfile) > 0) {
387-
fit.info <- matrix(c(select.indicator, run, count, ant, 999, 999, round((include), 5)), 1, )
388-
write.table(fit.info,
389-
file = summaryfile, append = T,
390-
quote = F, sep = " ", row.names = F, col.names = F
391-
)
392-
}
393-
394-
# provide feedback about search.
395-
if (length(feedbackfile) > 0) {
396-
feedback <- c(paste("<h1>", run, "-", count, "-", ant, "-", step, "- Failure", "</h1>"))
397-
write(feedback, file = feedbackfile, append = T)
397+
if (length(warnings) > 0 | length(errors) > 0) {
398+
if (grepl(paste0(bad.errors, collapse = "|"), errors, ignore.case = T) ||
399+
(grepl(paste0(bad.warnings, collapse = "|", warnings, ignore.case = T)))) {
400+
pheromone <- 0
401+
402+
# writes feedback about non-convergence and non-positive definite.
403+
if (length(summaryfile) > 0) {
404+
fit.info <- matrix(c(select.indicator, run, count, ant, 999, 999, round((include), 5)), 1, )
405+
write.table(fit.info,
406+
file = summaryfile, append = T,
407+
quote = F, sep = " ", row.names = F, col.names = F
408+
)
409+
}
410+
411+
# provide feedback about search.
412+
if (length(feedbackfile) > 0) {
413+
feedback <- c(paste("<h1>", run, "-", count, "-", ant, "-", step, "- Failure", "</h1>"))
414+
write(feedback, file = feedbackfile, append = T)
415+
}
416+
# finishes if for non-convergent cases.
398417
}
399-
# finishes if for non-convergent cases.
400-
} else {
418+
}
419+
else {
401420
modelInfo <- modelInfoExtract(
402421
modelCheckObj = modelCheck,
403422
fitIndices = fit.indices

man/antcolony.lavaan.Rd

Lines changed: 6 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)