def test_calcSigProp():
    # Set up test betas
    t_beta = np.array([[0, 0, 0, 0, 0], [0.4, 0.03, 0.1, 1, 0.17], [2, 0.1, 0.09, 0.2, 0.88], [1, 1.2, 0.9, 0.4, 0.51], [0.31, 0.22, 0.16, 0.05, 0.02]])
    sig_level = 0.1
    # Get significant level of 2nd column after reshaping to (5,5)
    # 0, 0.03, 0.1, 1.2, 0.22
    notzero_beta = t_beta[t_beta !=0].reshape(-1,5)
    t_psig_gain = sum(notzero_beta[:,1]<=sig_level)/len(notzero_beta[:,1])
    # Get significant level of 4th column 
    # 0, 1, 0.2, 0.4, 0.05
    t_psig_loss = sum(notzero_beta[:,3]<=sig_level)/len(notzero_beta[:,3]) 
 
   # My function
    my_psig_gain, my_psig_loss = calcSigProp(t_beta, sig_level)
    
    # Assert
    assert_almost_equal(my_psig_gain, t_psig_gain)
    assert_almost_equal(my_psig_loss, t_psig_loss)
示例#2
0
        parameters = merge_cond(behav_cond, task_cond1, task_cond2, task_cond3, task_cond4)
        neural_prediction = events2neural_extend(parameters,TR, n_vols)
        gain, loss, linear_dr, quad_dr = getRegressor(TR, n_vols, hrf_at_trs, neural_prediction)
        data, gain, loss, linear_dr, quad_dr = deleteOutliers(data, gain, loss, linear_dr, quad_dr, i, run, dvars_out, fd_out)
        run_count[j-1] = data.shape[3]     ## dummy variable indicating the groups
        data_full = np.concatenate((data_full,data),axis=3)
        gain_full = np.concatenate((gain_full,gain),axis=0)
        loss_full = np.concatenate((loss_full,loss),axis=0)
        linear_full = np.concatenate((linear_full,linear_dr),axis=0)
        quad_full = np.concatenate((quad_full,quad_dr),axis=0)
        
    run_group = np.concatenate((np.repeat(1, run_count[0]), 
                                np.repeat(2, run_count[1]), np.repeat(3, run_count[2])), axis=0)
    thrshd = 400 ## set a threshold to idenfity the voxels inside the brain
    print "calculating parameters of subject "+str(i)
    beta = calcBetaLme(data_full, gain_full, loss_full, linear_full, quad_full, run_group, thrshd)
    sig_level = 0.05
    sig_gain_prop[i-1], sig_loss_prop[i-1] = calcSigProp(beta, sig_level)
    write=pathtofolder + 'ds005/sub0'+str(i).zfill(2)+'/model/model001/onsets/sub0'+str(i).zfill(2)+'_lme_beta.txt'
    np.savetxt(write, beta)
    anov_test = calcAnov(data_full, run_group, thrshd)
    anov_prop[i-1] = anovStat(anov_test)

write=pathtofolder + 'ds005/models/lme_sig_gain_prop.txt'
np.savetxt(write,  sig_gain_prop)
write=pathtofolder + 'ds005/models/lme_sig_loss_prop.txt'
np.savetxt(write,  sig_loss_prop)
write=pathtofolder + 'ds005/models/anova_prop.txt'
np.savetxt(write,  anov_prop)

示例#3
0
        parameters = merge_cond(behav_cond, task_cond1, task_cond2, task_cond3, task_cond4)
        neural_prediction = events2neural_extend(parameters,TR, n_vols)
        gain, loss, linear_dr, quad_dr = getRegressor(TR, n_vols, hrf_at_trs, neural_prediction)
        data, gain, loss, linear_dr, quad_dr = deleteOutliers(data, gain, loss, linear_dr, quad_dr, i, run, dvars_out, fd_out)
        run_count[j-1] = data.shape[3]     ## dummy variable indicating the groups
        data_full = np.concatenate((data_full,data),axis=3)
        gain_full = np.concatenate((gain_full,gain),axis=0)
        loss_full = np.concatenate((loss_full,loss),axis=0)
        linear_full = np.concatenate((linear_full,linear_dr),axis=0)
        quad_full = np.concatenate((quad_full,quad_dr),axis=0)
        
    run_group = np.concatenate((np.repeat(1, run_count[0]), 
                                np.repeat(2, run_count[1]), np.repeat(3, run_count[2])), axis=0)
    thrshd = 400 ## set a threshold to idenfity the voxels inside the brain
    print "calculating parameters of subject "+str(i)
    beta = calcBetaLme(data_full, gain_full, loss_full, linear_full, quad_full, run_group, thrshd)
    sig_level = 0.05
    sig_gain_prop[i-1], sig_loss_prop[i-1] = calcSigProp(beta, sig_level)
    write=pathtofolder + 'ds005/sub0'+str(i).zfill(2)+'/model/model001/onsets/sub0'+str(i).zfill(2)+'_lme_beta.txt'
    np.savetxt(write, beta)
    anov_test = calcAnov(data_full, run_group)
    anov_prop[i-1] = anovStat(anov_test)

write=pathtofolder + 'ds005/models/lme_sig_gain_prop.txt'
np.savetxt(write,  sig_gain_prop)
write=pathtofolder + 'ds005/models/lme_sig_loss_prop.txt'
np.savetxt(write,  sig_loss_prop)
write=pathtofolder + 'ds005/models/anova_prop.txt'
np.savetxt(write,  anov_prop)