Skip to content

Commit

Permalink
fix some more errors Frantisek found
Browse files Browse the repository at this point in the history
  • Loading branch information
juliuspfadt committed Oct 16, 2024
1 parent 072eb69 commit f858139
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 16 deletions.
9 changes: 5 additions & 4 deletions R/confirmatoryfactoranalysis.R
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,9 @@ confirmatoryFactorAnalysisInternal <- function(jaspResults, dataset, options, ..
return(dataset)
}

if (!isSymmetric(as.matrix(dataset))) .quitAnalysis(gettext("Input data does not seem to be a symmetric matrix! Please check the format of the input data."))
dtmp <- as.matrix(dataset)
colnames(dtmp) <- NULL # otherwise isSymmetric complains
if (!isSymmetric(as.matrix(dtmp))) .quitAnalysis(gettext("Input data does not seem to be a symmetric matrix! Please check the format of the input data."))

vars <- unlist(lapply(options[["factors"]], `[[`, "indicators"), use.names = FALSE)

Expand All @@ -175,9 +177,8 @@ confirmatoryFactorAnalysisInternal <- function(jaspResults, dataset, options, ..
usedvars <- vars[!duplicateVars]
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(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 (inherits(mat, "try-error"))
.quitAnalysis(gettext("All cells must be numeric."))

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

Expand Down
6 changes: 2 additions & 4 deletions R/exploratoryfactoranalysis.R
Original file line number Diff line number Diff line change
Expand Up @@ -215,10 +215,8 @@ exploratoryFactorAnalysisInternal <- function(jaspResults, dataset, options, ...
# I can use stop() because it's caught by the try and the message is put on
# on the modelcontainer.
if (ncomp == 0)
stop(
gettext("No factors with an eigenvalue > "), options$eigenValuesBox, ". ",
gettext("Maximum observed eigenvalue equals "), round(max(parallelResult$fa.values), 3)
)
.quitAnalysis( gettextf("No factors with an eigenvalue > %1$s. Maximum observed eigenvalue equals %2$s.",
options$eigenValuesAbove, round(max(parallelResult$fa.values), 3)))
return(ncomp)
}
}
Expand Down
16 changes: 8 additions & 8 deletions R/principalcomponentanalysis.R
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,16 @@ principalComponentAnalysisInternal <- function(jaspResults, dataset, options, ..
return(dataset)
}

if (!isSymmetric(as.matrix(dataset))) .quitAnalysis(gettext("Input data does not seem to be a symmetric matrix! Please check the format of the input data."))
dtmp <- as.matrix(dataset)
colnames(dtmp) <- NULL # otherwise isSymmetric complains
if (!isSymmetric(as.matrix(dtmp))) .quitAnalysis(gettext("Input data does not seem to be a symmetric matrix! Please check the format of the input data."))

usedvars <- unlist(options[["variables"]])
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.")
if (inherits(mat, "try-error"))
.quitAnalysis(gettext("All cells must be numeric."))

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

colnames(mat) <- rownames(mat) <- colnames(dataset)[var_idx]
Expand Down Expand Up @@ -261,10 +263,8 @@ principalComponentAnalysisInternal <- function(jaspResults, dataset, options, ..
# I can use stop() because it's caught by the try and the message is put on
# on the modelcontainer.
if (ncomp == 0)
stop(
gettext("No components with an eigenvalue > "), options$eigenValuesBox, ". ",
gettext("Maximum observed eigenvalue equals "), round(max(parallelResult$pc.values), 3)
)
.quitAnalysis( gettextf("No factors with an eigenvalue > %1$s. Maximum observed eigenvalue equals %2$s.",
options$eigenValuesAbove, round(max(parallelResult$fa.values), 3)))
return(ncomp)
}

Expand Down
2 changes: 2 additions & 0 deletions inst/qml/ExploratoryFactorAnalysis.qml
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ Form
label: qsTr("Number of factors")
defaultValue: 1
min: 1
max: variables.count > 1 ? variables.count : 1

}
}
}
Expand Down
1 change: 1 addition & 0 deletions inst/qml/PrincipalComponentAnalysis.qml
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ Form
label: qsTr("Number of components")
defaultValue: 1
min: 1
max: variables.count > 1 ? variables.count : 1
}
}
}
Expand Down

0 comments on commit f858139

Please sign in to comment.