Skip to content

Commit 534c3e1

Browse files
committed
fix encoded names display in total effects table
1 parent 7f4ae03 commit 534c3e1

File tree

4 files changed

+31
-17
lines changed

4 files changed

+31
-17
lines changed

R/sem.R

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
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+
2326
# Read dataset
2427
options <- .semPrepOpts(options)
2528

@@ -624,10 +627,10 @@ checkLavaanModel <- function(model, availableVars) {
624627
}
625628

626629
total_effects <- c()
627-
for (pred in unique(c(pred,regressions[[group]][["rhs"]]))) {
630+
for (pred in unique(c(pred, regressions[[group]][["rhs"]]))) {
628631
for (out in unique(c(out, regressions[[group]][["lhs"]]))) {
629632
total_effect <- NULL
630-
total_effect_name <- paste0("total_", groups[group], "_", pred, "_", out)
633+
total_effect_name <- paste0("total_", groups[group], "__", pred, "__", out)
631634
indirect_effect_idx <- unlist(lapply(names(indirect_effects), function(x) {
632635
startsWith(x, pred) && endsWith(x, out)
633636
}))
@@ -1195,10 +1198,6 @@ checkLavaanModel <- function(model, availableVars) {
11951198

11961199
}
11971200

1198-
# TODO: bootstrap standardized CI:
1199-
#' Do we want the standardization to happen for the fit of each bootstrap sample and then save the std coeffs?
1200-
#' Or do we want to save all the unstd coeffs from the bootstrap, and after summarizing them with mean
1201-
#' and se and such standardize them?
12021201

12031202
if (options[["group"]] != "") {
12041203
pe[pe[["op"]] != ":=", "groupname"] <- lavaan::lavInspect(fit, "group.label")[pe[["group"]]]
@@ -1382,8 +1381,22 @@ checkLavaanModel <- function(model, availableVars) {
13821381

13831382
path <- list()
13841383
for (idx in 1:nrow(pe_toteff)) {
1385-
path[[idx]] <- gsub("_", " \u2192 ", pe_toteff[idx, "lhs"])
1386-
path[[idx]] <- gsub("total \u2192", "", path[[idx]])
1384+
# path[[idx]] <- gsub("_", " \u2192 ", pe_toteff[idx, "lhs"])
1385+
# path[[idx]] <- gsub("total \u2192", "", path[[idx]])
1386+
1387+
# Step 1: Remove the "total_X__" prefix (X can be a number or word)
1388+
path[[idx]] <- gsub("^total_[^_]+__", "", pe_toteff[idx, "lhs"])
1389+
1390+
# Step 2: Decode any "JaspColumn_X_Encoded" variable names
1391+
matches <- regmatches(path[[idx]], gregexpr("JaspColumn_[0-9]+_Encoded", path[[idx]]))
1392+
if (length(matches[[1]]) > 0) {
1393+
decoded_matches <- sapply(matches[[1]], jaspBase::decodeColNames) # Decode each match
1394+
regmatches(path[[idx]], gregexpr("JaspColumn_[0-9]+_Encoded", path[[idx]])) <- list(decoded_matches)
1395+
}
1396+
1397+
# Step 3: Replace double underscores "__" with " → "
1398+
path[[idx]] <- gsub("__", " \u2192 ", path[[idx]])
1399+
13871400
for (group in groups)
13881401
path[[idx]] <- gsub(paste0(" ", group, " \u2192"), "", path[[idx]])
13891402

jaspSem.Rproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
Version: 1.0
2+
ProjectId: d2e2ff5f-0cf8-4e57-82f3-e5f5382b33f9
23

34
RestoreWorkspace: No
45
SaveWorkspace: No

renv.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,7 @@
502502
},
503503
"cluster": {
504504
"Package": "cluster",
505-
"Version": "2.1.6",
505+
"Version": "2.1.8",
506506
"Source": "Repository",
507507
"Repository": "CRAN",
508508
"Requirements": [
@@ -512,7 +512,7 @@
512512
"stats",
513513
"utils"
514514
],
515-
"Hash": "0aaa05204035dc43ea0004b9c76611dd"
515+
"Hash": "b361779da7f8b129a1859b6cf243ba58"
516516
},
517517
"coda": {
518518
"Package": "coda",
@@ -1531,15 +1531,15 @@
15311531
},
15321532
"nnet": {
15331533
"Package": "nnet",
1534-
"Version": "7.3-19",
1534+
"Version": "7.3-20",
15351535
"Source": "Repository",
15361536
"Repository": "CRAN",
15371537
"Requirements": [
15381538
"R",
15391539
"stats",
15401540
"utils"
15411541
],
1542-
"Hash": "2c797b46eea7fb58ede195bc0b1f1138"
1542+
"Hash": "c955edf99ff24a32e96bd0a22645af60"
15431543
},
15441544
"numDeriv": {
15451545
"Package": "numDeriv",

tests/testthat/test-sem.R

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ options$modelTest <- "standard"
8282
options$reliability <- TRUE
8383
options$ave <- TRUE
8484
options$htmt <- TRUE
85-
results <- jaspTools::runAnalysis("SEM", "poldem_grouped.csv", options)
85+
results <- jaspTools::runAnalysis("SEM", testthat::test_path("poldem_grouped.csv"), options)
8686

8787

8888
container <- results[["results"]][["modelContainer"]][["collection"]]
@@ -175,7 +175,7 @@ options$models = list(
175175
list(name = "more constrained", syntax = modelMoreConstrained)
176176
)
177177

178-
results <- jaspTools::runAnalysis("SEM", "poldem_grouped.csv", options)
178+
results <- jaspTools::runAnalysis("SEM", testthat::test_path("poldem_grouped.csv"), options)
179179

180180

181181
test_that("Model fit table results match", {
@@ -603,7 +603,7 @@ options$bootstrapCiType <- "percentile"
603603
options$bootstrapSamples <- 100
604604

605605
set.seed(1)
606-
results <- jaspTools::runAnalysis("SEM", testthat::test_path("poldem_grouped.csv"), options, makeTests = T)
606+
results <- jaspTools::runAnalysis("SEM", testthat::test_path("poldem_grouped.csv"), options, makeTests = F)
607607

608608
# Model fit table results match
609609
test_that("Bootstrapping model fit table works", {
@@ -830,7 +830,7 @@ options$models = list(
830830
list(name = "default", syntax = modelDefault)
831831
)
832832

833-
results <- jaspTools::runAnalysis("SEM", "poldem_grouped.csv", options)
833+
results <- jaspTools::runAnalysis("SEM", testthat::test_path("poldem_grouped.csv"), options)
834834

835835

836836
test_that("Residual covariances table results match", {
@@ -1023,7 +1023,7 @@ options$models <- list(list(name = "Model1",
10231023
syntax = list(model=model,
10241024
columns = c("x1", "x2", "x3", "y1", "y2", "y3", "y4", "y5", "y6", "y7", "y8"))))
10251025
set.seed(1)
1026-
results <- runAnalysis("SEM", "poldem_grouped.csv", options)
1026+
results <- runAnalysis("SEM", testthat::test_path("poldem_grouped.csv"), options)
10271027

10281028
test_that("Sensitivity parameters that led to a change in significance table results match", {
10291029
table <- results[["results"]][["modelContainer"]][["collection"]][["modelContainer_sensitivity"]][["collection"]][["modelContainer_sensitivity_senpar"]][["data"]]

0 commit comments

Comments
 (0)