Skip to content

Commit

Permalink
Merge branch 'master' into easybgminJASP
Browse files Browse the repository at this point in the history
Merge branch 'master' into easybgminJASP

# Conflicts:
#	R/bayesiannetworkanalysis.R
#	inst/qml/BayesianNetworkAnalysis.qml
  • Loading branch information
sekulovskin committed Dec 11, 2024
2 parents 86ef220 + 4f5cdf8 commit 9a8e0e8
Show file tree
Hide file tree
Showing 12 changed files with 91 additions and 70 deletions.
1 change: 1 addition & 0 deletions .github/workflows/unittests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
43 changes: 33 additions & 10 deletions R/networkanalysis.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -95,8 +95,11 @@ NetworkAnalysis <- function(jaspResults, dataset, options) {

# check if data must be binarized
if (options[["estimator"]] %in% c("isingFit", "isingSampler")) {
idx <- colnames(dataset) != options[["groupingVariable"]]
dataset[idx] <- bootnet::binarize(dataset[idx], split = options[["split"]], verbose = FALSE, removeNArows = FALSE)

for (i in seq_along(dataset)) {
idx <- colnames(dataset[[i]]) != options[["groupingVariable"]]
dataset[[i]][idx] <- bootnet::binarize(dataset[[i]][idx], split = options[["split"]], verbose = FALSE, removeNArows = FALSE)
}

if (options[["estimator"]] == "isingFit") {
# required check since isingFit removes these variables from the analyses
Expand Down Expand Up @@ -177,12 +180,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"
))
Expand All @@ -199,7 +203,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")
Expand Down Expand Up @@ -462,7 +468,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)) {
Expand All @@ -471,7 +477,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)
}
Expand Down Expand Up @@ -669,7 +675,7 @@ NetworkAnalysis <- function(jaspResults, dataset, options) {
))
}

.networkAnalysisNetworkPlot <- function(plotContainer, network, options, method = "frequentist") {
.networkAnalysisNetworkPlot <- function(plotContainer, network, options, method = "frequentist", dataset = NULL) {


# Adjust options based on method
Expand Down Expand Up @@ -763,7 +769,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
Expand Down Expand Up @@ -1010,6 +1019,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)))
Expand Down Expand Up @@ -1112,10 +1126,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
)
Expand Down
Binary file modified inst/po/zh_Hans/LC_MESSAGES/R-jaspNetwork.mo
Binary file not shown.
4 changes: 2 additions & 2 deletions inst/qml/BayesianNetworkAnalysis.qml
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ VariablesForm
CheckBox { name: "manualColor"; label: qsTr("Manual colors"); id: manualColor }
DropDown
{
enabled: !manualColors.checked
enabled: !manualColor.checked
id: paletteSelector
name: "nodePalette"
label: qsTr("Node palette")
Expand Down Expand Up @@ -410,7 +410,7 @@ VariablesForm
Group
{
title: qsTr("Measures shown in centrality plot")
enabled: plotCentrality.checked
enabled: centralityPlot.checked
CheckBox { name: "betweenness"; label: qsTr("Betweenness"); checked: true }
CheckBox { name: "closeness"; label: qsTr("Closeness"); checked: true }
CheckBox { name: "strength"; label: qsTr("Strength"); checked: true }
Expand Down
8 changes: 4 additions & 4 deletions inst/qml/NetworkAnalysis.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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"); }
}
}

Expand Down Expand Up @@ -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 }
Expand Down
Binary file modified inst/qml/translations/jaspNetwork-es.qm
Binary file not shown.
Binary file modified inst/qml/translations/jaspNetwork-gl.qm
Binary file not shown.
Binary file modified inst/qml/translations/jaspNetwork-zh_Hans.qm
Binary file not shown.
28 changes: 14 additions & 14 deletions po/QML-es.po
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ msgstr "Excluir por lista"

msgctxt "NetworkAnalysis|"
msgid "Sample Size"
msgstr "Tamaño de la Muestra"
msgstr "Tamaño de la muestra"

msgctxt "NetworkAnalysis|"
msgid "Maximum"
Expand Down Expand Up @@ -254,7 +254,7 @@ msgstr "Opciones de Bootstrap"

msgctxt "NetworkAnalysis|"
msgid "Settings"
msgstr "Configuraciones"
msgstr "Configuración"

msgctxt "NetworkAnalysis|"
msgid "Bootstrap network"
Expand Down Expand Up @@ -326,27 +326,27 @@ msgstr "Color del grupo"

msgctxt "NetworkAnalysis|"
msgid "red"
msgstr "rojo"
msgstr "Rojo"

