Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: R-CMD-check

on:
push:
pull_request:

jobs:
R-CMD-check:
name: ${{ matrix.os }} / R ${{ matrix.r }}
runs-on: ${{ matrix.os }}

strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
r: [release]

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up R
uses: r-lib/actions/setup-r@v2
with:
r-version: ${{ matrix.r }}
use-public-rspm: true

- name: Set up pandoc
uses: r-lib/actions/setup-pandoc@v2

- name: Install system dependencies
uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: |
any::rcmdcheck
needs: check

- name: Check package
uses: r-lib/actions/check-r-package@v2
with:
upload-snapshots: true
19 changes: 10 additions & 9 deletions R/ACO.R
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ setMethod('show',
#'
#' @importFrom ggrepel geom_text_repel
#' @importFrom tidyr gather
#' @importFrom rlang .data
#'
#' @export
setMethod('plot',
Expand All @@ -91,12 +92,12 @@ setMethod('plot',
pheromone_plot <-
ggplot2::ggplot(
pheromone_long,
ggplot2::aes_string(
x = "run",
y = "Pheromone",
group = "Item",
fill = "Item",
colour = "Item"
ggplot2::aes(
x = .data$run,
y = .data$Pheromone,
group = .data$Item,
fill = .data$Item,
colour = .data$Item
)
) +
ggplot2::geom_area(
Expand All @@ -122,7 +123,7 @@ setMethod('plot',
gamma_plot <-
ggplot2::ggplot(
summary_results,
ggplot2::aes_string(x = "run", y = "mean.gamma")
ggplot2::aes(x = .data$run, y = .data$mean.gamma)
) +
ggplot2::geom_line() +
ggplot2::ylab(expression("Mean " * gamma)) +
Expand All @@ -147,7 +148,7 @@ setMethod('plot',
beta_plot <-
ggplot2::ggplot(
summary_results,
ggplot2::aes_string(x = "run", y = "mean.beta")
ggplot2::aes(x = .data$run, y = .data$mean.beta)
) +
ggplot2::geom_line() +
ggplot2::ylab(expression("Mean " * beta)) +
Expand All @@ -172,7 +173,7 @@ setMethod('plot',
variance_plot <-
ggplot2::ggplot(
summary_results,
ggplot2::aes_string(x = "run", y = "mean.var.exp")
ggplot2::aes(x = .data$run, y = .data$mean.var.exp)
) +
ggplot2::geom_line() +
ggplot2::ylab(expression("Mean Variance Explained")) +
Expand Down
62 changes: 59 additions & 3 deletions R/ACO_lavaan.R
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,49 @@
#' )
#'
#' abilityShortForm # print the results of the final short form
#'
#' # an example using binary (ordered) data
#' # create the simulated full model and model data
#' sim_model <- "
#' f1 =~ x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9 + x10
#' f2 =~ x11 + x12 + x13 + x14 + x15 + x16 + x17 + x18 + x19 + x20
#' f3 =~ x21 + x22 + x23 + x24 + x25 + x26 + x27 + x28 + x29 + x30"
#'
#' sim_data <-
#' cbind(
#' psych::sim.rasch(nvar = 10)$items,
#' psych::sim.rasch(nvar = 10)$items,
#' psych::sim.rasch(nvar = 10)$items
#' )
#'
#' colnames(sim_data) = paste0("x", 1:30)
#' # fit with antcolony.lavaan
#' # note that ONLY the estimator and ordered args
#' # of lavaan.model.specs are changed. This retains
#' # the default args, fitting a CFA but with ordered data.
#' example <-
#' antcolony.lavaan(
#' data = sim_data,
#' ants = 5, evaporation = 0.7,
#' antModel = sim_model,
#' lavaan.model.specs =
#' list(estimator = "wlsmv", ordered = T),
#' list.items = list(paste0('x', 1:10),
#' paste0('x', 11:20),
#' paste0('x', 21:30)),
#' full = 30,
#' i.per.f = c(5, 5, 5),
#' factors = c("f1", "f2", "f3"),
#' steps = 20,
#' fit.indices = c("cfi.scaled"),
#' fit.statistics.test = "(cfi.scaled > 0.90)",
#' summaryfile = NULL,
#' feedbackfile = NULL,
#' max.run = 500,
#' parallel = T
#' )
#' # note that this example will take a bit of time to run
#' # as ordered data factor analysis is computationally expensive.
#' }
#' @import lavaan utils
#' @export
Expand Down Expand Up @@ -364,7 +407,20 @@ antcolony.lavaan <- function(data = NULL, sample.cov = NULL, sample.nobs = NULL,
select.indicator <- is.element(item.vector, selected.vector)

# MODIFY LAVAAN SYNTAX
new_ant_model <- paste(antcolony.lavaan.env$input, collapse = "\n")
new_ant_model <-
input
for (factor in 1:length(factors)) {
temp_factor_definition <-
new_ant_model[grepl(factors[factor], new_ant_model)]
temp_factor_definition <-
sub(
"=~[[:alnum:][:space:] +]{1,}",
paste0("=~ ", paste0(selected.items[[factor]], collapse = " + ")),
temp_factor_definition
)
new_ant_model[grepl(factors[factor], new_ant_model)] <-
temp_factor_definition
}

# Run the model check function
# checks for and saves error/warning messages within the lavaan output,
Expand Down Expand Up @@ -491,8 +547,8 @@ antcolony.lavaan <- function(data = NULL, sample.cov = NULL, sample.nobs = NULL,
antResults[[bestAnt,'pheromone']]


# adjusts pheromone and best.so.far values only if the current pheromone is best than the previous.
if (best.pheromone > best.so.far.pheromone) {
# adjusts pheromone and best.so.far values only if the current pheromone is as good or better than the previous.
if (best.pheromone >= best.so.far.pheromone) {
include.pheromone <- antResults[[bestAnt, 'solution']] * best.pheromone
include <- include + include.pheromone

Expand Down
2 changes: 1 addition & 1 deletion R/simulated_annealing_internals.R
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ randomInitialModel <-
)
}
newModelSyntax <-
paste0(newModelSyntax, externalRelation, factorRelation, collapse = "\n")
paste(newModelSyntax, externalRelation, factorRelation, sep = "\n")
newModelSyntax <-
stringr::str_replace_all(newModelSyntax, "\n\n", "\n")

Expand Down
Binary file removed README-ACO example-1.png
Binary file not shown.
Binary file removed README-ACO example-2.png
Binary file not shown.
Binary file removed README-ACO example-3.png
Binary file not shown.
Binary file removed README-ACO example-4.png
Binary file not shown.
Binary file removed README-Simulated Annealing example-1.png
Binary file not shown.
Binary file removed README-Tabu example-1.png
Binary file not shown.
Binary file removed README-Tabu short form-1.png
Binary file not shown.
Binary file added README-quick-example-ACO-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added README-quick-example-ACO-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added README-quick-example-ACO-3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added README-quick-example-ACO-4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added README-quick-example-SA-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading