Skip to content

Commit

Permalink
symmetric check
Browse files Browse the repository at this point in the history
  • Loading branch information
juliuspfadt committed Oct 16, 2024
1 parent d4d2bcb commit 1095830
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
15 changes: 9 additions & 6 deletions R/confirmatoryfactoranalysis.R
Original file line number Diff line number Diff line change
Expand Up @@ -174,16 +174,19 @@ confirmatoryFactorAnalysisInternal <- function(jaspResults, dataset, options, ..
var_idx <- match(usedvars, colnames(dataset))
mat <- try(as.matrix(dataset[var_idx, var_idx]))
if (inherits(mat, "try-error") || any(is.na(mat)))
.quitAnalysis("Input data does not seem to be a covariance matrix! Please check the format of the input data.
All cells must be numeric, and the number of rows must equal the number of columns.")
.quitAnalysis(gettext("Input data does not seem to be a covariance matrix! Please check the format of the input data.
All cells must be numeric, and the number of rows must equal the number of columns."))

if (options[["group"]] != "") .quitAnalysis("Grouping variable not supported for covariance matrix input")
if (options[["group"]] != "") .quitAnalysis(gettext("Grouping variable not supported for covariance matrix input"))

if (options[["meanStructure"]]) .quitAnalysis("Mean structure not supported for covariance matrix input")
if (options[["meanStructure"]]) .quitAnalysis(gettext("Mean structure not supported for covariance matrix input"))

.hasErrors(mat, type = "varCovMatrix", message='default', exitAnalysisIfErrors = TRUE)

colnames(mat) <- rownames(mat) <- colnames(dataset)[var_idx]

if (!isSymmetric(as.matrix(mat))) .quitAnalysis(gettext("Input data does not seem to be a symmetric matrix! Please check the format of the input data."))

if (anyNA(mat)) {
inds <- which(is.na(mat))
mat <- mat[-inds, -inds]
Expand Down Expand Up @@ -243,7 +246,7 @@ confirmatoryFactorAnalysisInternal <- function(jaspResults, dataset, options, ..

if (anyNA(dataset)) {
naAction <- switch(
options$naAction,
options$naAction,
"twoStageRobust" = "robust.two.stage",
"twoStage" = "two.stage",
options$naAction)
Expand Down Expand Up @@ -345,7 +348,7 @@ confirmatoryFactorAnalysisInternal <- function(jaspResults, dataset, options, ..
"all" = "std.all",
"latentVariables" = "std.lv",
"noExogenousCovariates" = "std.nox")

if (options[["dataType"]] == "varianceCovariance") {
.quitAnalysis(gettext("Bootstrapping is not available for variance-covariance matrix input."))
}
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-confirmatoryfactoranalysis.R
Original file line number Diff line number Diff line change
Expand Up @@ -741,7 +741,7 @@ covMatrix <- cov(dt[, c("x1", "x2", "x3", "x4", "x5", "x6", "x7", "x8", "x9")])
covMatrix <- as.data.frame(covMatrix)

set.seed(1)
results <- jaspTools::runAnalysis("confirmatoryFactorAnalysis", covMatrix , options, makeTests = F)
results <- jaspTools::runAnalysis("confirmatoryFactorAnalysis", covMatrix, options, makeTests = F)


test_that("Chi-square test table results match", {
Expand Down

0 comments on commit 1095830

Please sign in to comment.