split_clusters-methods: Cut an object into a list of spatial or spatiotemporal...

split_clustersR Documentation

Cut an object into a list of spatial or spatiotemporal clusters

Description

This function cuts an object into a list of sub-objects based on a vector of cluster indices. The resulting list contains each of the clusters as separate objects.

These methods split a NeuroVec object into multiple ROIVec objects based on cluster assignments.

Usage

split_clusters(x, clusters, ...)

## S4 method for signature 'NeuroVec,ClusteredNeuroVol'
split_clusters(x, clusters, ...)

## S4 method for signature 'NeuroVec,integer'
split_clusters(x, clusters, ...)

## S4 method for signature 'NeuroVol,ClusteredNeuroVol'
split_clusters(x, clusters)

## S4 method for signature 'NeuroVol,integer'
split_clusters(x, clusters)

## S4 method for signature 'NeuroVol,numeric'
split_clusters(x, clusters)

## S4 method for signature 'ClusteredNeuroVol,missing'
split_clusters(x, clusters)

## S4 method for signature 'NeuroVec,integer'
split_clusters(x, clusters, ...)

## S4 method for signature 'NeuroVec,numeric'
split_clusters(x, clusters, ...)

## S4 method for signature 'NeuroVec,ClusteredNeuroVol'
split_clusters(x, clusters, ...)

Arguments

x

A NeuroVec object to be split.

clusters

Either a ClusteredNeuroVol object or an integer vector of cluster assignments.

...

Additional arguments to be passed to methods.

Details

There are two methods for splitting clusters:

  • Using a ClusteredNeuroVol object: This method uses the pre-defined clusters in the ClusteredNeuroVol object.

  • Using an integer vector: This method allows for custom cluster assignments.

Both methods return a deflist, which is a lazy-loading list of ROIVec objects.

Value

A deflist object containing ROIVec instances for each cluster.

See Also

NeuroVec-class, ClusteredNeuroVol-class, ROIVec-class

Examples

## Not run: 
# Using ClusteredNeuroVol
neuro_vec <- # ... create a NeuroVec object
clustered_vol <- # ... create a ClusteredNeuroVol object
split_result <- split_clusters(neuro_vec, clustered_vol)

# Using integer vector
cluster_assignments <- # ... create an integer vector of cluster assignments
split_result <- split_clusters(neuro_vec, cluster_assignments)

## End(Not run)


## split 'NeuroVol' with a 'ClusteredNeuroVol'
vol <- NeuroVol(array(runif(10*10*10),c(10,10,10)), NeuroSpace(c(10,10,10)))
mask <- as.logical(vol > .5)
mask.idx <- which(mask != 0)
grid <- index_to_coord(mask, mask.idx)
vox <- index_to_grid(mask, mask.idx)

library(purrr)
## partition coordinates into 50 clusters using 'kmeans'
kres <- kmeans(grid, centers=50, iter.max=500)
kvol <- ClusteredNeuroVol(mask, kres$cluster)
klis <- split_clusters(mask, kvol)
ret1 <- vol %>% split_clusters(kvol) %>% purrr::map_dbl(~ mean(values(.)))

## split NeuroVol with 'integer' vector of clusters.
indices <- numeric(prod(dim(mask)[1:3]))

## locations with a cluster value of 0 are ignored
indices[mask.idx] <- kres$cluster

ret2 <- vol %>% split_clusters(as.integer(indices)) %>% 
purrr::map_dbl(~ mean(values(.)))
all(ret1 == ret1)

bbuchsbaum/neuroim2 documentation built on Nov. 3, 2024, 9:31 a.m.