Esempio n. 1
0
def test_stratified_table_cube():
    # Test that we can pass a rank 3 ndarray or a list of rank 2
    # ndarrays to StratifiedTable and get the same results.

    tab1 = [[[8, 9], [6, 7]], [[4, 9], [5, 5]], [[8, 8], [9, 11]]]
    tab2 = np.asarray(tab1).T

    ct1 = ctab.StratifiedTable(tab1)
    ct2 = ctab.StratifiedTable(tab2)

    assert_allclose(ct1.oddsratio_pooled, ct2.oddsratio_pooled)
    assert_allclose(ct1.logodds_pooled, ct2.logodds_pooled)
Esempio n. 2
0
    def test_from_data(self):

        np.random.seed(241)
        df = pd.DataFrame(index=range(100), columns=("v1", "v2", "strat"))
        df["v1"] = np.random.randint(0, 2, 100)
        df["v2"] = np.random.randint(0, 2, 100)
        df["strat"] = np.kron(np.arange(10), np.ones(10))

        tables = []
        for k in range(10):
            ii = np.arange(10 * k, 10 * (k + 1))
            tables.append(pd.crosstab(df.loc[ii, "v1"], df.loc[ii, "v2"]))

        rslt1 = ctab.StratifiedTable(tables)
        rslt2 = ctab.StratifiedTable.from_data("v1", "v2", "strat", df)

        assert_equal(rslt1.summary().as_text(), rslt2.summary().as_text())
Esempio n. 3
0
 def initialize(cls, tables):
     cls.rslt = ctab.StratifiedTable(tables)
     cls.rslt_0 = ctab.StratifiedTable(tables, shift_zeros=True)
     tables_pandas = [pd.DataFrame(x) for x in tables]
     cls.rslt_pandas = ctab.StratifiedTable(tables_pandas)
Esempio n. 4
0
 def initialize(cls, tables, use_arr=False):
     tables1 = tables if not use_arr else np.dstack(tables)
     cls.rslt = ctab.StratifiedTable(tables1)
     cls.rslt_0 = ctab.StratifiedTable(tables, shift_zeros=True)
     tables_pandas = [pd.DataFrame(x) for x in tables]
     cls.rslt_pandas = ctab.StratifiedTable(tables_pandas)
 def initialize(self, tables):
     self.rslt = ctab.StratifiedTable(tables)
     self.rslt_0 = ctab.StratifiedTable(tables, shift_zeros=True)
     tables_pandas = [pd.DataFrame(x) for x in tables]
     self.rslt_pandas = ctab.StratifiedTable(tables_pandas)
#
    if ((matchindex - currRow) == number_of_elements_of_stratified_table):
        ctable = np.zeros(shape=(2, 2, sk))
        ict = currRow
        for k in range(0, sk):
            #           print("=======================================")
            #           print("strata :" + str(k+1))
            #           print("=======================================")
            for i in range(0, 2):
                for j in range(0, 2):
                    ctable[i, j, k] = data.iloc[ict, 12]
                    #                   print(" c(" + str(i+1) + "," + str(j+1) + "," + str(k+1) + ") = " + str(ctable[i,j,k]), end = '')
                    ict = ict + 1
#               print("\n", end = '')
#           print(ctable[:,:,k])
        cmh = sm.StratifiedTable(ctable)
        t = cmh.test_null_odds()
        print(currTemp + " " + currDay + " " + currMapping + " " +
              currPosition + "\t" + currRef + "\t" + currAllele + "\t" +
              str(t.pvalue) + "\t" + str(t.statistic))
#       print(cmh.test_null_odds())
#       print(cmh.test_equal_odds())
#       print(cmh.summary())
#   while loop check
    currRow = matchindex
    if (currRow < nrow):
        currTemp = data.iloc[currRow, 0]
        currDay = data.iloc[currRow, 1]
        currPop = data.iloc[currRow, 2]
        currMapping = data.iloc[currRow, 3]
        currPosition = data.iloc[currRow, 4]