Title: | Spatial Network Autocorrelation for Flow Data |
---|---|
Description: | Identify statistically significant flow clusters using the local spatial network autocorrelation statistic G_ij* proposed by 'Berglund' and 'Karlström' (1999) <doi:10.1007/s101090050013>. The metric, an extended statistic of 'Getis/Ord' G ('Getis' and 'Ord' 1992) <doi:10.1111/j.1538-4632.1992.tb00261.x>, detects a group of flows having similar traits in terms of directionality. You provide OD data and the associated polygon to get results with several parameters, some of which are defined by spdep package. |
Authors: | Youngbin Lee [aut, cre] , Hui Jeong Ha [aut] , Sohyun Park [aut] , Kyusik Kim [aut] , Jinhyung Lee [aut] |
Maintainer: | Youngbin Lee <[email protected]> |
License: | MIT + file LICENSE |
Version: | 1.1.0 |
Built: | 2024-11-26 06:45:02 UTC |
Source: | CRAN |
A dataframe containing migration of CA counties with origins and destinations from US Census
CA
CA
A data.frame
object with 2580 rows and 12 variables
Destinations' State code
Destinations' FIPS County code
Destinations' State U.S. Island Area Foreign Region Code
Origins' FIPS County code
Destinations' State name
Destinations' County name
Origins' State U.S. Island Area Foreign Region Code
Origins' County name
Flow count from the origin to the destination
Counterflow count from the destination to the origin
Net migration count from the origin to the destination
Gross migration count between counties
Census.gov > Population > Migration/Geographic Mobility > Guidance for Data Users > County-to-County Migration Flows https://www.census.gov/topics/population/migration/guidance/county-to-county-migration-flows.html
CA
CA
A sf(simple feature) containing geometric boundaries of CA counties with their codes.
CA_polygon
CA_polygon
A sf
object with 58 rows and 2 variables
FIPS County code of geography
the geometry column for counties(CRS: NAD83)
Calculate spatial autocorrelation with OD data and corresponding flows.
Gij.flow( df, shape, method = "queen", k = NULL, d = NULL, idw = FALSE, row_standardized = FALSE, snap = 1, OD = "t", R = 1000 )
Gij.flow( df, shape, method = "queen", k = NULL, d = NULL, idw = FALSE, row_standardized = FALSE, snap = 1, OD = "t", R = 1000 )
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 |
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. |
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.
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
# 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)
# 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)
Calculate spatial weights for networks based on input polygons.
Networknb(shape, snap = 1, queen = TRUE, method = "t")
Networknb(shape, snap = 1, queen = TRUE, method = "t")
shape |
A shapefile (in a polygon type) that matches to your OD dataframe. The shape must have an "id" column to match your ids in df. |
snap |
A parameter that is also used to calculate |
queen |
A TRUE/FALSE input that is used to calculate |
method |
A string value among "o" (origin based), "d" (destination based), and "t" (both way) which determines the way to generate Spatial Weights. The default value is "t". |
The result is in the form of a list which includes combinations of origin ids and destination ids.
# Data manipulation # Load sf polygon CA_polygon <- spnaf::CA_polygon # Execution of Networknb with data above and given parameters nnb <- Networknb(shape = CA_polygon, queen = TRUE, snap = 1, method = 'o') # check the results head(nnb)
# Data manipulation # Load sf polygon CA_polygon <- spnaf::CA_polygon # Execution of Networknb with data above and given parameters nnb <- Networknb(shape = CA_polygon, queen = TRUE, snap = 1, method = 'o') # check the results head(nnb)