Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix the add scores option for cov input #240

Merged
merged 4 commits into from
Oct 30, 2024
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
14 changes: 9 additions & 5 deletions R/confirmatoryfactoranalysis.R
Original file line number Diff line number Diff line change
Expand Up @@ -160,20 +160,24 @@ confirmatoryFactorAnalysisInternal <- function(jaspResults, dataset, options, ..

.cfaDataCovariance <- function(dataset, options) {


if (options[["dataType"]] == "raw") {
return(dataset)
}

# possible data matrix?
if ((nrow(dataset) != ncol(dataset)) && !all(dt[lower.tri(dt)] == t(dt)[lower.tri(dt)])) {
.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)

# are there any variables specified at all?
if (length(vars) == 0)
return(data.frame())

# possible data matrix?
if ((nrow(dataset) != ncol(dataset)))
.quitAnalysis(gettext("Input data does not seem to be a square matrix! Please check the format of the input data."))

if (!all(dataset[lower.tri(dataset)] == t(dataset)[lower.tri(dataset)]))
.quitAnalysis(gettext("Input data does not seem to be a symmetric matrix! Please check the format of the input data."))

duplicateVars <- duplicated(vars)
usedvars <- vars[!duplicateVars]
var_idx <- match(usedvars, colnames(dataset))
Expand Down
25 changes: 17 additions & 8 deletions R/exploratoryfactoranalysis.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ exploratoryFactorAnalysisInternal <- function(jaspResults, dataset, options, ...
# Read dataset
dataset <- .pcaAndEfaReadData(dataset, options)
ready <- length(options$variables) > 1
dataset <- .pcaAndEfaDataCovariance(dataset, options)
dataset <- .pcaAndEfaDataCovariance(dataset, options, ready)

if (ready)
.efaCheckErrors(dataset, options)
Expand Down Expand Up @@ -243,9 +243,11 @@ exploratoryFactorAnalysisInternal <- function(jaspResults, dataset, options, ...
if (options[["analysisBasedOn"]] == "polyTetrachoricCorrelationMatrix") {
polyTetraCor <- psych::mixedCor(dataset)
kmo <- psych::KMO(polyTetraCor$rho)
}
else{
kmo <- psych::KMO(dataset)
} else {
if (options[["dataType"]] == "raw")
kmo <- psych::KMO(dataset)
else
kmo <- psych::KMO(cov2cor(as.matrix(dataset)))
}

kmoTable[["col"]] <- c(gettext("Overall MSA\n"), names(kmo$MSAi))
Expand All @@ -269,9 +271,11 @@ exploratoryFactorAnalysisInternal <- function(jaspResults, dataset, options, ...
if (options[["analysisBasedOn"]] == "polyTetrachoricCorrelationMatrix") {
polyTetraCor <- psych::mixedCor(dataset)
bar <- psych::cortest.bartlett(polyTetraCor$rho, n = nrow(dataset))
}
else {
bar <- psych::cortest.bartlett(dataset)
} else {
if (options[["dataType"]] == "raw")
bar <- psych::cortest.bartlett(dataset)
else
bar <- psych::cortest.bartlett(cov2cor(as.matrix(dataset)))
}

bartlettTable[["chisq"]] <- bar[["chisq"]]
Expand Down Expand Up @@ -730,9 +734,14 @@ exploratoryFactorAnalysisInternal <- function(jaspResults, dataset, options, ...
plt <- plt + ggplot2::geom_point(na.rm = TRUE, size = max(0, 3 + log(10) - log(n_col)))
}

# theming with special legend thingy
# add axis lines and better breaks
plt <- plt +
jaspGraphs::geom_rangeframe() +
jaspGraphs::themeJaspRaw() +
ggplot2::scale_x_continuous(breaks = seq(1:n_col))

# theming with special legend thingy
plt <- plt +
ggplot2::theme(
legend.position = c(0.99, 0.95),
legend.justification = c(1, 1),
Expand Down
18 changes: 14 additions & 4 deletions R/principalcomponentanalysis.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ principalComponentAnalysisInternal <- function(jaspResults, dataset, options, ..
dataset <- .pcaAndEfaReadData(dataset, options)
ready <- length(options$variables) > 1

dataset <- .pcaAndEfaDataCovariance(dataset, options)
dataset <- .pcaAndEfaDataCovariance(dataset, options, ready)

if (ready)
.pcaCheckErrors(dataset, options)
Expand Down Expand Up @@ -69,16 +69,20 @@ principalComponentAnalysisInternal <- function(jaspResults, dataset, options, ..
}


.pcaAndEfaDataCovariance <- function(dataset, options) {
.pcaAndEfaDataCovariance <- function(dataset, options, ready) {

if (!ready) return()

if (options[["dataType"]] == "raw") {
return(dataset)
}

# possible data matrix?
if ((nrow(dataset) != ncol(dataset)) && !all(dt[lower.tri(dt)] == t(dt)[lower.tri(dt)])) {
if ((nrow(dataset) != ncol(dataset)))
.quitAnalysis(gettext("Input data does not seem to be a square matrix! Please check the format of the input data."))

if (!all(dataset[lower.tri(dataset)] == t(dataset)[lower.tri(dataset)]))
.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))
Expand Down Expand Up @@ -528,6 +532,12 @@ principalComponentAnalysisInternal <- function(jaspResults, dataset, options, ..
plt <- plt + ggplot2::geom_point(na.rm = TRUE, size = max(0, 3 + log(10) - log(n_col)))
}

# add axis lines and better breaks
plt <- plt +
jaspGraphs::geom_rangeframe() +
jaspGraphs::themeJaspRaw() +
ggplot2::scale_x_continuous(breaks = seq(1:n_col))

# theming with special legend thingy
plt <- plt +
jaspGraphs::themeJaspRaw() +
Expand Down
6 changes: 4 additions & 2 deletions inst/qml/ExploratoryFactorAnalysis.qml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ Form
RadioButtonGroup
{
name: "dataType"
id: dataType
columns: 2
RadioButton { value: "raw"; label: qsTr("Raw"); checked: true }
RadioButton
Expand Down Expand Up @@ -189,6 +190,7 @@ Form
}
RadioButton
{
enabled: dataType.value == "raw"
value: "polyTetrachoricCorrelationMatrix"
label: qsTr("Polychoric/tetrachoric correlation matrix")
}
Expand Down Expand Up @@ -269,7 +271,7 @@ Form
title: qsTr("Assumption checks")
CheckBox { name: "kaiserMeyerOlkinTest"; label: qsTr("KMO test") }
CheckBox { name: "bartlettTest"; label: qsTr("Bartlett's test") }
CheckBox { name: "mardiaTest"; label: qsTr("Mardia's test") }
CheckBox { name: "mardiaTest"; label: qsTr("Mardia's test") ; enabled: dataType.value == "raw" }
}
RadioButtonGroup
{
Expand All @@ -284,7 +286,7 @@ Form
id: addScores
name: "addScores"
label: qsTr("Add FA scores to data")
enabled: variables.count > 1
enabled: variables.count > 1 & dataType.value == "raw"

TextField {
name: "addedScoresPrefix"
Expand Down
6 changes: 4 additions & 2 deletions inst/qml/PrincipalComponentAnalysis.qml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ Form
RadioButtonGroup
{
name: "dataType"
id: dataType
columns: 2
RadioButton { value: "raw"; label: qsTr("Raw"); checked: true }
RadioButton
Expand Down Expand Up @@ -160,6 +161,7 @@ Form
}
RadioButton
{
enabled: dataType.value == "raw"
value: "polyTetrachoricCorrelationMatrix"
label: qsTr("Polychoric/tetrachoric correlation matrix")
}
Expand Down Expand Up @@ -236,7 +238,7 @@ Form
title: qsTr("Assumption checks")
CheckBox { name: "kaiserMeyerOlkinTest"; label: qsTr("KMO test") }
CheckBox { name: "bartlettTest"; label: qsTr("Bartlett's test") }
CheckBox { name: "mardiaTest"; label: qsTr("Mardia's test") }
CheckBox { name: "mardiaTest"; label: qsTr("Mardia's test") ; enabled: dataType.value == "raw" }
}

RadioButtonGroup
Expand All @@ -252,7 +254,7 @@ Form
id: addScores
name: "addScores"
label: qsTr("Add PC scores to data")
enabled: variables.count > 1
enabled: variables.count > 1 & dataType.value == "raw"

TextField {
name: "addedScoresPrefix"
Expand Down
Loading
Loading