<commit_before>"""
Geary's C statistic for spatial autocorrelation


Author(s): <NAME> <EMAIL>

"""
from pysal.common import *

PERMUTATIONS=999

class Geary:
    """Global Geary C Autocorrelation statistic
    
    Parameters
    ----------
    y              : array
    w              : W
                     spatial weights 
    transformation : string
                     weights transformation, default is row-standardized
                     "R". Other options include "B": binary, "D":
                         doubly-standardized, "U": untransformed (general
                         weights), "V": variance-stabilizing.
    permutations   : int
                     number of random permutations for calculation of
                     pseudo-p_values

    Attributes
    ----------
    y              : array
                     original variable
    w              : W
                     spatial weights
    permutations   : int
                     number of permutations
    C              : float
                     value of statistic
    EC             : float
                     expected value
    VC             : float
                     variance of G under normality assumption
    z_norm         : float
                     z-statistic for C under normality assumption
    z_rand         : float
                     z-statistic for C under randomization assumption
    p_norm         : float
                     p-value under normality assumption (one-tailed)
    p_rand         : float
                     p-value under randomization assumption (one-tailed)
    sim            : array (if permutations!=0)
                     vector of I values for permutated samples
    p_sim          : float (if permutations!=0)
                     p-value based on permutations
    EC_sim         : float (if permutations!=0)
                     average value of C from permutations
    VC_sim         : float (if permutations!=0)
                     variance of C from permutations
    seC_sim        : float (if permutations!=0)
                     standard deviation of C under permutations.
    z_sim          : float (if permutations!=0)
                     standardized C based on permutations
    p_z_sim        : float (if permutations!=0)
                     p-value based on standard normal approximation from
                     permutations

    Examples
    --------
    >>> import pysal
    >>> w=pysal.open("../examples/book.gal").read()
    >>> f=pysal.open("../examples/book.txt")
    >>> y=np.array(f.by_col['y'])
    >>> c=Geary(y,w,permutations=0)
    >>> c.C
    0.33281733746130032
    >>> c.p_norm
    0.00040151853759384792
    >>> 
    """
    def __init__(self,y,w,transformation="B",permutations=PERMUTATIONS):
        self.n=len(y)
        self.y=y
        w.transform=transformation
        self.w=w
        self.permutations=permutations
        self.__moments()<commit_msg>- catching platform precision bug<commit_after>"""
Geary's C statistic for spatial autocorrelation


Author(s): <NAME> <EMAIL>

"""
from pysal.common import *

PERMUTATIONS=999

class Geary:
    """Global Geary C Autocorrelation statistic
    
    Parameters
    ----------
    y              : array
    w              : W
                     spatial weights 
    transformation : string
                     weights transformation, default is row-standardized
                     "R". Other options include "B": binary, "D":
                         doubly-standardized, "U": untransformed (general
                         weights), "V": variance-stabilizing.
    permutations   : int
                     number of random permutations for calculation of
                     pseudo-p_values

    Attributes
    ----------
    y              : array
                     original variable
    w              : W
                     spatial weights
    permutations   : int
                     number of permutations
    C              : float
                     value of statistic
    EC             : float
                     expected value
    VC             : float
                     variance of G under normality assumption
    z_norm         : float
                     z-statistic for C under normality assumption
    z_rand         : float
                     z-statistic for C under randomization assumption
    p_norm         : float
                     p-value under normality assumption (one-tailed)
    p_rand         : float
                     p-value under randomization assumption (one-tailed)
    sim            : array (if permutations!=0)
                     vector of I values for permutated samples
    p_sim          : float (if permutations!=0)
                     p-value based on permutations
    EC_sim         : float (if permutations!=0)
                     average value of C from permutations
    VC_sim         : float (if permutations!=0)
                     variance of C from permutations
    seC_sim        : float (if permutations!=0)
                     standard deviation of C under permutations.
    z_sim          : float (if permutations!=0)
                     standardized C based on permutations
    p_z_sim        : float (if permutations!=0)
                     p-value based on standard normal approximation from
                     permutations

    Examples
    --------
    >>> import pysal
    >>> w=pysal.open("../examples/book.gal").read()
    >>> f=pysal.open("../examples/book.txt")
    >>> y=np.array(f.by_col['y'])
    >>> c=Geary(y,w,permutations=0)
    >>> c.C
    0.33281733746130032
    >>> print "%.8f"%c.p_norm
    0.00040152
    >>> 
    """
    def __init__(self,y,w,transformation="B",permutations=PERMUTATIONS):
        self.n=len(y)
        self.y=y
        w.transform=transformation
        self.w=w
        self.permutations=permutations
        self.__moments()
{'fraction_non_alphanumeric': 0.0813973206715279, 'fraction_numerical': 0.015092419874512463, 'mean_word_length': 1.3516746411483254, 'pattern_counts': {'":': 8, '<': 7, '<?xml version=': 0, '>': 55, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5481618', 'n_tokens_mistral': 1615, 'n_tokens_neox': 1429, 'n_words': 420}