group_obs {GpGp} | R Documentation |
Automatic grouping (partitioning) of locations
Description
Take in an array of nearest neighbors, and automatically partition the array into groups that share neighbors. This is helpful to speed the computations and improve their accuracy. The function returns a list, with each list element containing one or several rows of NNarray. The algorithm attempts to find groupings such that observations within a group share many common neighbors.
Usage
group_obs(NNarray, exponent = 2)
Arguments
NNarray |
Matrix of nearest neighbor indices, usually the result of |
exponent |
Within the algorithm, two groups are merged if the number of unique
neighbors raised to the |
Value
A list with elements defining the grouping. The list entries are:
-
all_inds
: vector of all indices of all blocks. -
last_ind_of_block
: Thei
th entry tells us the location inall_inds
of the last index of thei
th block. Thus the length oflast_ind_of_block
is the number of blocks, andlast_ind_of_block
can be used to chopall_inds
up into blocks. -
global_resp_inds
: Thei
th entry tells us the index of thei
th response, as ordered inall_inds
. -
local_resp_inds
: Thei
th entry tells us the location within the block of the response index. -
last_resp_of_block
: Thei
th entry tells us the location withinlocal_resp_inds
andglobal_resp_inds
of the last index of thei
th block.last_resp_of_block
is toglobal_resp_inds
andlocal_resp_inds
aslast_ind_of_block
is toall_inds
.
Examples
locs <- matrix( runif(200), 100, 2 ) # generate random locations
ord <- order_maxmin(locs) # calculate an ordering
locsord <- locs[ord,] # reorder locations
m <- 10
NNarray <- find_ordered_nn(locsord,m) # m nearest neighbor indices
NNlist2 <- group_obs(NNarray) # join blocks if joining reduces squares
NNlist3 <- group_obs(NNarray,3) # join blocks if joining reduces cubes
object.size(NNarray)
object.size(NNlist2)
object.size(NNlist3)
mean( NNlist2[["local_resp_inds"]] - 1 ) # average number of neighbors (exponent 2)
mean( NNlist3[["local_resp_inds"]] - 1 ) # average number of neighbors (exponent 3)
all_inds <- NNlist2$all_inds
last_ind_of_block <- NNlist2$last_ind_of_block
inds_of_block_2 <- all_inds[ (last_ind_of_block[1] + 1):last_ind_of_block[2] ]
local_resp_inds <- NNlist2$local_resp_inds
global_resp_inds <- NNlist2$global_resp_inds
last_resp_of_block <- NNlist2$last_resp_of_block
local_resp_of_block_2 <-
local_resp_inds[(last_resp_of_block[1]+1):last_resp_of_block[2]]
global_resp_of_block_2 <-
global_resp_inds[(last_resp_of_block[1]+1):last_resp_of_block[2]]
inds_of_block_2[local_resp_of_block_2]
# these last two should be the same