estimate_networks_by_group: Estimate Networks by Group

View source: R/estimate_networks_by_group.R

estimate_networks_by_groupR Documentation

Estimate Networks by Group

Description

Estimates network models separately for each group in the data.

Usage

estimate_networks_by_group(
  data,
  group_var,
  columns,
  default = "ggmModSelect",
  stepwise = TRUE,
  corMethod = "spearman",
  abbreviate_vars = FALSE,
  abbr_minlength = 3,
  labels = NULL,
  set_labels_on_graph = TRUE
)

Arguments

data

Data frame containing the data.

group_var

Name of the grouping variable column.

columns

Character vector of variable names to include.

default

Network estimation method (default: "ggmModSelect").

stepwise

Logical; use stepwise model selection.

corMethod

Correlation method (default: "spearman").

abbreviate_vars

Logical; abbreviate variable names.

abbr_minlength

Minimum length for abbreviated names.

labels

Optional custom labels for nodes.

set_labels_on_graph

Logical; apply labels to graph object.

Value

A named list with one estimated network (a bootnetResult object) per group. Each network carries the attribute var_mapping, a tibble that maps the original variable names to the labels used.

Examples

set.seed(123)
n <- 300
f1 <- rnorm(n)
f2 <- 0.3 * f1 + rnorm(n)
items <- data.frame(
  sapply(1:4, function(i) 0.7 * f1 + rnorm(n, 0, 0.7)),
  sapply(1:4, function(i) 0.7 * f2 + rnorm(n, 0, 0.7))
)
names(items) <- c(paste0("A", 1:4), paste0("B", 1:4))
items$sex <- rep(c("Female", "Male"), each = n / 2)

nets <- estimate_networks_by_group(items, group_var = "sex",
                                   columns = names(items)[1:8],
                                   default = "EBICglasso")
names(nets)

InterconectaR documentation built on Oct. 16, 2026, 1:06 a.m.