Skip to content

Commit dae5540

Browse files
committed
fix benachmark all bug
1 parent a6a36dd commit dae5540

File tree

5 files changed

+346
-304
lines changed

5 files changed

+346
-304
lines changed

R/plssem.R

Lines changed: 14 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#
1717

1818
PLSSEMInternal <- function(jaspResults, dataset, options, ...) {
19+
1920
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/.")
2021

2122
options <- .plsSemPrepOpts(options)
@@ -24,6 +25,9 @@ PLSSEMInternal <- function(jaspResults, dataset, options, ...) {
2425
dataset <- .plsSemReadData(dataset, options)
2526
ready <- .plsSemIsReady(dataset, options)
2627

28+
saveRDS(dataset, "~/Downloads/dataset.rds")
29+
saveRDS(options, "~/Downloads/options.rds")
30+
2731
# Store in container
2832
modelContainer <- .plsSemModelContainer(jaspResults)
2933

@@ -146,7 +150,7 @@ checkCSemModel <- function(model, availableVars) {
146150

147151
# check for '~~'
148152
if (grepl("~~", vmodel)) {
149-
return(gettext("Using '~~' is not supported. Try '~' instead"))
153+
return(gettext("Using '~~' is not yet supported. Try '~' instead"))
150154
}
151155

152156
# if checks pass, return empty string
@@ -165,7 +169,7 @@ checkCSemModel <- function(model, availableVars) {
165169
"structuralModelIgnored", "innerWeightingScheme", "errorCalculationMethod",
166170
"bootstrapSamples", "ciLevel",
167171
"setSeed", "seed", "handlingOfInadmissibles", "endogenousIndicatorPrediction",
168-
"kFolds", "repetitions", "benchmark", "predictedScore", "models"))
172+
"kFolds", "repetitions", "benchmark", "models"))
169173
jaspResults[["modelContainer"]] <- modelContainer
170174
}
171175

@@ -257,7 +261,7 @@ checkCSemModel <- function(model, availableVars) {
257261
}
258262

259263
results[[i]] <- fit
260-
264+
saveRDS(fit, "~/Downloads/fit.rds")
261265
}
262266

