|
100 | 100 | #' of ants in a row for which the model does not change.
|
101 | 101 | #' @param lavaan.model.specs A list which contains the specifications for the
|
102 | 102 | #' 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. |
104 | 109 | #' @param pheromone.calculation A character string specifying the method for
|
105 | 110 | #' calculating the pheromone strength. Must be one of "\code{gamma}"
|
106 | 111 | #' (standardized latent regression coefficients), "\code{beta}"
|
@@ -278,6 +283,16 @@ antcolony.lavaan <- function(data = NULL, sample.cov = NULL, sample.nobs = NULL,
|
278 | 283 | step <- 1
|
279 | 284 |
|
280 | 285 | # 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 |
281 | 296 | mapply(assign, names(lavaan.model.specs), lavaan.model.specs, MoreArgs = list(envir = antcolony.lavaan.env))
|
282 | 297 |
|
283 | 298 | # 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,
|
379 | 394 | warnings <- modelCheck@warnings
|
380 | 395 | errors <- modelCheck@errors
|
381 | 396 | # 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. |
398 | 417 | }
|
399 |
| - # finishes if for non-convergent cases. |
400 |
| - } else { |
| 418 | + } |
| 419 | + else { |
401 | 420 | modelInfo <- modelInfoExtract(
|
402 | 421 | modelCheckObj = modelCheck,
|
403 | 422 | fitIndices = fit.indices
|
|
0 commit comments