Last data update: 2014.03.03
R: Computation of the spatial potential
calcMultiPotential R Documentation
Computation of the spatial potential
Description
Compute the regional potential of a spatial field. Call the calcMultiPotential_cpp
C++ function.
Usage
calcMultiPotential(W_SR, W_LR, distance.ref, sample, coords,
threshold = 0.01, nbGroup_min = 100, check.args = TRUE, verbose = TRUE)
Arguments
W_SR
The local neighborhood matrix. dgCMatrix . Should be normalized by row (i.e. rowSums(Wweight_SR)=1
). REQUIRED.
W_LR
The regional neighborhood matrix. dgCMatrix . Should contain the distances between the observations (0
indicating infinite distance). REQUIRED.
distance.ref
The intervals of distance defining the several neighborhood orders in W_LR
. numeric vector . REQUIRED.
sample
The probability membership to the group. numeric vector or character vector . REQUIRED.
coords
The voxel coordinates. matrix . REQUIRED.
threshold
The minimum value to consider non-negligible group membership. numeric . Default is 0.01
.
nbGroup_min
The minimum group size of the spatial groups required for computing the potential. integer . Default is 100
.
check.args
Should the validity of the arguments be checked ? logical .
verbose
Should the radius of the spatial groups be displayed ? logical .
Details
If check.args
is set to TRUE
, argument ccords
must be a matrix (and not a data.frame ) and the x slot of argument W_LR
must contain categories of distances instead of distances.
Distance categories must begin at 0
and end at length(distance.ref)-1
.
Value
A numeric vector containing the regional potential.
Examples
# spatial field
## Not run:
n <- 30
## End(Not run)
G <- 3
coords <- data.frame(which(matrix(0, nrow = n * G, ncol = n * G) == 0, arr.ind = TRUE), 1)
optionsMRIaggr(quantiles.legend = FALSE, axes = FALSE, num.main = FALSE)
# neighborhood matrix
W_SR <- calcW(coords, range = sqrt(2), row.norm = TRUE)$W
W_LR <- calcW(coords, range = 10, row.norm = FALSE)$W
distance.ref <- seq(1, 10, 1)
# data
set.seed(10)
sample <- simulPotts(W = W_SR, G = G, rho = 3.5, iter_max = 500)
#
multiplot(coords,sample$simulation[,2])
V1 <- calcMultiPotential(W_SR = W_SR, W_LR = W_LR, distance.ref = seq(1, 10, 1),
sample = sample$simulation[,2], coords = coords, verbose = TRUE)
multiplot(coords, V1)
#
sampleV <- (apply(sample$simulation, 1, which.max) - 1) / 2
multiplot(coords, sampleV)
system.time(
V2 <- calcMultiPotential(W_SR = W_SR, W_LR = W_LR, distance.ref = seq(1, 10, 1),
sample = sampleV, coords = coords, verbose = TRUE)
)
Wcat_LR <- W_LR
Wcat_LR@x <- findInterval(x = Wcat_LR@x, vec = distance.ref) - 1
system.time(
V2 <- calcMultiPotential(W_SR = W_SR, W_LR = Wcat_LR, distance.ref = seq(1, 10, 1),
sample = sampleV, coords = as.matrix(coords), verbose = TRUE, check.args = FALSE)
)
# quicker but arguments have to be correctly specified
multiplot(coords, V2)
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/sfMM-calcMultiPotential.Rd_%03d_medium.png", width=480, height=480)
> ### Name: calcMultiPotential
> ### Title: Computation of the spatial potential
> ### Aliases: calcMultiPotential
> ### Keywords: functions
>
> ### ** Examples
>
> # spatial field
> ## Not run:
> ##D n <- 30
> ## End(Not run)
> ## Don't show:
> n <- 10
> ## End(Don't show)
> G <- 3
> coords <- data.frame(which(matrix(0, nrow = n * G, ncol = n * G) == 0, arr.ind = TRUE), 1)
> optionsMRIaggr(quantiles.legend = FALSE, axes = FALSE, num.main = FALSE)
>
> # neighborhood matrix
> W_SR <- calcW(coords, range = sqrt(2), row.norm = TRUE)$W
> W_LR <- calcW(coords, range = 10, row.norm = FALSE)$W
> distance.ref <- seq(1, 10, 1)
>
> # data
> set.seed(10)
> sample <- simulPotts(W = W_SR, G = G, rho = 3.5, iter_max = 500)
NOTE : specifying argument 'site_order' would speed up the execution of the function
0% 10 20 30 40 50 60 70 80 90 100%
|----|----|----|----|----|----|----|----|----|----|
**************************************************|
|
>
> #
> multiplot(coords,sample$simulation[,2])
>
> V1 <- calcMultiPotential(W_SR = W_SR, W_LR = W_LR, distance.ref = seq(1, 10, 1),
+ sample = sample$simulation[,2], coords = coords, verbose = TRUE)
segment x slot of argument 'W_LR' according to argument 'distance.ref'
radius : 10.22
>
> multiplot(coords, V1)
>
>
> #
> sampleV <- (apply(sample$simulation, 1, which.max) - 1) / 2
> multiplot(coords, sampleV)
>
> system.time(
+ V2 <- calcMultiPotential(W_SR = W_SR, W_LR = W_LR, distance.ref = seq(1, 10, 1),
+ sample = sampleV, coords = coords, verbose = TRUE)
+ )
segment x slot of argument 'W_LR' according to argument 'distance.ref'
radius : 11.42
user system elapsed
0.008 0.000 0.007
>
> Wcat_LR <- W_LR
> Wcat_LR@x <- findInterval(x = Wcat_LR@x, vec = distance.ref) - 1
>
> system.time(
+ V2 <- calcMultiPotential(W_SR = W_SR, W_LR = Wcat_LR, distance.ref = seq(1, 10, 1),
+ sample = sampleV, coords = as.matrix(coords), verbose = TRUE, check.args = FALSE)
+ )
radius : 11.42
user system elapsed
0.000 0.000 0.002
> # quicker but arguments have to be correctly specified
>
> multiplot(coords, V2)
>
>
>
>
>
>
> dev.off()
null device
1
>