Skip to content

Commit

Permalink
failing to get the scores to work
Browse files Browse the repository at this point in the history
  • Loading branch information
juliuspfadt committed May 7, 2024
1 parent 74e28d3 commit a934682
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 16 deletions.
43 changes: 36 additions & 7 deletions R/principalcomponentanalysis.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
#

principalComponentAnalysisInternal <- function(jaspResults, dataset, options, ...) {

# sink(file="~/Downloads/log.txt")
# on.exit(sink(NULL))

jaspResults$addCitation("Revelle, W. (2018) psych: Procedures for Personality and Psychological Research, Northwestern University, Evanston, Illinois, USA, https://CRAN.R-project.org/package=psych Version = 1.8.12.")

# Read dataset
Expand Down Expand Up @@ -245,8 +249,11 @@ principalComponentAnalysisInternal <- function(jaspResults, dataset, options, ..
goodnessOfFitTable$addFootnote(message = gettext("Degrees of freedom below 0, model is unidentified."), symbol = gettext("<em>Warning:</em>"))
}


.pcaLoadingsTable <- function(modelContainer, dataset, options, ready) {

if (!is.null(modelContainer[["loadingsTable"]])) return()

loadingsTable <- createJaspTable(gettext("Component Loadings"))
loadingsTable$dependOn(c("loadingsDisplayLimit", "componentLoadingsOrder"))
loadingsTable$position <- 2
Expand Down Expand Up @@ -626,15 +633,37 @@ principalComponentAnalysisInternal <- function(jaspResults, dataset, options, ..
}

.pcaAddComponentsToData <- function(jaspResults, modelContainer, options, ready) {
if(!ready || !options[["addComponentScores"]] || options[["componentsPrefix"]] == "" || modelContainer$getError()) return()

if (!ready ||
!options[["addComponentScores"]] ||
modelContainer$getError() ||
!is.null(jaspResults[["addedScoresContainer"]])) {
return()
}

container <- createJaspContainer()
container$dependOn(optionsFromObject = modelContainer)

scores <- modelContainer[["model"]][["object"]][["scores"]]
for (i in 1:ncol(scores)) {
scorename <- paste0(options[["componentsPrefix"]], "_", i)
if (is.null(jaspResults[[scorename]])) {
jaspResults[[scorename]] <- createJaspColumn(scorename)
jaspResults[[scorename]]$dependOn(optionsFromObject = modelContainer)
jaspResults[[scorename]]$setScale(scores[, i])
baseNames <- gettextf("Component_%s", seq_len(ncol(scores)))
encodedNames <- jaspBase::createColumns(baseNames)

# print(length(container[[""]]))
if (length(encodedNames) == length(baseNames)) {
for (i in seq_len(ncol(scores))) {
container[[encodedNames[i]]] <- jaspBase::createJaspColumn(encodedNames[i])
container[[encodedNames[i]]]$setScale(scores[, i])
}
jaspResults[["addedScoresContainer"]] <- container

} else {
container <- NULL
jaspResults[["addedScoresContainer"]] <- NULL
}



return()

}

4 changes: 2 additions & 2 deletions inst/qml/ConfirmatoryFactorAnalysis.qml
Original file line number Diff line number Diff line change
Expand Up @@ -279,12 +279,12 @@ Form
{
title: qsTr("Options")
debug: true
CheckBox { label: qsTr("Fix manifest intercepts to zero") ; name: "manifestInterceptsFixedToZero" }
CheckBox { label: qsTr("Fix manifest intercepts to zero") ; name: "manifestInterceptsFixedToZero" }
CheckBox { label: qsTr("Fix latent intercepts to zero") ; name: "latentInterceptsFixedToZero"; checked: true }
CheckBox { label: qsTr("Omit residual single indicator") ; name: "residualSingleIndicatorOmitted"; checked: true }
CheckBox { label: qsTr("Residual variances") ; name: "residualVariances"; checked: true }
CheckBox { label: qsTr("Correlate exogenous latents") ; name: "exogenousLatentsCorrelated"; checked: true }
CheckBox { label: qsTr("Add thresholds") ; name: "thresholds"; checked: true }
CheckBox { label: qsTr("Add thresholds") ; name: "thresholds"; checked: true }
CheckBox { label: qsTr("Add scalings parameters") ; name: "scalingParamaters"; checked: true }
CheckBox { label: qsTr("Correlate dependent variables") ; name: "dependentVariablesCorrelated"; checked: true }
}
Expand Down
15 changes: 8 additions & 7 deletions inst/qml/PrincipalComponentAnalysis.qml
Original file line number Diff line number Diff line change
Expand Up @@ -237,18 +237,19 @@ Form

CheckBox
{
debug: true
id: addPC
name: "addComponentScores"
text: qsTr("Add PC scores to data")
enabled: variables.count > 1

ComputedColumnField {
name: "componentsPrefix"
text: "Prefix: "
fieldWidth: 120
visible: addPC.checked
}
// ComputedColumnField
// {
// name: "addComponentScoresPrefix"
// text: qsTr("Column prefix")
// placeholderText: qsTr("Score_")
// fieldWidth: 120
// enabled: addPC.checked
// }
}
}
}

0 comments on commit a934682

Please sign in to comment.