Skip to content

Commit

Permalink
fixes for new data reading (#122)
Browse files Browse the repository at this point in the history
* fixes for new data reading

* cleanup Description.qml (spaces -> tabs)
  • Loading branch information
vandenman authored Oct 8, 2024
1 parent f79ec9c commit 4d4d8b9
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 29 deletions.
30 changes: 20 additions & 10 deletions R/networkanalysis.R
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,20 @@ NetworkAnalysis <- function(jaspResults, dataset, options) {

.networkAnalysisReadData <- function(dataset, options) {

if (!is.null(dataset))
return(dataset)

vars2read <- c("variables", "groupingVariable")
exclude <- c()
if (options[["missingValues"]] == "listwise")
exclude <- vars2read
layoutVariables <- c(options[["layoutX"]], options[["layoutY"]])
layoutVariables <- layoutVariables[layoutVariables != ""]
hasLayoutData <- length(layoutVariables) > 0L
if (hasLayoutData) {
layoutData <- dataset[layoutVariables]
layoutData <- jaspBase::excludeNaListwise(layoutData, layoutVariables)
# remove the two layout columns
dataset[layoutVariables] <- list(NULL)
}

dataset <- jaspBase::readDataSetByVariableTypes(options, vars2read, exclude.na.listwise = exclude)
if (options[["missingValues"]] == "listwise") {
exclude <- c(options[["variables"]], options[["groupingVariable"]])
dataset <- jaspBase::excludeNaListwise(dataset, exclude[exclude != ""])
}

if (options[["groupingVariable"]] == "") { # one network
dataset <- list(dataset) # for compatability with the split behaviour
Expand All @@ -68,6 +73,10 @@ NetworkAnalysis <- function(jaspResults, dataset, options) {
dataset <- split(dataset, groupingVariableData, drop = TRUE)
attr(dataset, "groupingVariableData") <- groupingVariableData
}

if (hasLayoutData)
attr(dataset, "layoutData") <- layoutData

return(dataset)

}
Expand Down Expand Up @@ -1289,8 +1298,9 @@ NetworkAnalysis <- function(jaspResults, dataset, options) {
# it turns out that we must save the layout in the A1 = ... style.
if (options[["layoutX"]] != "" && options[["layoutY"]] != "") {

layoutXData <- .readDataSetToEnd(columns = options[["layoutX"]], exclude.na.listwise = options[["layoutX"]])[[1L]]
layoutYData <- .readDataSetToEnd(columns = options[["layoutY"]], exclude.na.listwise = options[["layoutY"]])[[1L]]
layoutData <- attr(dataset, "layoutData")
layoutXData <- layoutData[[1L]]
layoutYData <- layoutData[[2L]]
variables <- unlist(options[["variables"]])
layoutInfo <- .networkAnalysisSanitizeLayoutData(variables, layoutXData, layoutYData, options[["layoutX"]], options[["layoutY"]])

Expand Down
34 changes: 17 additions & 17 deletions inst/Description.qml
Original file line number Diff line number Diff line change
Expand Up @@ -12,33 +12,33 @@ Description
maintainer: "JASP Team <[email protected]>"
website: "jasp-stats.org"
license: "GPL (>= 2)"
preloadData: true

GroupTitle
{
title: "Classical"
icon: "analysis-network.svg"
}

GroupTitle
{
title: "Classical"
icon: "analysis-network.svg"
}

Analysis
{
title: qsTr("Network Analysis")
qml: "NetworkAnalysis.qml"
func: "NetworkAnalysis"
qml: "NetworkAnalysis.qml"
func: "NetworkAnalysis"
}

Separator {}

GroupTitle
{
title: "Bayesian"
icon: "bayesian-analysis-network.svg"
}
{
title: "Bayesian"
icon: "bayesian-analysis-network.svg"
}

Analysis
{
title: qsTr("Bayesian Network Analysis")
qml: "BayesianNetworkAnalysis.qml"
func: "BayesianNetworkAnalysis"
qml: "BayesianNetworkAnalysis.qml"
func: "BayesianNetworkAnalysis"
}
}
4 changes: 2 additions & 2 deletions tests/testthat/test-networkanalysis.R
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,8 @@ n <- 50
p <- 3
dataset <- as.data.frame(matrix(rnorm(n * (p-1)), n, p-1))
dataset$V3 <- dataset$V1 + dataset$V2 + rnorm(n)
dataset$layoutX <- c("V1 = 1", "V2 = 0")
dataset$layoutY <- c("V1 = 1", "V2 = 0")
dataset$layoutX <- factor(c("V1 = 1", "V2 = 0"))
dataset$layoutY <- factor(c("V1 = 1", "V2 = 0"))
options <- jaspTools::analysisOptions("NetworkAnalysis")
options$estimator <- "ebicGlasso"
options$variables <- c("V1", "V2", "V3")
Expand Down

0 comments on commit 4d4d8b9

Please sign in to comment.