pdk.Math.SpatialStatistics ($Date: 2002/12/04 10:16:02 $)
index
pdk/Math/SpatialStatistics.py

Spatial statistics routines.

FOG 08.1999,08.2002

 
Classes
            
pdk.ErrorClasses.pdkError(exceptions.StandardError)
SpatialStatsError
 
class SpatialStatsError(pdk.ErrorClasses.pdkError)
       
  
Method resolution order:
SpatialStatsError
pdk.ErrorClasses.pdkError
exceptions.StandardError
exceptions.Exception

Data and non-method functions defined here:
CODES = {'empty_distance_class': ('Distance class with no members encountered', 'Decrease the number of distance classes so each one will contain more members'), 'invalid_distance_class_mode': ('Invalid mode for generation of distance classes', 'Must be "equalsized", "linearspaced", or "logspaced" ["logspaced" not yet supported!]'), 'invalid_distance_class_type': ('Invalid distance class type', 'Must be either "circle" or "concentric"')}
DOMAIN = 'spatial stats'
 
Functions
            
mantel_correlogram(spatialDistMatrix, featureDistMatrix, mode='classical', test=0, statistics=<function mantel_r>, numberPermutations=1000, correlationFunction=<function correlation>, **distanceClassOptionD)

performs individual Mantel tests for each of a number of (spatial) distance classes built from the matrix of spatial distances spatialDistMatrix.

If mode is set to MANTELCORRELOGRAM_MODE_AUTO, a rather experimental autocorrelation statistics is computed (a true autocorrelation [lag one] of the distance class vectors; use e.g. cpca as statistics parameter in this mode).

Parameters:
  • spatialDistMatrix: a symmetric matrix of spatial distances between objects
  • featureDistMatrix: matrix of feature-induced distances between objects; must have the same shape as spatialDistMatrix
  • test: if True, a permutation test for significance of the correlogram is performed
  • statistics (only used if test is True): statistics for the correlogram significance test
  • numberPermutations (only used if test is True): number of permutations for the correlogram significance test
  • correlationFunction (only used with mode set to MANTELCORRELOGRAM_MODE_AUTO): is used for correlating the average distance vectors resulting from the individual distance classes
  • distanceClassOptionD: keyword arguments that are passed on to the distance_classes function
Value:

list of 4-tuples of results per distance class :: (<statistics value>,<significance>,<real distance>,<n class members>)

significance is always None if test is not set.

distance_classes(D, numberClasses, mode, bounds, kind='concentric')

Takes a symmetic pxp distance matrix <D> and returns a list of numberClasses (<indicator matrix>,<upper bound>,<class size>) tuples with

  • <indicator matrix>: symmetric binary matrix indicating membership to

    the distance class

  • <upper bound>: upper boundary for distance class

  • <class size>: number of sample units per class

If bounds is not None, it is taken to be a list of upper boundaries. Otherwise, the boundaries are computed according to the value of mode, which can be one of the following:

  • DISTANCECLASS_MODE_EQUALSIZED: produces classes with equal numbers of neighborhood relationships (but not necessarily containing equal numbers of sample units!)
  • DISTANCECLASS_MODE_EQUALSPACED: produces classes based on linearly spaced boundaries
  • DISTANCECLASS_MODE_LOGSPACED: produces classes based on log-spaced boundaries (not implemented yet!)

kind decides on what type of distance classes is generated:

  • DISTANCECLASS_KIND_CIRCULAR: includes all neighbors closer than bounds[ i ]
  • DISTANCECLASS_KIND_CONCENTRIC: includes neighbors which are closer than bounds[ i ], but farther than bounds[ i-1 ]
n_nearest_neighbors(D, n=5)
Takes a pxp distance matrix D and returns a pxp binary matrix indicating the nearest n neighbors of each row/column in D. n = 0 for i in [ 0..p-1 ].
spatial_ca(X, M, mode='principal', n_axes=1)

performs a CA with spatial weights as shown in Thiououse et al. (1995) (J Ecol Environ Statist 2: 1-14). X is the n x p data matrix (non-negative, no zero row/column totals as in normal CA) and M is the (n x n) matrix of the neighboring graph (m_ij = 1 if i neighbor of j; also symmetric with no zero row/column totals).

Returns a 3-tuple

(<total CA results>, <global CA results>, <local CA results>)

each consisting of a triplet of arrays:

(<row principals>, <column principals>, <singular values>)
spatial_pca(X, M, mode='principal', n_axes=1)
performs a PCA with spatial weights as shown in Thiououse et al. (1995) (J Ecol Environ Statist 2: 1-14).
 
Author
            
$Author: gathmann $