def pValForGi(gVal):
        """ This function uses the pdf module to calculate p values.
        
        Parameters:
        Name        Type                Description
        gVal        Float               A Gi statistic value (standard normal variate.

        Output:
        Name        Type                Description
        pVal        Float               A value from the normal or t probability distribution.
        """
        if gVal >= 0:
            if gVal < 6.0:
                pVal = 1.0-pdf.zprob(gVal)
            else:
                pVal = pdf.tpvalue(gVal,3000)
        else:
             if gVal > -6.0:
                pVal = pdf.zprob(gVal)
             else:
                pVal = pdf.tpvalue(gVal,3000)
        return 2.0*pVal
Exemple #2
0
    def __init__(self, y, w, permutations=0, varAssumption="normalization"):
        self.variable = y
        if y.t == 1:  # check for cs variable
            n = y.n
            y = reshape(y, (n, 1))
        self.varAssumption = varAssumption
        self.iMoments(w)
        self.permutations = permutations
        self.w = w
        yd = y - mean(y)
        den = matrixmultiply(transpose(yd), yd)
        print sum(sum(den == 0))
        # from here down changes for permutations (not done yet)
        # check for permutation and then permutate the yd
        ylag = lag(yd, w)
        self.ylag = lag(y, w)
        num = matrixmultiply(transpose(yd), ylag)
        if len(shape(num)) > 1:
            self.mi = diag(num / den)
            self.zi = (self.mi - self.ei) / self.si
            n, t = shape(ylag)
        else:
            n = len(y)
            t = 1
            self.mi = num / den
            self.zi = (self.mi - self.ei) / self.si

        self.npvalue = [1 - pdf.zprob(abs(x)) for x in self.zi]
        if permutations:
            Message(
                "Moran's I, %d permutations for %d regions and %d time periods"
                % (permutations, n, t))
            mip = []
            count = zeros([1, t])
            for iter in range(permutations):
                ylag = lag(permutate(yd), w)
                num = matrixmultiply(transpose(yd), ylag)
                if len(shape(num)) > 1:
                    mi = diag(num / den)
                else:
                    mi = num / den
                count += self.extreme(mi)
                mip.append(mi)
            self.ppvalue = count / (permutations * 1.0)
Exemple #3
0
 def __init__(self,y,w,permutations=0,varAssumption = "normalization"):
     self.variable = y
     if y.t == 1: # check for cs variable
         n=y.n
         y = reshape(y,(n,1))
     self.varAssumption = varAssumption
     self.iMoments(w)
     self.permutations=permutations
     self.w = w
     yd = y - mean(y)
     den = matrixmultiply(transpose(yd),yd)
     print sum(sum(den==0))
     # from here down changes for permutations (not done yet)
     # check for permutation and then permutate the yd
     ylag = lag(yd,w)
     self.ylag = lag(y,w)
     num = matrixmultiply(transpose(yd),ylag)
     if len(shape(num)) > 1:
         self.mi = diag(num/den)
         self.zi = (self.mi - self.ei)/self.si
         n,t=shape(ylag)
     else:
         n=len(y)
         t=1
         self.mi = num/den
         self.zi = (self.mi - self.ei)/self.si
         
     self.npvalue = [ 1 - pdf.zprob(abs(x)) for x in self.zi]
     if permutations:
         Message("Moran's I, %d permutations for %d regions and %d time periods"
         %(permutations,n,t))
         mip = []
         count =zeros([1,t]) 
         for iter in range(permutations):
             ylag=lag(permutate(yd),w)
             num = matrixmultiply(transpose(yd),ylag)
             if len(shape(num)) > 1:
                 mi = diag(num/den)
             else:
                 mi = num/den
             count += self.extreme(mi)
             mip.append(mi)
         self.ppvalue = count/(permutations * 1.0)
Exemple #4
0
 def __init__(self,y,w,permutations=0,varAssumption = "normalization"):
     self.varAssumption = varAssumption
     self.w=w
     self.variable = y
     n=y.n
     self.n=n
     self.cMoments(w)
     self.iMat=ones((n,n))
     res=map(self.calc,transpose(y))
     self.gc=array(res)
     self.zc = (self.gc - 1) / self.sc
     self.zpvalue = [ 1 - pdf.zprob(abs(x)) for x in self.zc]
     self.permutations = permutations
     if permutations:
         count = ones([1,y.t])
         resperm=[]
         iterations=range(permutations)
         for it in iterations:
             yp=permutate(y)
             gc = map(self.calc,transpose(yp))
             resperm.append(gc)
             count += self.extreme(gc)
         self.ppvalue = count/(permutations * 1.0 + 1.0)