Esempio n. 1
0
            pair = [pair[1],pair[0]]
            a = df_sub[pair[0]].values
            b = df_sub[pair[1]].values
        ps = resample_ttest_2sample(a,b,500,10000)
        results['greater'].append(pair[0])
        results['lesser'].append(pair[1])
        results['ps_mean'].append(ps.mean())
        results['ps_std'].append(ps.std())
        results['model'].append(model)
results = pd.DataFrame(results)

temp = []
for modle, df_sub in results.groupby('model'):
    idx_sort = np.argsort(df_sub['ps_mean'].values)
    df_sub = df_sub.iloc[idx_sort,:]
    converter = MCPConverter(df_sub['ps_mean'].values)
    d = converter.adjust_many()
    df_sub['p_corrected'] = d['bonferroni'].values
    temp.append(df_sub)
results = pd.concat(temp)
results_pos = results.copy()
results_pos['exp'] = 'pos'

# epx 2
results = dict(greater = [],
               lesser  = [],
               ps_mean = [],
               ps_std  = [],
               model   = [],)
df = att[(att['window'] > 0) & (att['window'] < 4)]
for model,df_sub in df.groupby('model'):
Esempio n. 2
0
 
 ###########################################################################
 #############################################################################
 ############################################################################
 
 pos = pd.read_csv(os.path.join(results_dir,'Att_leave_one_sub_out.csv'))
 att = pd.read_csv(os.path.join(results_dir,'Att_leave_one_sub_out.csv'))
 
 combimed = []
 n_back = 4
 df = pos.copy()
 df = df[df['window'] <= 4]
 temp = []
 for model,df_sub in df.groupby('model'):
     df_temp = df_sub.sort_values(by='p_val')
     converter = MCPConverter(df_temp['p_val'].values)
     df_pvals = converter.adjust_many()
     df_temp['p_corrected'] = df_pvals['bonferroni'].values
     temp.append(df_temp)
 df = pd.concat(temp)
 df['experiment'] = 'Probability of Success'
 combimed.append(df)
 
 df = att.copy()
 df = df[df['window'] <= 4]
 temp = []
 for model,df_sub in df.groupby('model'):
     df_temp = df_sub.sort_values(by='p_val')
     converter = MCPConverter(df_temp['p_val'].values)
     df_pvals = converter.adjust_many()
     df_temp['p_corrected'] = df_pvals['bonferroni'].values
        corr,
        0,
    )
    print(corr.shape)
    t_test_results['experiment'].append(experiment)
    t_test_results['comparison'].append(comparison)
    t_test_results['p'].append(p)
    t_test_results['t'].append(t)
    t_test_results['corr_mean'].append(df_sub['correlation'].values.mean())
    t_test_results['corr_std'].append(df_sub['correlation'].values.std())
t_test_results = pd.DataFrame(t_test_results)
temp = []
for experiment, df_sub in t_test_results.groupby(['experiment']):
    df_sub = df_sub.sort_values(['p'])
    ps = df_sub['p'].values
    converter = MCPConverter(pvals=ps)
    d = converter.adjust_many()
    df_sub['p_corrected'] = d['bonferroni'].values
    temp.append(df_sub)
t_test_results = pd.concat(temp)
t_test_results = t_test_results[[
    'experiment', 'comparison', 'p_corrected', 't', 'corr_mean', 'corr_std',
    'p'
]]

df_full = pd.concat([df, df_chance])
df_full['x'] = 0

g = sns.catplot(
    x='x',
    y='correlation',
Esempio n. 4
0
if not os.path.exists(figure_dir):
    os.mkdir(figure_dir)
n_sub = {'POS': 15, 'ATT': 16}
df_plot = []
for f in working_data:
    f = f.replace('\\', '/')
    df = pd.read_csv(f)
    df = df.iloc[1:, :]
    attr = df['Unnamed: 0'].apply(lambda x: x.split('_')[0])
    time = df['Unnamed: 0'].apply(lambda x: int(x.split('_')[1]))
    df = df.iloc[:, 1:]
    df['Attributes'] = attr
    df['time'] = time
    df['experiment'] = f.split('/')[-1].split('_')[0]
    df = df.sort_values(['sign'])
    converter = MCPConverter(df['sign'].values)
    d = converter.adjust_many()
    df['ps_corrected'] = d['bonferroni'].values
    df_plot.append(df)
df_plot = pd.concat(df_plot)
df_plot['star'] = df_plot['ps_corrected'].apply(stars)
df_plot['Attributes'] = df_plot['Attributes'].map({
    'awareness': 'awareness',
    'confidence': 'confidence',
    'correct': 'correctness'
})

res = dict(
    experiment=[],
    time=[],
    t=[],
        ps = resample_ttest_2sample(df_sub['score'].values,
                                    df_sub_chance['score'].values,
                                    one_tail=False,
                                    n_ps=1000,
                                    n_permutation=10000)
        results['model'].append(model)
        results['window'].append(window)
        results['ps_mean'].append(ps.mean())
        results['ps_std'].append(ps.std())
    results = pd.DataFrame(results)
    temp = []
    for model, df_sub in results.groupby('model'):
        idx_sort = np.argsort(df_sub['ps_mean'])
        for name in results.columns:
            df_sub[name] = df_sub[name].values[idx_sort]
        convert = MCPConverter(pvals=df_sub['ps_mean'].values)
        df_pvals = convert.adjust_many()
        df_sub['ps_corrected'] = df_pvals['bonferroni'].values
        temp.append(df_sub)
    results = pd.concat(temp)
    results.sort_values(['model', 'window'
                         ]).to_csv('../results/Pos_ttest_6_features.csv',
                                   index=False)

    ##########################################################################
    id_vars = [
        'model',
        'score',
        'sub',
        'window',
    ]
    )
    ttest['model'].append(model)
    ttest['window'].append(window)
    ttest['ps_mean'].append(np.mean(ps))
    ttest['ps_std'].append(np.std(ps))
    print('{} window {} {:.3f}'.format(model, window, np.mean(ps)))
d = pd.DataFrame(ttest)  # transform a dictionary object to data frame
# now it is the p value correction for multiple comparison
# note that the correction is done within each model along the number of windows
# , and we have 3 models
temp = []
for model, d_ in d.groupby('model'):  # for each model
    idx_sort = np.argsort(d_['ps_mean'].values)
    for name in d_.columns:
        d_[name] = d_[name].values[idx_sort]
    coverter = MCPConverter(d_['ps_mean'].values  # numpy array 
                            )  # initialize the functional object
    df = coverter.adjust_many()  # run the method in the object
    d_['ps_corrected'] = df[
        'bonferroni'].values  # here is one of the 4 correction methods
    temp.append(d_)
d = pd.concat(temp)
d.to_csv('../results/Pos_ttest_6_features.csv', index=False)
################################################################################
# use success, awareness, and confidence as features
experiment = 'pos'
df = pd.read_csv(os.path.join(working_dir, '../data/PoSdata.csv'))
df = df[df.columns[1:]]
df.columns = [
    'participant', 'blocks', 'trials', 'firstgabor', 'success', 'tilted',
    'correct', 'RT_correct', 'awareness', 'RT_awareness', 'confidence',
    'RT_confidence'