spatial_statistic: Calculating Spatial Statistics

spatial_statisticR Documentation

Calculating Spatial Statistics

Description

Calculation of a specified spatial statistic for the data from an infpan object.

Usage

spatial_statistic(
    object,
    attribute = "Cases",
    timepoint = NULL,
    statistic = "nbstat",
    func = NULL,
    row.names = NULL,
    snap = NULL,
    queen = TRUE,
    weights_style = "W",
    weights_zeropolicy = NULL,
    verbose = FALSE,
    ...
  )

Arguments

object

object of class infpan

attribute

Attribute for which the statistic is calculated, must be defined in infpan object (e.g., "Cases", "Incidence")

timepoint

Time point for which the statistic is calculated

statistic

Statistic to be computed

func

If statistic == "nbstat": Descriptive statistic (FUN) to be computed for data_col of the neighbouring regions

row.names

row.names for the sf object, passed to spdep::poly2nb

snap

Snapping distance, passed to spdep::poly2nb

queen

If TRUE, a single shared boundary point meets the contiguity condition; passed to spdep::poly2nb

weights_style

weights_style can take values “W”, “B”, “C”, “U”, “minmax” and “S”; passed to the style argument of spdep::nb2listw

weights_zeropolicy

if FALSE stop with error for any empty neighbour sets, if TRUE permit the weights list to be formed with zero-length weights vectors; passed to the zero.policy argument of spdep::nb2listw

verbose

bool argument which indicates whether progress messages are displayed

...

Further arguments passed to the spatial statistics functions (see details)

Details

The user must choose a specific time point using the timepoint argument. If no time point is stated, the most current time point is chosen automatically.

The ... arguments are passed to the specific spatial statistics function which depends on what is specified by argument statistic. See moran, getisord, gstar.

Value

nbmatrix object including the spatial statistic to be calculated

Author(s)

Thomas Wieland

References

Cliff AD, Ord JK (1981) Spatial Processes: Models & Applications. https://archive.org/details/spatialprocesses0000clif

GeoDa Center (2026) GeoDa. An Introduction to Spatial Data Science. https://geodacenter.github.io/

Wieland T (2020) Flatten the Curve! Modeling SARS-CoV-2/COVID-19 Growth in Germany at the County Level. REGION 7(2), 43–83. \Sexpr[results=rd]{tools:::Rd_expr_doi("https://doi.org/10.18335/region.v7i2.324")}

Wieland T (2022) Spatial patterns of excess mortality in the first year of the COVID-19 pandemic in Germany. European Journal of Geography 13(4), 18-33. \Sexpr[results=rd]{tools:::Rd_expr_doi("https://doi.org/10.48088/ejg.t.wie.13.4.018.033")}

See Also

infpan-class, nbstat, nbmatrix, moran, getisord, gstar

Examples

data(COVID19Cases_geoRegion)
# Get SWISS COVID19 cases at NUTS 3 level

data(K4kant20260101gf_ch2007Poly)
# Cantonal boundaries of Switzerland

COVID19Cases_geoRegion <- 
  COVID19Cases_geoRegion[!COVID19Cases_geoRegion$geoRegion %in% c("CH", "CHFL"),]
# Exclude CH = Switzerland total and CHFL = Switzerland and Liechtenstein total

COVID19Cases_geoRegion <- 
  COVID19Cases_geoRegion[COVID19Cases_geoRegion$datum <= "2020-05-31",]
# Extract first COVID-19 wave

infpan_CH <- load_infections_paneldata(
  data = COVID19Cases_geoRegion,
  col_cases = "entries",
  col_date = "datum",
  col_region = "geoRegion",
  other_cols = c(
    "Population" = "pop"
  ), 
  verbose = TRUE
)
# Import as infections panel data set (class infpan)

infpan_CH <- add_geodata(
  infpan_CH,
  K4kant20260101gf_ch2007Poly,
  unit_col = "cant_abbrev"
)
# Adding geodata (sf) to infpan object

summary(infpan_CH)
# Summary of infpan object

timestamps(infpan_CH)
# Time stamps of infpan object

moran_incidence <-
  spatial_statistic(
    infpan_CH,
    statistic = "moran",
    randomization = FALSE
  )
# Calculating Moran's I test under normality
# Result = nbmatrix object

swash documentation built on Oct. 18, 2026, 5:06 p.m.