Last data update: 2014.03.03

R: Compute spatial groups
calcGroupsCoordsR Documentation

Compute spatial groups

Description

Compute the spatial groups using the coordinates of the observations.

Usage

calcGroupsCoords(coords, array = NULL, Neighborhood, max_groups = 10000, 
         verbose = optionsMRIaggr("verbose"))

Arguments

coords

the spatial coordinates of the observations. data.frame. REQUIRED.

array

alternative specification of the spatial coordinates using an array where the non-NA values indicates the points of interest. array or NULL leading to consider the coords argument.

Neighborhood

the type of neighbourhood. character.

max_groups

the maximum number of groups. postive integer.

verbose

should the execution of the function be traced ? logical.

Details

ARGUMENTS:
the Neighborhood argument can be a matrix or an array defining directly the neighbourhood to use (i.e the weight of each neighbor) or a name indicating which type of neighbourhood should be used (see the details section of initNeighborhood).

Value

An list containing :

  • [[ls.group]] : lists of the observations of each spatial group.

  • [[df.group]] : a data.frame indicating the position and the group of each observation.

  • [[group_size]] : the size of each spatial group. integer vector.

See Also

initFilter for various pre-stored filters.

Examples

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

optionsMRIaggr(outline.index = TRUE, num.main = FALSE)

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

#### 1- compute spatial groups using coordinates ####
res3DN18 <- calcGroupsCoords(coords = coords[MASK_DWI_t0 == 1,], Neighborhood = "3D_N18")
res3DN18$group_size

## display the lesion spatial groups
multiplot(coords, contrast=MASK_DWI_t0, legend = FALSE, num=2,
          index1=coords[MASK_DWI_t0 == 1,][res3DN18$ls.group[[1]],])

#### 2-compute spatial groups using an array ####
A.MASK_DWI_t0 <- df2array(MASK_DWI_t0,coords = coords)$contrast[[1]]
A.MASK_DWI_t0[A.MASK_DWI_t0 == FALSE] <- NA

## display
graphics::image(A.MASK_DWI_t0[,,3])

## computation of the spatial groups
res3DN18.bis <- calcGroupsCoords(array = A.MASK_DWI_t0, Neighborhood = "3D_N18")

res3DN18$group_size - res3DN18.bis$group_size # same result

Results


R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> library(MRIaggr)
Loading required package: Rcpp
> png(filename="/home/ddbj/snapshot/RGM3/R_CC/result/MRIaggr/MRIaggr-calcGroupsCoords.Rd_%03d_medium.png", width=480, height=480)
> ### Name: calcGroupsCoords
> ### Title: Compute spatial groups
> ### Aliases: calcGroupsCoords
> ### Keywords: functions
> 
> ### ** Examples
> 
> ## load a MRIaggr object
> data("MRIaggr.Pat1_red", package = "MRIaggr")
> 
> optionsMRIaggr(outline.index = TRUE, num.main = FALSE)
> 
> ## select data
> MASK_DWI_t0 <- selectContrast(MRIaggr.Pat1_red, param = "MASK_DWI_t0")
> coords <- selectCoords(MRIaggr.Pat1_red)
> 
> #### 1- compute spatial groups using coordinates ####
> res3DN18 <- calcGroupsCoords(coords = coords[MASK_DWI_t0 == 1,], Neighborhood = "3D_N18")
0% 10   20   30   40   50   60   70   80   90   100%
|----|----|----|----|----|----|----|----|----|----|
**************************************************|
> res3DN18$group_size
[1] 479   2
> 
> ## display the lesion spatial groups
> multiplot(coords, contrast=MASK_DWI_t0, legend = FALSE, num=2,
+           index1=coords[MASK_DWI_t0 == 1,][res3DN18$ls.group[[1]],])
> 
> #### 2-compute spatial groups using an array ####
> A.MASK_DWI_t0 <- df2array(MASK_DWI_t0,coords = coords)$contrast[[1]]
> A.MASK_DWI_t0[A.MASK_DWI_t0 == FALSE] <- NA
> 
> ## display
> graphics::image(A.MASK_DWI_t0[,,3])
> 
> ## computation of the spatial groups
> res3DN18.bis <- calcGroupsCoords(array = A.MASK_DWI_t0, Neighborhood = "3D_N18")
0% 10   20   30   40   50   60   70   80   90   100%
|----|----|----|----|----|----|----|----|----|----|
**************************************************|
> 
> res3DN18$group_size - res3DN18.bis$group_size # same result
[1] 0 0
> 
> 
> 
> 
> 
> dev.off()
null device 
          1 
>