263267
# store results in model container
@@ -897,7 +901,7 @@ checkCSemModel <- function(model, availableVars) {
897901

898902
predict <- createJaspContainer(gettext("Endogenous Indicator Prediction"))
899903
predict$position <- 2
900-
predict$dependOn(c("endogenousIndicatorPrediction", "models", "kFolds", "repetitions", "benchmark", "predictedScore"))
904+
predict$dependOn(c("endogenousIndicatorPrediction", "models", "kFolds", "repetitions", "benchmark"))
901905
modelContainer[["predict"]] <- predict
902906

903907
if (length(options[["models"]]) < 2) {
@@ -924,27 +928,12 @@ checkCSemModel <- function(model, availableVars) {
924928

925929
if (options[["benchmark"]] != "none" && options[["benchmark"]] != "all") {
926930
benchmarks <- options[["benchmark"]]
927-
}
928-
else if (options[["benchmark"]] == "all") {
929-
benchmarks <- c("lm", "PLS-PM", "GSCA", "PCA", "MAXVAR")
930-
benchmarks <- benchmarks[benchmarks != "PLS-PM"]
931+
} else if (options[["benchmark"]] == "all") {
932+
benchmarks <- c("lm", "GSCA", "PCA", "MAXVAR")
931933
} else {
932934
benchmarks <- NULL
933935
}
934936

935-
if (options[["benchmark"]] != "none" && options[["benchmark"]] != "all" && benchmarks == "PLS-PM") {
936-
errormsg <- gettextf("The target model uses the same weighting approach as the benchmark model, please choose another benchmark.")
937-
modelContainer$setError(errormsg)
938-
modelContainer$dependOn("benchmark")
939-
return()
940-
}
941-
if (options[["benchmark"]] == "all" && options[["predictedScore"]]) {
942-
errormsg <- gettextf("For the predicted indicator scores table(s), please select a single benchmark or 'none'.")
943-
modelContainer$setError(errormsg)
944-
modelContainer$dependOn("benchmark")
945-
return()
946-
}
947-
948937
#Create metrics table
949938
metricstab <- createJaspTable(gettext("Prediction Metrics"))
950939

@@ -956,9 +945,7 @@ checkCSemModel <- function(model, availableVars) {
956945
metricstab$addColumnInfo(name = "mae", title = gettext("Target MAE"), type = "number")
957946

958947
if("lm" %in% benchmarks)
959-
metricstab$addColumnInfo(name = "maelm", title = gettext("Linear model MAE"), type = "number")
960-
if("PLS-PM" %in% benchmarks)
961-
metricstab$addColumnInfo(name = "maePLS-PM", title = gettext("PLS-PM MAE"), type = "number")
948+
metricstab$addColumnInfo(name = "maelm", title = gettext("LM MAE"), type = "number")
962949
if("GSCA" %in% benchmarks)
963950
metricstab$addColumnInfo(name = "maeGSCA", title = gettext("GSCA MAE"), type = "number")
964951
if("PCA" %in% benchmarks)
@@ -969,9 +956,7 @@ checkCSemModel <- function(model, availableVars) {
969956
metricstab$addColumnInfo(name = "rmse", title = gettext(" Target RMSE"), type = "number")
970957

971958
if("lm" %in% benchmarks)
972-
metricstab$addColumnInfo(name = "rmselm", title = gettext("Linear model RMSE"), type = "number")
973-
if("PLS-PM" %in% benchmarks)
974-
metricstab$addColumnInfo(name = "rmsePLS-PM", title = gettext("PLS-PM RMSE"), type = "number")
959+
metricstab$addColumnInfo(name = "rmselm", title = gettext("LM RMSE"), type = "number")
975960
if("GSCA" %in% benchmarks)
976961
metricstab$addColumnInfo(name = "rmseGSCA", title = gettext("GSCA RMSE"), type = "number")
977962
if("PCA" %in% benchmarks)
@@ -1003,7 +988,7 @@ checkCSemModel <- function(model, availableVars) {
1003988
return()
1004989
}
1005990
progressbarTick()
1006-
prediction_list[i] <- prediction
991+
prediction_list[[benchmarks[i]]] <- prediction
1007992
}
1008993
} else if (options[["benchmark"]] == "none") {
1009994
prediction <- try(cSEM::predict(fit, .handle_inadmissibles = "ignore", .cv_folds = options[["kFolds"]], .r = options[["repetitions"]]))
@@ -1063,7 +1048,7 @@ checkCSemModel <- function(model, availableVars) {
10631048
metricstab[[paste0("rmse", benchmarks)]] <- unlist(lapply(prediction, function(x) x[["Prediction_metrics"]][["RMSE_benchmark"]]))
10641049
}
10651050

1066-
if(options[["benchmark"]] == "all") {
1051+
if (options[["benchmark"]] == "all") {
10671052
for (i in seq_along(benchmarks)) {
10681053
prediction <- prediction_list[[benchmarks[[i]]]]
10691054
metricstab[[paste0("mae", benchmarks[[i]])]] <- unlist(lapply(prediction, function(x) x[["Prediction_metrics"]][["MAE_benchmark"]]))

R/sem.R

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,6 @@
2020
SEMInternal <- function(jaspResults, dataset, options, ...) {
2121
jaspResults$addCitation("Rosseel, Y. (2012). lavaan: An R Package for Structural Equation Modeling. Journal of Statistical Software, 48(2), 1-36. URL http://www.jstatsoft.org/v48/i02/")
2222

23-
# sink(file="~/Downloads/log.txt")
24-
# on.exit(sink(NULL))
25-
2623
# Read dataset
2724
options <- .semPrepOpts(options)
2825

inst/qml/PLSSEM.qml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ Form
155155
Group
156156
{
157157
CheckBox { name: "rSquared"; label: qsTr("R-squared") }
158-
CheckBox { name: "additionalFitMeasures"; label: qsTr("Additional fit measures") }
158+
CheckBox { name: "additionalFitMeasures"; label: qsTr("Fit measures") }
159159
CheckBox { name: "mardiasCoefficient"; label: qsTr("Mardia's coefficient") }
160160
CheckBox { name: "reliabilityMeasures"; label: qsTr("Reliability measures") }
161161
}

0 commit comments

Comments
 (0)