Skip to content

Commit

Permalink
fix cov input bug
Browse files Browse the repository at this point in the history
  • Loading branch information
juliuspfadt committed Jan 27, 2025
1 parent 8b4a1ca commit cd9c4ef
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion R/principalcomponentanalysis.R
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@ principalComponentAnalysisInternal <- function(jaspResults, dataset, options, ..
return(dataset)
}

# it seems the column names are sorted alphabetically when all columns are read
# so we need to sort the column names to match the order of the variables
sortedIndices <- sort(as.numeric(gsub(".*_(\\d+)_.*", "\\1", colnames(dataset))))
sortedNames <- paste0("JaspColumn_", sortedIndices, "_Encoded")
dataset <- dataset[, sortedNames]

# 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."))
Expand All @@ -87,6 +93,7 @@ principalComponentAnalysisInternal <- function(jaspResults, dataset, options, ..

usedvars <- unlist(options[["variables"]])
var_idx <- match(usedvars, colnames(dataset))

mat <- try(as.matrix(dataset[var_idx, var_idx]))
if (inherits(mat, "try-error"))
.quitAnalysis(gettext("All cells must be numeric."))
Expand All @@ -102,10 +109,11 @@ principalComponentAnalysisInternal <- function(jaspResults, dataset, options, ..
.quitAnalysis("Not enough valid columns to run this analysis")
}
}


return(mat)
}


.pcaCheckErrors <- function(dataset, options) {

customChecksPCAEFA <- list(
Expand Down

0 comments on commit cd9c4ef

Please sign in to comment.