msgctxt "NetworkAnalysis|"
msgid "blue"
msgstr "azul"
msgstr "Azul"

msgctxt "NetworkAnalysis|"
msgid "yellow"
msgstr "amarillo"
msgstr "Amarillo"

msgctxt "NetworkAnalysis|"
msgid "green"
msgstr "verde"
msgstr "Verde"

msgctxt "NetworkAnalysis|"
msgid "purple"
msgstr "violeta"
msgstr "Violeta"

msgctxt "NetworkAnalysis|"
msgid "orange"
msgstr "anaranjado"
msgstr "Anaranjado"

msgctxt "NetworkAnalysis|"
msgid "Group"
Expand Down Expand Up @@ -718,27 +718,27 @@ msgstr "Color del grupo"

msgctxt "BayesianNetworkAnalysis|"
msgid "red"
msgstr "rojo"
msgstr "Rojo"

msgctxt "BayesianNetworkAnalysis|"
msgid "blue"
msgstr "azul"
msgstr "Azul"

msgctxt "BayesianNetworkAnalysis|"
msgid "yellow"
msgstr "amarillo"
msgstr "Amarillo"

msgctxt "BayesianNetworkAnalysis|"
msgid "green"
msgstr "verde"
msgstr "Verde"

msgctxt "BayesianNetworkAnalysis|"
msgid "purple"
msgstr "violeta"
msgstr "Violeta"

msgctxt "BayesianNetworkAnalysis|"
msgid "orange"
msgstr "anaranjado"
msgstr "Anaranjado"

msgctxt "BayesianNetworkAnalysis|"
msgid "Variables in network"
Expand Down
26 changes: 13 additions & 13 deletions po/QML-gl.po
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ msgstr "CIR"

msgctxt "NetworkAnalysis|"
msgid "red"
msgstr "vermello"
msgstr "Vermello"

msgctxt "NetworkAnalysis|"
msgid "EBIC"
Expand Down Expand Up @@ -106,7 +106,7 @@ msgstr "STARS"

msgctxt "NetworkAnalysis|"
msgid "green"
msgstr "verde"
msgstr "Verde"

msgctxt "NetworkAnalysis|"
msgid "Min edge strength"
Expand Down Expand Up @@ -278,15 +278,15 @@ msgstr "Regresións univariantes"

msgctxt "NetworkAnalysis|"
msgid "orange"
msgstr "laranxa"
msgstr "Laranxa"

msgctxt "NetworkAnalysis|"
msgid "Edge labels"
msgstr "Etiquetas das beiras"

msgctxt "NetworkAnalysis|"
msgid "purple"
msgstr "morado"
msgstr "Morado"

msgctxt "NetworkAnalysis|"
msgid "name for y-coordinates"
Expand All @@ -302,7 +302,7 @@ msgstr "Medidas amosadas na gráfica de centrado"

msgctxt "NetworkAnalysis|"
msgid "yellow"
msgstr "amarelo"
msgstr "Amarelo"

msgctxt "NetworkAnalysis|"
msgid "Parametric"
Expand Down Expand Up @@ -406,7 +406,7 @@ msgstr "Opcións de Bootstrap"

msgctxt "NetworkAnalysis|"
msgid "Settings"
msgstr "Configuracións"
msgstr "Configuración"

msgctxt "NetworkAnalysis|"
msgid "In plot number: "
Expand Down Expand Up @@ -514,7 +514,7 @@ msgstr "Valores Ausentes"

msgctxt "NetworkAnalysis|"
msgid "Sample Size"
msgstr "Tamaño da Mostra"
msgstr "Tamaño da mostra"

msgctxt "NetworkAnalysis|"
msgid "Maximum"
Expand Down Expand Up @@ -718,27 +718,27 @@ msgstr "Cor do grupo"

msgctxt "BayesianNetworkAnalysis|"
msgid "red"
msgstr "vermello"
msgstr "Vermello"

msgctxt "BayesianNetworkAnalysis|"
msgid "blue"
msgstr "azul"
msgstr "Azul"

msgctxt "BayesianNetworkAnalysis|"
msgid "yellow"
msgstr "amarelo"
msgstr "Amarelo"

msgctxt "BayesianNetworkAnalysis|"
msgid "green"
msgstr "verde"
msgstr "Verde"

msgctxt "BayesianNetworkAnalysis|"
msgid "purple"
msgstr "morado"
msgstr "Morado"

msgctxt "BayesianNetworkAnalysis|"
msgid "orange"
msgstr "laranxa"
msgstr "Laranxa"

msgctxt "BayesianNetworkAnalysis|"
msgid "Variables in network"
Expand Down
Loading

0 comments on commit 9a8e0e8

Please sign in to comment.