Learn R Programming

MRIaggr (version 1.1.5)

calcGroupsW: Compute spatial groups

Description

Compute the spatial groups using a neighbourhood matrix.

Usage

calcGroupsW(W, subset = NULL, max_groups = 10000, verbose = optionsMRIaggr("verbose"))

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.
verbose
should the execution of the function be traced ? logical.

Value

An list containing :
  • [[group]] : a vector containing the group index for each observation. Observations out of the subset are set to NA.
  • [[subset]] : a vector containing the group index for each observation in subset.
  • [[group_size]] : a vector with 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.

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