vignettes/riemtan.Rmd
riemtan.Rmd
The riemtan
package provides tools for statistical
analysis of connectomes using Riemannian geometry. This package is
particularly useful for researchers working with fMRI data and other
applications where symmetric positive definite (SPD) matrices play a
crucial role.
You can install riemtan
from CRAN:
install.packages("riemtan")
Or install the development version from GitHub:
devtools::install_github("nicoesve/riemtan")
# Compute tangent space representations
sample1$compute_unvecs()
sample1$compute_tangents()
# Compute manifold representations
sample1$compute_conns()
# Check if computations were successful
!is.null(sample1$connectomes) # Should be TRUE
# Create a sample from your connectome data
conn_sample <- CSample$new(conns = your_connectomes, metric_obj = airm)
# Compute the Fréchet mean
conn_sample$compute_fmean()
# Center the sample at the Fréchet mean
conn_sample$center()
This example shows how to prepare data for clustering analysis:
# Combine two samples
joint_conns <- c(sample1$connectomes, sample2$connectomes)
combined_sample <- CSample$new(conns = joint_conns, metric_obj = airm)
# Prepare for clustering
combined_sample$compute_tangents()
combined_sample$center() # Center at Fréchet mean
combined_sample$compute_vecs() # Get vectorized representation
# The vectorized representations can now be used with standard clustering algorithms
When working with real connectome data, you’ll typically need to pre-process your matrices:
# Convert your matrices to the correct format
parsed_conns <- your_raw_conns |>
purrr::map(\(x) as(x, "dpoMatrix")) |>
purrr::map(Matrix::pack)
# Create a CSample object
conn_sample <- CSample$new(parsed_conns, airm)
# Compute geometric statistics
conn_sample$compute_fmean()
conn_sample$compute_tangents()
conn_sample$center()
conn_sample$compute_vecs()
The CSample
class is the main workhorse of the package.
It manages:
Key methods include: - compute_tangents()
: Computes
tangent space representations - compute_conns()
: Computes
manifold representations - compute_vecs()
: Computes
vectorized representations - compute_fmean()
: Computes
Fréchet mean - center()
: Centers the sample at its Fréchet
mean - compute_variation()
: Computes sample variation -
compute_sample_cov()
: Computes sample covariance
plan(multisession)
)