Skip to content

Commit

Permalink
Rename .HardCodedModels to .procGetHardCodedModel and Hmodels t…
Browse files Browse the repository at this point in the history
…o `.procHardcodedModelNumbers`
  • Loading branch information
maltelueken committed Sep 20, 2023
1 parent a908666 commit 483064d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 18 deletions.
11 changes: 10 additions & 1 deletion R/HardCodedModels.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,16 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#

.HardCodedModels <- function(number, k) {
# Existing Hayes models
.procHardCodedModelNumbers <- function() {
return(c(
1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,
21,22,28,29,58,59,60,61,62,63,64,65,66,67,68,70,
72,75,76,80,81,82,83,84,85,86,87,88,89,90,91,92
))
}

.procGetHardCodedModel <- function(number, k) {

# k = number of mediators

Expand Down
24 changes: 7 additions & 17 deletions R/classicProcess.R
Original file line number Diff line number Diff line change
Expand Up @@ -140,16 +140,12 @@ ClassicProcess <- function(jaspResults, dataset = NULL, options) {
}

.procModelRegListSingleModel <- function(modelOptions, globalDependent,options) {
# Existing Hayes models
# Hmodels <- c(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,
# 21,22,28,29,58,59,60,61,62,63,64,65,66,67,68,69,70,
# 71,72,73,75,76,80,81,82,83,84,85,86,87,88,89,90,91,92)
processRelationships <- switch(modelOptions[["inputType"]],
inputVariables = modelOptions[["processRelationships"]],
# Insert function for plotting conceptual hard-coded Hayes model, in case
# no estimation takes place yet (because of not having filled in all necessary
# variables)
inputModelNumber = .HardCodedModels(modelOptions[["modelNumber"]], length(modelOptions[["modelNumberMediators"]]))
inputModelNumber = .procGetHardCodedModel(modelOptions[["modelNumber"]], length(modelOptions[["modelNumberMediators"]]))
)
## TODO: Models involving moderated moderation 19,20,69,71,73

Expand Down Expand Up @@ -417,28 +413,22 @@ ClassicProcess <- function(jaspResults, dataset = NULL, options) {

.procIsModelNumberGraph <- function(modelNumber, graph, modelOptions, globalDependent) {
# Create regList from hard-coded model
regList <- .procProcessRelationshipsToRegList(.HardCodedModels(modelNumber, length(modelOptions[["modelNumberMediators"]])))
regList <- .procProcessRelationshipsToRegList(.procGetHardCodedModel(modelNumber, length(modelOptions[["modelNumberMediators"]])))

# Replace dummy variables in regList
regList <- .procRegListInputModelNumber(regList, modelOptions, globalDependent)
# Convert hard-coded regList to graph
modelNumberGraph <- .procRegListToGraph(regList)
# Check if user graph and hard-coded graph are identical (except for order of vertices)
isIdentical <- igraph::identical_graphs(modelNumberGraph, graph)

return(isIdentical)
}

.procRecognizeModelNumber <- function(regList) {
# Create graph from regList specified by user
graphM <- .procRegListToGraph(regList)

# Hayes models currently specified in HardCodedModels
Hmodels <- c(1,2,4,5,6,7,8,9,10,14,15,16,17,
21,22,28,29,58,59,60,61,62,63,
64,65,66,67,75,76,80,81,82,83,
84,85,86,87,88,89,90,91,92)

# Get global dependent variable
isDep <- sapply(regList, function(row) row$dep)
globalDependent <- names(regList)[isDep]
Expand Down Expand Up @@ -467,17 +457,17 @@ ClassicProcess <- function(jaspResults, dataset = NULL, options) {
)

# Check which hard-coded model matches user model
modelMatch <- sapply(Hmodels, .procIsModelNumberGraph, graph = graphM, modelOptions = modelOptions, globalDependent = globalDependent)
modelMatch <- sapply(.procHardCodedModelNumbers(), .procIsModelNumberGraph, graph = graphM, modelOptions = modelOptions, globalDependent = globalDependent)

# If no match swap W and Z and check again
if (!any(modelMatch)) {
modelOptions[["modelNumberModeratorW"]] <- modZ
modelOptions[["modelNumberModeratorZ"]] <- modW

modelMatch <- sapply(Hmodels, .procIsModelNumberGraph, graph = graphM, modelOptions = modelOptions, globalDependent = globalDependent)
modelMatch <- sapply(.procHardCodedModelNumbers(), .procIsModelNumberGraph, graph = graphM, modelOptions = modelOptions, globalDependent = globalDependent)
}

return(Hmodels[modelMatch])
return(.procHardCodedModelNumbers()[modelMatch])
}

.procAddLavModVar <- function(regList, dependent, variable) {
Expand Down

0 comments on commit 483064d

Please sign in to comment.