18
18
PLSSEMInternal <- function (jaspResults , dataset , options , ... ) {
19
19
jaspResults $ addCitation(" Rademaker ME, Schuberth F (2020). cSEM: Composite-Based Structural Equation Modeling. Package version: 0.4.0, https://m-e-rademaker.github.io/cSEM/." )
20
20
21
- sink(file = " ~/Downloads/log.txt" )
22
- on.exit(sink(NULL ))
21
+ # sink(file="~/Downloads/log.txt")
22
+ # on.exit(sink(NULL))
23
23
24
24
options <- .plsSemPrepOpts(options )
25
25
@@ -1140,12 +1140,12 @@ checkCSemModel <- function(model, availableVars) {
1140
1140
progressbarTick()
1141
1141
prediction_list [i ] <- prediction
1142
1142
}
1143
- }
1144
- else if (options [[" benchmark" ]] == " none" ) {
1143
+ } else if (options [[" benchmark" ]] == " none" ) {
1145
1144
prediction <- try(cSEM :: predict(fit , .handle_inadmissibles = " ignore" , .cv_folds = options [[" kFolds" ]], .r = options [[" repetitions" ]]))
1146
1145
} else {
1147
1146
prediction <- try(cSEM :: predict(fit , .handle_inadmissibles = " ignore" , .benchmark = benchmarks , .cv_folds = options [[" kFolds" ]], .r = options [[" repetitions" ]]))
1148
1147
}
1148
+
1149
1149
if (isTryError(prediction )) {
1150
1150
err <- .extractErrorMessage(prediction )
1151
1151
if (grepl(" attempt to set 'colnames'" , err ))
@@ -1215,9 +1215,10 @@ checkCSemModel <- function(model, availableVars) {
1215
1215
if (options [[" group" ]] != " " ) {
1216
1216
scorestab $ addColumnInfo(name = " group" , title = gettext(" Group" ), type = " string" , combine = TRUE )
1217
1217
group_names <- names(prediction )
1218
- indicator_names <- names(prediction [[group_names [1 ]]][[" Actual" ]])
1218
+ indicator_names <- names(prediction [[group_names [1 ]]][[" Actual" ]][[ 1 ]] )
1219
1219
} else {
1220
- indicator_names <- names(prediction [[" Actual" ]])
1220
+ indicator_names <- names(prediction [[" Actual" ]][[1 ]])
1221
+ # Actual list has as many datasets as Repetitions and the indicator names are columns names for each dataset
1221
1222
}
1222
1223
for (j in indicator_names ) {
1223
1224
scorestab $ addColumnInfo(name = paste0(" actual" , j ), title = gettext(" Actual scores" ), type = " number" , overtitle = gettext(j ))
@@ -1241,7 +1242,7 @@ checkCSemModel <- function(model, availableVars) {
1241
1242
group_i <- rep(i , length(prediction [[i ]][[" Actual" ]][[indicator_names [1 ]]]))
1242
1243
group_list <- c(group_list , group_i )
1243
1244
}
1244
- scorestab [[" group" ]] <- group_list
1245
+ scorestab [[" group" ]] <- group_list
1245
1246
for (j in indicator_names ) {
1246
1247
scorestab [[paste0(" actual" ,j )]] <- unlist(lapply(prediction , function (x ) x [[" Actual" ]][[j ]]))
1247
1248
scorestab [[paste0(" prediction" ,j )]] <- unlist(lapply(prediction , function (x ) x [[" Predictions_target" ]][, j ]))
@@ -1977,34 +1978,48 @@ checkCSemModel <- function(model, availableVars) {
1977
1978
1978
1979
modelNames <- sapply(models , function (x ) x [[" name" ]])
1979
1980
modelNames <- gsub(" " , " _" , modelNames )
1980
- allNamesR <- c()
1981
+ colNamesR <- c()
1982
+
1981
1983
# loop over the models
1982
1984
for (i in seq_len(length(results ))) {
1983
- scores <- cSEM :: getConstructScores(results [[i ]])$ Construct_scores
1984
1985
1985
- # then loop over the scores
1986
- scoreNames <- colnames(scores )
1987
- for (ii in seq_len(ncol(scores ))) {
1986
+ if (options $ group != " " ) {
1987
+ scoresList <- cSEM :: getConstructScores(results [[i ]])
1988
+ scores <- lapply(scoresList , function (x ) x $ Construct_scores )
1989
+ groupLabs <- names(scoresList )
1990
+ facNames <- colnames(scores [[1 ]])
1991
+ colNamesR <- paste0(rep(groupLabs , each = ncol(scores [[1 ]])), " _" , " CS_" , facNames )
1992
+ } else {
1993
+ scores <- cSEM :: getConstructScores(results [[i ]])$ Construct_scores
1994
+ facNames <- colnames(scores )
1995
+ colNamesR <- paste0(" CS_" , facNames )
1996
+ scores <- list (scores )
1997
+ }
1988
1998
1989
- colNameR <- paste0(modelNames [i ], " _" , scoreNames [ii ])
1999
+ z <- 1
2000
+ for (ll in seq_len(length(scores ))) {
2001
+ for (ii in seq_len(ncol(scores [[ll ]]))) {
1990
2002
1991
- if (jaspBase ::: columnExists(colNameR ) && ! jaspBase ::: columnIsMine(colNameR )) {
1992
- .quitAnalysis(gettextf(" Column '%s' name already exists in the dataset" , colNameR ))
1993
- }
2003
+ colNameR <- colNamesR [z ]
2004
+ scoresTmp <- scores [[ll ]]
2005
+ if (jaspBase ::: columnExists(colNameR ) && ! jaspBase ::: columnIsMine(colNameR )) {
2006
+ .quitAnalysis(gettextf(" Column name %s already exists in the dataset" , colNameR ))
2007
+ }
1994
2008
1995
- container [[colNameR ]] <- jaspBase :: createJaspColumn(colNameR )
1996
- container [[colNameR ]]$ setScale(scores [, ii ])
2009
+ container [[colNameR ]] <- jaspBase :: createJaspColumn(colNameR )
2010
+ container [[colNameR ]]$ setScale(scoresTmp [, ii ])
1997
2011
1998
- # save the names to keep track of all names
1999
- allNamesR <- c(allNamesR , colNameR )
2012
+ z <- z + 1
2013
+
2014
+ }
2000
2015
}
2001
2016
}
2002
2017
2003
2018
jaspResults [[" addedScoresContainer" ]] <- container
2004
2019
2005
2020
# check if there are previous colNames that are not needed anymore and delete the cols
2006
2021
oldNames <- jaspResults [[" createdColumnNames" ]][[" object" ]]
2007
- newNames <- allNamesR
2022
+ newNames <- colNamesR [ 1 : z ]
2008
2023
if (! is.null(oldNames )) {
2009
2024
noMatch <- which(! (oldNames %in% newNames ))
2010
2025
if (length(noMatch ) > 0 ) {
@@ -2015,7 +2030,7 @@ checkCSemModel <- function(model, availableVars) {
2015
2030
}
2016
2031
2017
2032
# save the created col names
2018
- jaspResults [[" createdColumnNames" ]] <- createJaspState(allNamesR )
2033
+ jaspResults [[" createdColumnNames" ]] <- createJaspState(newNames )
2019
2034
2020
2035
2021
2036
return ()
0 commit comments