Skip to content

Commit

Permalink
Update hardcoded models with flexible amount of mediators (6, 80, and…
Browse files Browse the repository at this point in the history
… 81)
  • Loading branch information
ThijsVroegh authored and maltelueken committed Sep 19, 2023
1 parent 7f57f57 commit beb8ef2
Show file tree
Hide file tree
Showing 2 changed files with 163 additions and 117 deletions.
241 changes: 143 additions & 98 deletions R/HardCodedModels.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#

.HardCodedModels <- function(number) {
.HardCodedModels <- function(number, k) {

# k = number of mediators

## TODO: Models involving moderated moderation 19,20,69,71,73
## TODO: Models involving flexible amount of mediators 6,80,81

if (number == 1) {
processRelationships <- list(
Expand Down Expand Up @@ -94,26 +95,7 @@
}

if (number == 6) {
processRelationships <- list(
list(
processDependent = "Y",
processIndependent = "X",
processType = "mediators",
processVariable = "M1"
),
list(
processDependent = "Y",
processIndependent = "X",
processType = "mediators",
processVariable = "M2"
),
list(
processDependent = "Y",
processIndependent = "M1",
processType = "mediators",
processVariable = "M2"
)
)
processRelationships <- .generateProcessRelationships_6(k)
}

if (number == 7) {
Expand Down Expand Up @@ -966,6 +948,8 @@
)
}

# Enable once multiple moderated moderation is working
#
# if (number == 69) {
# processRelationships <- list(
# list(
Expand Down Expand Up @@ -1154,85 +1138,11 @@
}

if (number == 80) {
processRelationships <- list(
list(
processDependent = "Y",
processIndependent = "X",
processType = "mediators",
processVariable = "M1"
),
list(
processDependent = "Y",
processIndependent = "X",
processType = "mediators",
processVariable = "Mk"
),
list(
processDependent = "Mk",
processIndependent = "X",
processType = "mediators",
processVariable = "M1"
),
list(
processDependent = "Mk",
processIndependent = "X",
processType = "mediators",
processVariable = "Mk-1"
),
list(
processDependent = "Y",
processIndependent = "M1",
processType = "mediators",
processVariable = "Mk"
),
list(
processDependent = "Y",
processIndependent = "Mk-1",
processType = "mediators",
processVariable = "Mk"
)
)
processRelationships <- .generateProcessRelationships_80(k)
}

if (number == 81) {
processRelationships <- list(
list(
processDependent = "Y",
processIndependent = "X",
processType = "mediators",
processVariable = "M1"
),
list(
processDependent = "Y",
processIndependent = "X",
processType = "mediators",
processVariable = "Mk"
),
list(
processDependent = "M2",
processIndependent = "X",
processType = "mediators",
processVariable = "M1"
),
list(
processDependent = "Mk",
processIndependent = "X",
processType = "mediators",
processVariable = "M1"
),
list(
processDependent = "Y",
processIndependent = "M1",
processType = "mediators",
processVariable = "M2"
),
list(
processDependent = "Y",
processIndependent = "M1",
processType = "mediators",
processVariable = "Mk"
)
)
processRelationships <- .generateProcessRelationships_81(k)
}

if (number == 82) {
Expand Down Expand Up @@ -1681,3 +1591,138 @@
}
return(varNames)
}

# model 6
.generateProcessRelationships_6 <- function(k) {

processRelationships <- list()

if (k >= 3) {
for (i in 1:(k - 2)) {
for (j in (i + 1):(k - 1)) {
for (k in (j + 1):k) {
path <- list(
processDependent = paste("M", k, sep = ""),
processIndependent = paste("M", i, sep = ""),
processType = "mediators",
processVariable = paste("M", j, sep = "")
)
processRelationships <- append(processRelationships, list(path))
}
}
}
}

if (k >= 2) {
for (i in 1:(k - 1)) {
for (j in (i + 1):k) {
path <- list(
processDependent = "Y",
processIndependent = paste("M", i, sep = ""),
processType = "mediators",
processVariable = paste("M", j, sep = "")
)
processRelationships <- append(processRelationships, list(path))
}
}
}

if (k >= 1) {
for (i in 1:k) {
path <- list(
processDependent = "Y",
processIndependent = "X",
processType = "mediators",
processVariable = paste("M", i, sep = "")
)
processRelationships <- append(processRelationships, list(path))
}
}

return(processRelationships)
}

# model 80
.generateProcessRelationships_80 <- function(k) {

processRelationships <- list()

if (k >= 2) {
for (i in 1:(k)) {

path1 <- list(
processDependent = "Y",
processIndependent = "X",
processType = "mediators",
processVariable = paste("M", i, sep = "")
)

processRelationships <- append(processRelationships, list(path1))
}
}

for (i in 1:k) {
for (j in 1:k) {
if (i != j && i < j && j == k ) {
path2 <- list(
processDependent = paste("M", j, sep = ""),
processIndependent = "X",
processType = "mediators",
processVariable = paste("M", i, sep = "")
)
path3 <- list(
processDependent = "Y",
processIndependent = paste("M", i, sep = ""),
processType = "mediators",
processVariable = paste("M", j, sep = "")
)
processRelationships <- append(processRelationships, list(path2,path3))
}
}
}

return(processRelationships)
}


# model 81
.generateProcessRelationships_81 <- function(k) {

processRelationships <- list()

if (k >= 2) {
for (i in 1:(k)) {

path1 <- list(
processDependent = "Y",
processIndependent = "X",
processType = "mediators",
processVariable = paste("M", i, sep = "")
)

processRelationships <- append(processRelationships, list(path1))
}
}

for (i in 1:k) {

if (i > 1 ) {
path2 <- list(
processDependent = paste("M", i, sep = ""),
processIndependent = "X",
processType = "mediators",
processVariable = paste("M1", sep = "")
)
path3 <- list(
processDependent = "Y",
processIndependent = paste("M1", sep = ""),
processType = "mediators",
processVariable = paste("M", i, sep = "")
)
processRelationships <- append(processRelationships, list(path2,path3))
}

}

return(processRelationships)
}
Loading

0 comments on commit beb8ef2

Please sign in to comment.