pointpats.Knox

class pointpats.Knox(s_coords, t_coords, delta, tau, permutations=99, keep=False)[source]

Global Knox statistic for space-time interactions

Parameters:
s_coords: array-like

spatial coordinates of point events

t_coords: array-like

temporal coordinates of point events (floats or ints, not dateTime)

delta: float

spatial threshold defining distance below which pairs are spatial neighbors

tau: float

temporal threshold defining distance below which pairs are temporal neighbors

permutations: int

number of random permutations for inference

keep: bool

whether to store realized values of the statistic under permutations

Notes

Technical details can be found in [Rog01]

Examples

>>> import libpysal
>>> path = libpysal.examples.get_path('burkitt.shp')
>>> import geopandas
>>> df = geopandas.read_file(path)
>>> from pointpats.spacetime import Knox
>>> global_knox = Knox(df[['X', 'Y']], df[["T"]], delta=20, tau=5)
>>> global_knox.statistic_
13
>>> global_knox.p_poisson
0.14624558197140414
>>> global_knox.observed
array([[1.300e+01, 3.416e+03],
       [3.900e+01, 1.411e+04]])
>>> global_knox.expected
array([[1.01438161e+01, 3.41885618e+03],
       [4.18561839e+01, 1.41071438e+04]])
>>> hasattr(global_knox, 'sim')
False
>>> import numpy
>>> numpy.random.seed(12345)
>>> global_knox = Knox(df[['X', 'Y']], df[["T"]], delta=20, tau=5, keep=True)
>>> hasattr(global_knox, 'sim')
True
>>> global_knox.p_sim
0.21
Attributes:
s_coords: array-like

spatial coordinates of point events

t_coords: array-like

temporal coordinates of point events (floats or ints, not dateTime)

delta: float

spatial threshold defining distance below which pairs are spatial neighbors

tau: float

temporal threshold defining distance below which pairs are temporal neighbors

permutations: int

number of random permutations for inference

keep: bool

whether to store realized values of the statistic under permutations

nst: int

number of space-time pairs

p_poisson: float

Analytical p-value under Poisson assumption

p_sim: float

Pseudo p-value based on random permutations

expected: array

Two-by-two array with expected counts under the null of no space-time interactions. [[NST, NS_], [NT_, N__]] where NST is the expected number of space-time pairs, NS_ is the expected number of spatial (but not also temporal) pairs, NT_ is the number of expected temporal (but not also spatial pairs), N__ is the number of pairs that are neighor spatial or temporal neighbors.

observed: array

Same structure as expected with the observed pair classifications

sim: array

Global statistics from permutations (if keep=True)

__init__(s_coords, t_coords, delta, tau, permutations=99, keep=False)[source]

Methods

__init__(s_coords, t_coords, delta, tau[, ...])

from_dataframe(dataframe, time_col, delta, tau)

Compute a Knox statistic from a dataframe of Point observations

classmethod from_dataframe(dataframe, time_col: int, delta: int, tau: int, permutations: int = 99, keep: bool = False)[source]

Compute a Knox statistic from a dataframe of Point observations

Parameters:
dataframegeopandas.GeoDataFrame

geodataframe holding observations. Should be in a projected coordinate system with geometries stored as Point

time_colstr

column in the dataframe storing the time values (integer coordinate) for each observation. For example if the observations are stored with a timestamp, the time_col should be converted to a series of integers representing, e.g. hours, days, seconds, etc.

deltaint

delta parameter defining the spatial neighbor threshold measured in the same units as the dataframe CRS

tauint

tau parameter defining the temporal neihgbor threshold (in the units measured by time_col)

permutationsint, optional

permutations to use for computation inference, by default 99

keepbool

whether to store realized values of the statistic under permutations

Returns:
pointpats.spacetime.Knox

a fitted Knox class