## ----include = FALSE----------------------------------------------------------
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)

## ----setup--------------------------------------------------------------------
library(circularNet)

## -----------------------------------------------------------------------------
# Simulated example data
set.seed(1)
data <- matrix(runif(200, -pi, pi), ncol = 5)

# Fit the model
fit <- fit_circular_model(data)

# Build adjacency matrix
network <- build_network(fit)

# Display network structure
network


## -----------------------------------------------------------------------------

# Plot the network
plot_network(network)


## -----------------------------------------------------------------------------
true_network <- matrix(
  sample(0:1, 25, replace = TRUE),
  ncol = 5
)

results <- evaluate_network(
  network,
  true_network
)

results


## -----------------------------------------------------------------------------
gene_file <- system.file(
  "extdata",
  "gene_expression_subset.csv",
  package = "circularNet"
)

gene_data <- read.csv(
  gene_file,
  check.names = FALSE
)

# Remove gene identifier column if present
if (!is.numeric(gene_data[[1]])) {
  gene_data <- gene_data[, -1]
}

gene_data <- as.matrix(gene_data)

# Convert from genes × samples to observations × variables
gene_data <- t(gene_data)

# Use a small subset of genes for faster vignette execution
gene_data_small <- gene_data[, 1:min(5, ncol(gene_data))]

# Fit circular graphical model
fit_gene <- fit_circular_model(gene_data_small)

# Display estimated coefficient matrix
round(fit_gene, 3)

# Build adjacency matrix
network_gene <- build_network(
  fit_gene,
  threshold = 0.2
)

# Display estimated network
network_gene

# Visualize estimated network
plot_network(network_gene)


