Example #1
0
                            % (groups[i1], groups[i2]), Style_3)

        # prepare data
        Y1 = np.zeros([groups_n[i1], len(rois), len(effects)])
        Y2 = np.zeros([groups_n[i2], len(rois), len(effects)])
        for e in range(0, len(effects)):
            sheet = xls.sheet_by_index(e)

            for r in range(0, len(rois)):
                for s in range(0, groups_n[i1]):
                    Y1[s, r, e] = sheet.cell(groups_row[i1] + s, r + 1).value
                for s in range(0, groups_n[i2]):
                    Y2[s, r, e] = sheet.cell(groups_row[i2] + s, r + 1).value

        # run the test
        t, T, pu, p = permutation_test(Y1, Y2, permutations=nPERMUTATIONS)

        # add to the spreadsheet
        for r in range(0, len(rois)):
            if pu[r] <= 0.05:
                sheet_out.write(OUT_row, r + 1, pu[r], Style_1)
            else:
                sheet_out.write(OUT_row, r + 1, pu[r], Style_2)
            if p[r] <= 0.05:
                sheet_out.write(OUT_row + nTESTs + 2, r + 1, p[r], Style_1)
            else:
                sheet_out.write(OUT_row + nTESTs + 2, r + 1, p[r], Style_2)
        OUT_row = OUT_row + 1


# writing results to file
Example #2
0
import numpy as np
from scikits.permuttest.two_sample import permutation_test, t_stat, hotelling_t_square, design_matrix


"""
Y = np.random.normal(size=(10, 10000))
t = t_stat(Y, 5)
"""

# 10 subjects, 7 regions, 2 contrasts
Y = np.random.normal(size=(10, 100, 2))

# test hotelling stat without confounds
T0 = hotelling_t_square(Y, 5)

# test hotelling stat with confounds
# age = np.random.rand(10)
age = np.zeros(10) + 0.01 * np.random.rand(10)
age[0:5] += 1.0

T1 = hotelling_t_square(Y, 5, confounds=(age,))

# test permutation test
t, T, pu, p = permutation_test(Y[0:5, ...], Y[5:, ...], confounds=(age,), permutations=100)

t, T, pu, p = permutation_test(Y[0:5, :, 0] + 5, Y[5:, :, 0], confounds=(age,), permutations=100, two_sided=False)

# t, T, pu, p = permutation_test(Y[0:5, :, 0] + 2, Y[5:, :, 0], permutations=100)
        # prepare data
        Y1 = np.zeros([groups_n[i1], len(rois), len(effects)])
        Y2 = np.zeros([groups_n[i2], len(rois), len(effects)])
        for e in range(0, len(effects)):
            sheet = xls.sheet_by_name( effects[e] )

            for r in range(0, len(rois)):
                for s in range(0, groups_n[i1]):
                    Y1[s, r, e] = sheet.cell(groups_row[i1] + s, r + 1).value
                for s in range(0, groups_n[i2]):
                    Y2[s, r, e] = sheet.cell(groups_row[i2] + s, r + 1).value

        # run the test
        if len(covariates) == 0 or use_covariates == False :
            t, T, pu, p = permutation_test(Y1, Y2, permutations=nPERMUTATIONS, confounds=None, two_sided=(True if nTAILS == 2 else False))
        else :
            # prepare covariates
            CONFOUNDS = np.zeros([len(covariates), groups_n[i1]+groups_n[i2]])
            sheet = xls.sheet_by_name( "Covariates" )
            for c in range(0, len(covariates)):
                for s in range(0, groups_n[i1]):
                    CONFOUNDS[c,s] = sheet.cell(groups_row[i1] + s, c + 1).value
                for s in range(0, groups_n[i2]):
                    CONFOUNDS[c, groups_n[i1]+s] = sheet.cell(groups_row[i2] + s, c + 1).value

            t, T, pu, p = permutation_test(Y1, Y2, permutations=nPERMUTATIONS, confounds=CONFOUNDS, two_sided=(True if nTAILS == 2 else False))

        # add to the spreadsheet
        for r in range(0, len(rois)):
            if pu[r] <= 0.05: