[jaspFactor] Enable ordinal variable support in Exploratory Factor Analysis by...#331
Open
sisyphus-jasp wants to merge 1 commit intojasp-stats:masterfrom
Open
[jaspFactor] Enable ordinal variable support in Exploratory Factor Analysis by...#331sisyphus-jasp wants to merge 1 commit intojasp-stats:masterfrom
sisyphus-jasp wants to merge 1 commit intojasp-stats:masterfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes: jasp-stats/jasp-issues#4005
Root cause
R/principalcomponentanalysis.R,.pcaAndEfaCoerceToNumeric()usedvariableType %in% c("ordinal", "nominal") || ....variableTypewasNULL, first term becamelogical(0), which could propagate to an invalid/NA condition inif (conversionIntroducedNA && isCategorical)and error at runtime in fallback paths.What changed and why
isTypeCategorical <- !is.null(variableType) && variableType %in% c("ordinal", "nominal")isCategorical <- isTypeCategorical || is.factor(x) || is.ordered(x)variables.typesfallback safe.Verification
agentTestAll()=>FAIL: 0 | WARN: 0 | SKIP: 13 | PASS: 131.x <- c("A","1"), variableType = NULL) previously errored; after fix no error.factor(c("low","high")), variableType = NULL) no error.Caveats / reviewer checks
testAll()path lackedrunAnalysison search path; used documented fallbackagentTestAll()for valid full-suite verification.Implementation Plan
Root cause
In
R/principalcomponentanalysis.R,.pcaAndEfaCoerceToNumeric()computes:isCategorical <- variableType %in% c("ordinal", "nominal") || is.factor(x) || is.ordered(x).When
variableTypeisNULL,variableType %in% ...islogical(0). With non-factor input,isCategoricalcan becomeNA; thenif (conversionIntroducedNA && isCategorical)errors (missing value where TRUE/FALSE needed). This breaks fallback path whenoptions[["variables.types"]]is absent/incomplete.Proposed changes
R/principalcomponentanalysis.R.pcaAndEfaCoerceToNumeric()isTypeCategorical <- !is.null(variableType) && variableType %in% c("ordinal", "nominal")isCategorical <- isTypeCategorical || is.factor(x) || is.ordered(x)Expected test impact
NULLtype edge cases.REVIEW ITERATION 2 of 3
A code review agent examined your previous fix and found issues.
Your previous changes are still in the workspace.
REVIEWER FEEDBACK:
The fix addresses the reported root cause for labeled ordinal data in the common path, but
.pcaAndEfaCoerceToNumeric()has a correctness issue:isCategorical <- variableType %in% c("ordinal", "nominal") || ...is unsafe whenvariableTypeisNULL(your intended fallback case). In R,NULL %in% ...yieldslogical(0), andlogical(0) || ...triggers a length-0 logical error.This means the newly introduced fallback behavior can fail at runtime instead of gracefully handling missing
options[["variables.types"]].Actionable fix:
isTypeCategorical <- !is.null(variableType) && variableType %in% c("ordinal", "nominal")isCategorical <- isTypeCategorical || is.factor(x) || is.ordered(x).After that change, the patch should be in good shape for approval.
SPECIFIC ISSUES:
R/principalcomponentanalysis.R:.pcaAndEfaCoerceToNumeric()can error whenvariableTypeisNULLdue tological(0) || ...inisCategoricalcomputation, breaking the intended fallback path.Address the reviewer's feedback. You may skip Stage 1 (REPRODUCE).
ORIGINAL TASK:
Enable ordinal variable support in Exploratory Factor Analysis by computing polychoric correlations, reusing existing CFA implementation patterns
Test Results
Automated Code Review
Approved after 2 review iteration(s).