コード例 #1
0
def test_assoc(stat, expected):
    # 2d Array
    obs1 = np.array([[12, 13, 14, 15, 16],
                     [17, 16, 18, 19, 11],
                     [9, 15, 14, 12, 11]])
    a = association(observed=obs1, method=stat)
    assert_allclose(a, expected)
コード例 #2
0
    def fill_pairwisematrix(self):
        '''
        fills the square matrix using scipy's association method

        Returns
        -------
        None.

        '''

        n = len(self.cat_columns)
        # get all possible pair-wise combinations in the columns list
        # this assumes that A-->B equals B-->A so we don't need to
        # calculate the same thing twice
        # we also never get "A --> A"
        all_combinations = combinations(self.cat_columns, r=2)

        # note that because we ignore redundant combinations,
        # we perform half the calculations, so we get the results
        # twice as fast
        for comb in all_combinations:
            i = comb[0]
            j = comb[1]

            # make contingency table
            input_tab = crosstab(self.data[i], self.data[j])

            # find the resulting cramer association value using scipy's
            # association method
            res_cramer = association(input_tab, method='cramer')
            self.matrix[i][j], self.matrix[j][i] = res_cramer, res_cramer