Gij.flow {spnaf}R Documentation

Calculate spatial autocorrelation with OD data and corresponding flows.

Description

Calculate spatial autocorrelation with OD data and corresponding flows.

Usage

Gij.flow(
  df,
  shape,
  method = "queen",
  k = NULL,
  d = NULL,
  idw = FALSE,
  row_standardized = FALSE,
  snap = 1,
  OD = "t",
  R = 1000
)

Arguments

df

A data.frame that contains your Origin-Destination data. The df must consist of "oid" (origin id), "did" (destination id), and "n" (flow weight).

shape

A shapefile (in a polygon type) that matches your OD dataframe. The shape must have an "id" column to match your ids in df.

method

A string value among "queen" (spatial contiguity), "KNN" (k-nearest neighbors), and "fixed_distance" (fixed distance).

k

An integer value to define the number of nearest neighbors for the K-nearest neighbors method.

d

An integer value to define the distance for the fixed distance spatial weight matrix.

idw

A logical value indicating whether to use inverse distance weighting.

row_standardized

A logical value indicating whether to row-standardize the spatial weights.

snap

A parameter used to calculate spdep's spatial contiguity (please refer to the poly2nb documentation for more information).

OD

A string value among "o" (origin-based), "d" (destination-based), and "t" (both ways), which determines how to generate spatial weights. The default value is "t".

R

An integer value to define how many times you want to execute bootstrapping.

Value

The result is a list containing a dataframe and an sf object. Both contain Gij statistics and p-value columns merged with your input df. The geometry type of the latter is linestring.

References

Berglund, S., & Karlström, A. (1999). Identifying local spatial association in flow data. Journal of Geographical Systems, 1(3), 219-236. https://doi.org/10.1007/s101090050013

Examples

# Data manipulation
CA <- spnaf::CA
OD <- cbind(CA$FIPS.County.Code.of.Geography.B, CA$FIPS.County.Code.of.Geography.A)
OD <- cbind(OD, CA$Flow.from.Geography.B.to.Geography.A)
OD <- data.frame(OD)
names(OD) <- c("oid", "did", "n")
OD$n <- as.numeric(OD$n)
OD <- OD[order(OD[,1], OD[,2]),]
head(OD) # check the input df's format

# Load sf polygon
CA_polygon <- spnaf::CA_polygon
head(CA_polygon) # it has a geometry column

# Execution of Gij.flow with data above and given parameters
## Not run: 
result <- Gij.flow(df = OD, shape = CA_polygon, method = 'queen', snap = 1, OD = 't', R = 1000)

## End(Not run)

# check the results
## Not run: 
head(result[[1]])
head(result[[2]])

## End(Not run)

[Package spnaf version 1.1.0 Index]