From a9346821c3fb5554497f2069f636c43cf0065ed9 Mon Sep 17 00:00:00 2001 From: Julius Pfadt Date: Thu, 20 Apr 2023 16:16:59 +0200 Subject: [PATCH] failing to get the scores to work --- R/principalcomponentanalysis.R | 43 +++++++++++++++++++++---- inst/qml/ConfirmatoryFactorAnalysis.qml | 4 +-- inst/qml/PrincipalComponentAnalysis.qml | 15 +++++---- 3 files changed, 46 insertions(+), 16 deletions(-) diff --git a/R/principalcomponentanalysis.R b/R/principalcomponentanalysis.R index cbf9066a..8bd88450 100644 --- a/R/principalcomponentanalysis.R +++ b/R/principalcomponentanalysis.R @@ -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 @@ -245,8 +249,11 @@ principalComponentAnalysisInternal <- function(jaspResults, dataset, options, .. goodnessOfFitTable$addFootnote(message = gettext("Degrees of freedom below 0, model is unidentified."), symbol = gettext("Warning:")) } + .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 @@ -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() + } + diff --git a/inst/qml/ConfirmatoryFactorAnalysis.qml b/inst/qml/ConfirmatoryFactorAnalysis.qml index e2c9354c..8d0a28d7 100644 --- a/inst/qml/ConfirmatoryFactorAnalysis.qml +++ b/inst/qml/ConfirmatoryFactorAnalysis.qml @@ -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 } } diff --git a/inst/qml/PrincipalComponentAnalysis.qml b/inst/qml/PrincipalComponentAnalysis.qml index ed22f67a..d3c5ad2f 100644 --- a/inst/qml/PrincipalComponentAnalysis.qml +++ b/inst/qml/PrincipalComponentAnalysis.qml @@ -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 + // } } } }