diff --git a/.github/workflows/unittests.yml b/.github/workflows/unittests.yml index 6059693..0862afd 100644 --- a/.github/workflows/unittests.yml +++ b/.github/workflows/unittests.yml @@ -12,6 +12,7 @@ jobs: unit-tests: + if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name != github.event.pull_request.base.repo.full_name uses: jasp-stats/jasp-actions/.github/workflows/unittests.yml@master with: needs_JAGS: false diff --git a/R/networkanalysis.R b/R/networkanalysis.R index a95e56a..814440f 100644 --- a/R/networkanalysis.R +++ b/R/networkanalysis.R @@ -38,7 +38,7 @@ NetworkAnalysis <- function(jaspResults, dataset, options) { .networkAnalysisCentralityTable (mainContainer, network, options) .networkAnalysisClusteringTable (mainContainer, network, options) - .networkAnalysisPlotContainer (mainContainer, network, options) + .networkAnalysisPlotContainer (mainContainer, network, options, dataset) .networkAnalysisWeightMatrixTable(mainContainer, network, options) # done last so that all other results are shown already @@ -177,12 +177,13 @@ NetworkAnalysis <- function(jaspResults, dataset, options) { if (is.null(mainContainer)) { mainContainer <- createJaspContainer(dependencies = c( # data - "variables", "groupingVariable", "mgmVariableType", + "variables", "groupingVariable", # what kind of network is estimated "estimator", # arguments for the estimator "correlationMethod", "tuningParameter", "criterion", "isingEstimator", "nFolds", "split", "rule", "sampleSize", "thresholdBox", "thresholdString", "thresholdValue", + "mgmContinuousVariables", "mgmCategoricalVariables", "mgmCountVariables", # general arguments "weightedNetwork", "signedNetwork", "missingValues" )) @@ -199,7 +200,9 @@ NetworkAnalysis <- function(jaspResults, dataset, options) { if (is.null(mainContainer[["generalTable"]])) { tb <- createJaspTable(gettext("Summary of Network"), position = 1, dependencies = c( # These are dependencies because specifying them incorrectly is communicated as footnotes on this table - "computedLayoutX", "computedLayoutY", "bootstrap", "bootstrapSamples", "minEdgeStrength" + "computedLayoutX", "computedLayoutY", "bootstrap", "bootstrapSamples", "minEdgeStrength", + # these trigger recomputation in addition to footnotes + "mgmContinuousVariables", "mgmCategoricalVariables", "mgmCountVariables" )) if (length(dataset) > 1L) tb$addColumnInfo(name = "info", title = gettext("Network"), type = "string") @@ -462,7 +465,7 @@ NetworkAnalysis <- function(jaspResults, dataset, options) { } # plots ---- -.networkAnalysisPlotContainer <- function(mainContainer, network, options) { +.networkAnalysisPlotContainer <- function(mainContainer, network, options, dataset) { plotContainer <- mainContainer[["plotContainer"]] if (is.null(plotContainer)) { @@ -471,7 +474,7 @@ NetworkAnalysis <- function(jaspResults, dataset, options) { mainContainer[["plotContainer"]] <- plotContainer } - .networkAnalysisNetworkPlot (plotContainer, network, options) + .networkAnalysisNetworkPlot (plotContainer, network, options, dataset = dataset) .networkAnalysisCentralityPlot(plotContainer, network, options) .networkAnalysisClusteringPlot(plotContainer, network, options) } @@ -669,7 +672,7 @@ NetworkAnalysis <- function(jaspResults, dataset, options) { )) } -.networkAnalysisNetworkPlot <- function(plotContainer, network, options, method = "frequentist") { +.networkAnalysisNetworkPlot <- function(plotContainer, network, options, method = "frequentist", dataset = NULL) { if (!is.null(plotContainer[["networkPlotContainer"]]) || !options[["networkPlot"]]) return() @@ -755,7 +758,10 @@ NetworkAnalysis <- function(jaspResults, dataset, options) { idx[options[["variables"]] %in% options[[nms[[i]]]]] <- i # idx[i] is 1 if variable[i] %in% mgmContinuousVariables, 2 if in mgmCategoricalVariables, etc. - ll <- lengths(options[c("mgmContinuousVariables", "mgmCategoricalVariables", "mgmCountVariables")]) + # order of variables need not match dataset, and thus the order of types may be wrong + newOrder <- match(colnames(dataset[[1L]]), options[["variables"]]) + # now we have variables[newOrder] == colnames(dataset[[1L]]) + idx <- idx[newOrder] if (options[["mgmVariableTypeShown"]] == "nodeShape") { # gaussian, categorical, poisson @@ -1002,6 +1008,11 @@ NetworkAnalysis <- function(jaspResults, dataset, options) { } } + # order of variables need not match dataset, and thus the order of types may be wrong + newOrder <- match(colnames(dataset[[1L]]), variables) + # now we have variables[newOrder] == colnames(dataset[[1L]]) + type <- type[newOrder] + if (any(type == "")) { message <- gettext("Please drag all variables to a particular type under \"Analysis options\".") e <- structure(class = c("mgmError", "error", "condition"), list(message = message, call = sys.call(-1))) @@ -1104,10 +1115,19 @@ NetworkAnalysis <- function(jaspResults, dataset, options) { # for every dataset do the analysis for (nw in seq_along(dataset)) { + data <- dataset[[nw]] + + # mgm requires integer instead of factor + if (options[["estimator"]] == "mgm") { + for (i in seq_along(data)) + if (!is.numeric(data[[i]])) + data[[i]] <- as.integer(data[[i]]) + } + jaspBase::.suppressGrDevice( msg <- capture.output( network <- bootnet::estimateNetwork( - data = dataset[[nw]], + data = data, default = .networkAnalysisJaspToBootnetEstimator(options[["estimator"]]), .dots = .dots ) diff --git a/inst/qml/NetworkAnalysis.qml b/inst/qml/NetworkAnalysis.qml index 2be6970..3abf2ed 100644 --- a/inst/qml/NetworkAnalysis.qml +++ b/inst/qml/NetworkAnalysis.qml @@ -213,9 +213,9 @@ Form source: ["variables"] } - AssignedVariablesList { name: "mgmContinuousVariables"; title: qsTr("Continuous Variables"); allowedColumns: ["scale"]} - AssignedVariablesList { name: "mgmCategoricalVariables"; title: qsTr("Categorical Variables"); allowedColumns: ["ordinal"]} - AssignedVariablesList { name: "mgmCountVariables"; title: qsTr("Count Variables"); allowedColumns: ["nominal"]} + AssignedVariablesList { name: "mgmContinuousVariables"; title: qsTr("Continuous Variables"); } + AssignedVariablesList { name: "mgmCategoricalVariables"; title: qsTr("Categorical Variables"); } + AssignedVariablesList { name: "mgmCountVariables"; title: qsTr("Count Variables"); } } } @@ -383,7 +383,7 @@ Form { name: "mgmVariableTypeShown"; title: qsTr("Show Variable Type") - visible: [7].includes(estimator.currentIndex) + visible: [6].includes(estimator.currentIndex) RadioButton { value: "hide"; label: qsTr("Don't show") } RadioButton { value: "nodeColor"; label: qsTr("Using node color") } RadioButton { value: "nodeShape"; label: qsTr("Using node shape"); checked: true }