proximity_builder {sim2Dpredictr}R Documentation

Generate a Proximity Matrix

Description

Generates a proximity matrix where non-zero entries are the weights associated with neighbors, and zero entries are not neighbors.

Usage

proximity_builder(
  im.res,
  neighborhood = "ar1",
  type = c("sparse", "full"),
  weight = "binary",
  phi = 1,
  r = NULL,
  h = NULL,
  w = NULL,
  include.coords = FALSE,
  print.im = FALSE
)

Arguments

im.res

A vector defining the dimension of spatial data. The first entry is the number of rows and the second entry is the number of columns.

neighborhood

Determines how to assign neighbor status to locations; i.e. 1 for neighbors, 0 otherwise. type = "round" assigns neighbor status to locations within radius r. type = "ar1" assigns 1 to locations directly above or beside. type = "rectangle" assigns neighbor status to locations within w units to the left or right and h units up or down.

type

Specifies either sparse (type = "sparse") or full (type = "full") proximity matrix.

weight

Determines how weights are assigned. "distance" assigns weights as the inverse of Euclidean distance times a constant, phi. "binary" assigns weights to 1 for neighbors and 0 otherwise.

phi

When weight = "distance" a constant by which to multiply the inverse of Euclidean distance. Defaults to 1.

r, h, w

When neighborhood = "round", r specifies the radius within which other locations are neighbors. When neighborhood = "rectangle", w and h specify the number of units to the left/right and above/below the location are to be counted as neighbors.

include.coords

If type = "sparse" and include.coords = TRUE, then the coordinates of neighbors are returned along with their indices.

print.im

Allows user to print the 2D "image" matrix with index labels to visually verify that the proximity matrix is as expected.

Value

A (proximity) matrix.

Examples

## Not run: 
## adjacency matrix with sparse structure (i.e., 2 columns) 
## and ar1 neighborhood
sp.ar1 <- proximity_builder(im.res = c(3, 3),
                            weight = "binary",
                            neighborhood = "ar1",
                            type = "sparse")
## adjacency matrix with full structure 
## (i.e., prod(im.dim) rows & columns) and ar1 neighborhood
full.ar1 <- proximity_builder(im.res = c(3, 3),
                              weight = "binary",
                              neighborhood = "ar1",
                              type = "full")

## proximity matrix weighted by distance (sparse)
sp.rnd <- proximity_builder(im.res = c(3, 3),
                            weight = "distance",
                            neighborhood = "round", r = 2,
                            type = "sparse",
                            include.coords = TRUE)

## proximity matrix weighted by distance (full)
full.rnd <- proximity_builder(im.res = c(3, 3),
                              weight = "distance",
                              neighborhood = "round", r = 2,
                              type = "full")

## End(Not run)

[Package sim2Dpredictr version 0.1.1 Index]