Skip to content

Commit

Permalink
Adressing review comments round 2: implemented camelCase consistently…
Browse files Browse the repository at this point in the history
…, adjusted the arguments in functions, and some other small fixes.
  • Loading branch information
sekulovskin committed Nov 18, 2024
1 parent 6825ea3 commit 452e3ca
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 66 deletions.
61 changes: 30 additions & 31 deletions R/bayesiannetworkanalysis.R
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ BayesianNetworkAnalysis <- function(jaspResults, dataset, options) {
mainContainer <- jaspResults[["mainContainer"]]
if (is.null(mainContainer)) {
mainContainer <- createJaspContainer(dependencies = c("variables", "groupingVariable", "model",
"burnin", "iter", "gprior", "dfprior", "initialConfiguration",
"edgePrior", "interactionScale", "beta_alpha", "beta_beta",
"dirichlet_alpha", "threshold_alpha", "threshold_beta"))
"burnin", "iter", "gPrior", "dfPrior", "initialConfiguration",
"edgePrior", "interactionScale", "betaAlpha", "betaBeta",
"dirichletAlpha", "thresholdAlpha", "thresholdBeta"))
jaspResults[["mainContainer"]] <- mainContainer
}
.bayesianNetworkAnalysisMainTableMeta(mainContainer, dataset, options)
Expand Down Expand Up @@ -205,19 +205,18 @@ BayesianNetworkAnalysis <- function(jaspResults, dataset, options) {
for (nw in seq_along(dataset)) {
# When method = "gcgm" a vector with binary values is needed:
if (options[["model"]] == "ggm") {

# Estimate mixed network
# Estimate network
jaspBase::.setSeedJASP(options)
easybgmFit <- try(easybgm::easybgm(data = as.data.frame(apply(dataset[[nw]], 2, as.numeric)),
easybgmFit <- try(easybgm::easybgm(data = apply(dataset[[nw]], 2, as.numeric),
type = "continuous",
package = "BDgraph" ,
iter = as.numeric(options[["iter"]]),
iter = options[["iter"]],
save = TRUE,
centrality = FALSE,
burnin = as.numeric(options[["burnin"]]),
burnin = options[["burnin"]],
g.start = options[["initialConfiguration"]],
df.prior = as.numeric(options[["dfprior"]]),
g.prior = as.numeric(options[["gprior"]])))
df.prior = options[["dfPrior"]],
g.prior = options[["gPrior"]]))

if (isTryError(easybgmFit)) {
message <- .extractErrorMessage(easybgmFit)
Expand Down Expand Up @@ -248,25 +247,25 @@ BayesianNetworkAnalysis <- function(jaspResults, dataset, options) {
for (var in options[["variables"]]) {

# A 1 indicates noncontinuous variables:
if (is.factor(dataset[[nw]][[var]])) {
if (is.factor(dataset[[nw]][[var]])) {
nonContVariables <- c(nonContVariables, 1)
} else {
nonContVariables <- c(nonContVariables, 0)
}
}
# Estimate mixed network
# Estimate network
jaspBase::.setSeedJASP(options)
easybgmFit <- try(easybgm::easybgm(data = as.data.frame(apply(dataset[[nw]], 2, as.numeric)),
easybgmFit <- try(easybgm::easybgm(data = apply(dataset[[nw]], 2, as.numeric),
type = "mixed",
package = "BDgraph",
not_cont = nonContVariables,
iter = as.numeric(options[["iter"]]),
iter = options[["iter"]],
save = TRUE,
centrality = FALSE,
burnin = as.numeric(options[["burnin"]]),
burnin = options[["burnin"]],
g.start = options[["initialConfiguration"]],
df.prior = as.numeric(options[["dfprior"]]),
g.prior = as.numeric(options[["gprior"]])))
df.prior = options[["dfPrior"]],
g.prior = options[["gPrior"]]))


if (isTryError(easybgmFit)) {
Expand Down Expand Up @@ -295,27 +294,27 @@ BayesianNetworkAnalysis <- function(jaspResults, dataset, options) {
if (options[["model"]] == "omrf") {
for (var in options[["variables"]]) {
# Check if variables are binary or ordinal:
if (!is.factor(dataset[[nw]][[var]])) {
if (!is.factor(dataset[[nw]][[var]])) {
.quitAnalysis(gettext("Some of the variables you have entered for analysis are not binary or ordinal. Please make sure that all variables are binary or ordinal or change the model to gcgm."))
}
}
# Estimate mixed network
# Estimate network
jaspBase::.setSeedJASP(options)
easybgmFit <- try(easybgm::easybgm(data = as.data.frame(dataset[[nw]]),
easybgmFit <- try(easybgm::easybgm(data = dataset[[nw]],
type = "ordinal",
package = "bgms",
iter = as.numeric(options[["iter"]]),
iter = options[["iter"]],
save = TRUE,
centrality = FALSE,
burnin = as.numeric(options[["burnin"]]),
inclusion_probability = as.numeric(options[["gprior"]]),
interaction_scale = as.numeric(options[["interactionScale"]]),
edge_prior = as.character(options[["edgePrior"]]),
threshold_alpha = as.numeric(options[["threshold_alpha"]]),
threshold_beta = as.numeric(options[["threshold_beta"]]),
beta_bernoulli_alpha = as.numeric(options[["beta_alpha"]]),
beta_bernoulli_beta = as.numeric(options[["beta_beta"]]),
dirichlet_alpha = as.numeric(options[["dirichlet_alpha"]])))
burnin = options[["burnin"]],
inclusion_probability = options[["gPrior"]],
interaction_scale = options[["interactionScale"]],
edge_prior = options[["edgePrior"]],
threshold_alpha = options[["thresholdAlpha"]],
threshold_beta = options[["thresholdBeta"]],
beta_bernoulli_alpha = options[["betaAlpha"]],
beta_bernoulli_beta = options[["betaBeta"]],
dirichlet_alpha = options[["dirichletAlpha"]]))



Expand Down Expand Up @@ -1096,7 +1095,7 @@ BayesianNetworkAnalysis <- function(jaspResults, dataset, options) {
# add footnote on the infinities only show this message of the evidence type is BF10 or BF01

if (options$evidenceType %in% c("BF10", "BF01")){
table$addFootnote("Bayes factors with values of infinity indicate that the posterior inclusion probability is either 1 or 0, meaning there is overwhelming evidence for edge inclusion or exclusion, respectively.")
table$addFootnote("Bayes factors with values of infinity indicate that the estimated posterior inclusion probability is either 1 or 0. Please see the help file for more information.")
}
mainContainer[["edgeEvidenceTable"]] <- table
}
Expand Down
69 changes: 34 additions & 35 deletions inst/qml/BayesianNetworkAnalysis.qml
Original file line number Diff line number Diff line change
Expand Up @@ -95,16 +95,15 @@ Form
{
title: qsTr("Sampling Options")
Layout.columnSpan: 2
IntegerField { name: "burnin"; label: qsTr("Burn in: "); value: "5000" ; min: 0; max: iter.value / 2; fieldWidth: 100; id: burnin }
IntegerField { name: "iter"; label: qsTr("Iterations: "); value: "10000" ; min: burnin.value * 2; fieldWidth: 100; id: iter }
IntegerField { name: "burnin"; label: qsTr("Burn in: "); value: 1000 ; min: 0; max: iter.value / 2; fieldWidth: 100; id: burnin }
IntegerField { name: "iter"; label: qsTr("Iterations: "); value: 10000 ; min: burnin.value * 2; fieldWidth: 100; id: iter }

SetSeed{}
}

Section {
Section {
title: qsTr("Prior Specification")
Layout.fillWidth: true

Column {
spacing: 15
anchors.fill: parent
Expand All @@ -126,46 +125,46 @@ Section {
values: [
{ value: "Bernoulli", label: "Bernoulli" },
{ value: "Beta-Bernoulli", label: "Beta-Bernoulli" },
{ value: "Stochastic-Block", label: "Stochastic-Block" }
{ value: "Stochastic-Block", label: "Stochastic Block" }
]
visible: model.currentValue === "omrf"
}

FormulaField {
name: "gprior"
label: qsTr("Prior edge inclusion probability:")
value: "0.5"
min: 0.001
max: 1
Layout.fillWidth: true
preferredWidth: 300
visible: (model.currentValue === "ggm" || model.currentValue === "gcgm") || (model.currentValue === "omrf" && edgePrior.currentValue === "Bernoulli")
}

FormulaField {
name: "beta_alpha"
DoubleField {
name: "gPrior"
label: qsTr("Prior edge inclusion probability:")
value: 0.5
min: 0.001
max: 1
Layout.fillWidth: true
preferredWidth: 300
visible: (model.currentValue === "ggm" || model.currentValue === "gcgm") || (model.currentValue === "omrf" && edgePrior.currentValue === "Bernoulli")
}

DoubleField {
name: "betaAlpha"
label: qsTr("Shape parameter 1:")
value: "1"
value: 1
min: 0.001
Layout.fillWidth: true
preferredWidth: 300
visible: (model.currentValue === "omrf") && (edgePrior.currentValue === "Beta-Bernoulli" || edgePrior.currentValue === "Stochastic-Block")
}

FormulaField {
name: "beta_beta"
DoubleField {
name: "betaBeta"
label: qsTr("Shape parameter 2:")
value: "1"
value: 1
min: 0.001
Layout.fillWidth: true
preferredWidth: 300
visible: (model.currentValue === "omrf") && (edgePrior.currentValue === "Beta-Bernoulli" || edgePrior.currentValue === "Stochastic-Block")
}

FormulaField {
name: "dirichlet_alpha"
DoubleField {
name: "dirichletAlpha"
label: qsTr("Concentration parameter:")
value: "1"
value: 1
min: 0.001
Layout.fillWidth: true
preferredWidth: 300
Expand Down Expand Up @@ -196,7 +195,7 @@ Section {
Layout.fillWidth: true

IntegerField {
name: "dfprior"
name: "dfPrior"
label: qsTr("Degrees of freedom of G-Wishart prior:")
value: 3
min: 3
Expand All @@ -205,31 +204,31 @@ Section {
visible: model.currentValue === "ggm" || model.currentValue === "gcgm"
}

FormulaField {
DoubleField {
name: "interactionScale"
label: qsTr("Scale of the Cauchy distribution for the edge weights:")
value: "2.5"
value: 2.5
min: 0.1
Layout.fillWidth: true
preferredWidth: 300
visible: model.currentValue === "omrf"
}


FormulaField {
name: "threshold_alpha"
label: qsTr("Threshold Shape parameter 1:")
value: "1"
DoubleField {
name: "thresholdAlpha"
label: qsTr("Threshold shape parameter 1:")
value: 1
min: 0.001
Layout.fillWidth: true
preferredWidth: 300
visible: model.currentValue === "omrf"
}

FormulaField {
name: "threshold_beta"
DoubleField {
name: "thresholdBeta"
label: qsTr("Threshold shape parameter 2:")
value: "1"
value: 1
min: 0.001
Layout.fillWidth: true
preferredWidth: 300
Expand Down

0 comments on commit 452e3ca

Please sign in to comment.