@@ -22,16 +22,16 @@ PLSSEMInternal <- function(jaspResults, dataset, options, ...) {
22
22
23
23
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/." )
24
24
25
- saveRDS( options , " ~/Downloads/options.rds " )
25
+
26
26
options <- .plsSemPrepOpts(options )
27
+ saveRDS(options , " ~/Downloads/options.rds" )
27
28
28
- # Read data, check if ready
29
- saveRDS (dataset , " ~/Downloads/dataset.rds " )
29
+ # Handle data, check if ready
30
+ # dataset <- .plsSemHandleData (dataset, options )
30
31
dataset <- .plsSemReadData(dataset , options )
31
32
ready <- .plsSemIsReady(dataset , options )
32
33
33
- print(str(dataset ))
34
-
34
+ saveRDS(dataset , " ~/Downloads/dataset.rds" )
35
35
36
36
# Store in container
37
37
modelContainer <- .plsSemModelContainer(jaspResults )
@@ -68,10 +68,18 @@ PLSSEMInternal <- function(jaspResults, dataset, options, ...) {
68
68
return (options )
69
69
}
70
70
71
+ .plsSemHandleData <- function (dataset , options ) {
72
+
73
+ # listwise deletion
74
+ dataset <- dataset [complete.cases(dataset ), ]
75
+ return (dataset )
76
+ }
77
+
71
78
.plsSemReadData <- function (dataset , options ) {
72
79
if (! is.null(dataset )) return (dataset )
73
80
74
81
variablesToRead <- if (options [[" group" ]] == " " ) character () else options [[" group" ]]
82
+
75
83
for (model in options [[" models" ]])
76
84
variablesToRead <- unique(c(variablesToRead , model [[" columns" ]]))
77
85
@@ -153,9 +161,35 @@ checkCSemModel <- function(model, availableVars) {
153
161
}
154
162
}
155
163
156
- # check for '~~'
157
- if (grepl(" ~~" , vmodel )) {
158
- return (gettext(" Using '~~' is not yet supported. Try '~' instead" ))
164
+ checkTildeTilde <- function (vmodel ) {
165
+ # Extract all lines with "~~"
166
+ lines <- unlist(strsplit(vmodel , " \n " ))
167
+ tildeLines <- grep(" ~~" , lines , value = TRUE )
168
+
169
+ # Extract variable pairs using a regex
170
+ variablePairs <- lapply(tildeLines , function (line ) {
171
+ match <- regexec(" \\ s*(\\ w+)\\ s*~~\\ s*(\\ w+)" , line )
172
+ subMatch <- regmatches(line , match )[[1 ]]
173
+ if (length(subMatch ) == 3 ) {
174
+ return (list (subMatch [2 ], subMatch [3 ]))
175
+ } else {
176
+ return (NULL )
177
+ }
178
+ })
179
+
180
+ # Clean up the result (remove NULLs)
181
+ variablePairs <- Filter(Negate(is.null ), variablePairs )
182
+ return (variablePairs )
183
+ }
184
+
185
+ checkTildeTilde(vmodel )
186
+ tildeResult <- checkTildeTilde(vmodel )
187
+ if (! is.null(tildeResult )) {
188
+ latents <- unique(rownames(parsed $ measurement ))
189
+ for (i in seq_along(tildeResult )) {
190
+ if (all(unlist(tildeResult [[i ]]) %in% latents ))
191
+ return (gettext(" Using '~~' is not supported for composite covariances. Try '~' instead" ))
192
+ }
159
193
}
160
194
161
195
# if checks pass, return empty string
@@ -565,7 +599,7 @@ checkCSemModel <- function(model, availableVars) {
565
599
pe [[" Total_effect" ]] <- list ()
566
600
pe [[" Total_effect" ]][[" mean" ]] <- summ $ Effect_estimates $ Total_effect $ Estimate
567
601
names(pe [[" Total_effect" ]][[" mean" ]]) <- summ $ Effect_estimates $ Total_effect $ Name
568
- } else {
602
+ } else {
569
603
IdxViFB <- 0
570
604
IdxViF <- 0
571
605
for (i in names(summ )) {
@@ -1743,14 +1777,14 @@ checkCSemModel <- function(model, availableVars) {
1743
1777
jaspResults [[" modelContainer" ]]$ getError() ||
1744
1778
! options [[" addConstructScores" ]]) {
1745
1779
1746
- cat(" ===== DID NOT ENTER =====\n " )
1780
+ # cat("===== DID NOT ENTER =====\n")
1747
1781
1748
1782
return ()
1749
1783
}
1750
1784
1751
- cat(" ===== ENTER: .plsAddConstructScores() =====\n " )
1752
- cat(" container scores: " )
1753
- print(is.null(jaspResults [[" addedScoresContainer" ]]))
1785
+ # cat("===== ENTER: .plsAddConstructScores() =====\n")
1786
+ # cat("container scores: ")
1787
+ # print(is.null(jaspResults[["addedScoresContainer"]]))
1754
1788
1755
1789
container <- createJaspContainer()
1756
1790
container $ dependOn(options = " addConstructScores" )
0 commit comments