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:
Or install the development version from GitHub:
The package provides several pre-configured metrics:
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
Metric objects (class rmetric
) contain four essential
functions: - log
: Computes Riemannian logarithm -
exp
: Computes Riemannian exponential - vec
:
Performs vectorization - unvec
: Performs inverse
vectorization
plan(multisession)
)For more details about the mathematical foundations and methodology, refer to: