Learn R Programming

MRIaggr (version 1.1.3)

calcGroupsW: Compute spatial groups

Description

Compute the spatial groups using a neighbourhood matrix.

Usage

calcGroupsW(W, subset = NULL, max_groups = 10000)

Arguments

W
the neighbourhood matrix. dgCMatrix. REQUIRED.
subset
the subset of observations to use. positive integer vector or NULL leading to use all observations.
max_groups
the maximum number of groups. postive integer.

Value

  • An list containing :
    • [[group]]: avectorcontaining the group index for each observation. Observations out of the subset are set toNA.
    • [[subset]]: avectorcontaining the group index for each observation in subset.
    • [[group_size]]: avectorwith the size of each spatial group.
    • [[group_number]]: the number of spatial groups.integer vector.
    • [[group_max]]: the number of the largest group.integer vector.

concept

calc.

Details

This function requires to have installed the Matrix and the spam package to work.

Examples

Run this code
## load a MRIaggr object
data("MRIaggr.Pat1_red", package = "MRIaggr")

## select data
MASK_DWI_t0 <- selectContrast(MRIaggr.Pat1_red, param = "MASK_DWI_t0")
coords <- selectCoords(MRIaggr.Pat1_red)

## select compute W
W <- calcW(object = as.data.frame(coords[MASK_DWI_t0 == 1,]), 
           range = sqrt(2), row.norm = TRUE)$W
 
## find spatial groups
res.Groups <- calcGroupsW(W)
res.Groups$group_size

## display
multiplot(coords[MASK_DWI_t0 == 1,], contrast = res.Groups$group,
          legend = FALSE, cex=0.5,
          palette=rainbow(10)[-1])

Run the code above in your browser using DataLab