コード例 #1
0
def test_hypothesis_3():
    # new multiple-regression
    img = nib.load(pathtoclassdata + "ds114_sub009_t2r1.nii")
    data = img.get_data()[..., 4:]
    # Read in the convolutions.
    convolved = np.loadtxt(pathtoclassdata + "ds114_sub009_t2r1_conv.txt")[4:]
    # Create design matrix.
    X = np.ones((convolved.shape[0], 2))
    X[:, 1] = convolved

    beta, t, df, p = t_stat(data, convolved, [0, 1])
    beta2, t2, df2, p2 = t_stat_mult_regression_single(data, X)

    beta3, t3, df3, p3 = t_stat_mult_regression(data, X)

    assert_array_equal(t, t2)
    assert_array_equal(t, np.atleast_2d(t3[1, :]))
コード例 #2
0
def test_hypothesis_3():
    # new multiple-regression
    img = nib.load(pathtoclassdata + "ds114_sub009_t2r1.nii")
    data = img.get_data()[..., 4:]
    # Read in the convolutions. 
    convolved = np.loadtxt(pathtoclassdata + "ds114_sub009_t2r1_conv.txt")[4:]
    # Create design matrix. 
    X=np.ones((convolved.shape[0],2))
    X[:,1]=convolved


    beta,t,df,p = t_stat(data, convolved,[0,1])
    beta2, t2,df2,p2 = t_stat_mult_regression_single(data, X)

    beta3, t3,df3,p3 = t_stat_mult_regression(data, X)


    assert_array_equal(t,t2)
    assert_array_equal(t,np.atleast_2d(t3[1,:]))
コード例 #3
0
        X_cond = np.ones((n_vols, 17))
        X_cond[:, 1] = hrf_matrix_1[:, j]  # 1 more
        X_cond[:, 2] = hrf_matrix_2[:, j]  # 1 more
        X_cond[:, 3] = hrf_matrix_3[:, j]  # 1 more
        X_cond[:, 4] = np.linspace(-1, 1, num=X.shape[0])  #drift # one
        X_cond[:, 5:11] = fourier_creation(X.shape[0], 3)[:, 1:]  # six more
        X_cond[:, 11:] = pca_addition

        #START CREATING MODELS

        ###################
        #   MODEL 1       #
        ###################
        # hrf (simple)

        beta1, t, df1, p = t_stat_mult_regression(data_slice, X[:, 0:2])

        MRSS1, fitted, residuals = glm_diagnostics(beta1, X[:, 0:2],
                                                   data_slice)

        model1_slice = np.zeros(len(MRSS1))

        rank1 = npl.matrix_rank(X[:, 0:2])

        count = 0

        for value in MRSS1:
            model1_slice[count] = adjR2(value, np.array(data_slice[count, :]),
                                        df1, rank1)
            count += 1
コード例 #4
0
ファイル: glm_final.py プロジェクト: janewliang/project-alpha

    
    #Run per slice in order to correct for time
    for j in range(data.shape[2]):
        
        data_slice = data[:, :, j, :]
        
        #Create design matrix
        X = np.ones((n_vols, 9))
        X[:, 1] = convolve[:, j]
        X[:, 2] = np.linspace(-1, 1, num = X.shape[0]) #drift
        X[:, 3:] = fourier_creation(n_vols, 3)[:, 1:]
        
        
        beta, t, df, p = t_stat_mult_regression(data_slice, X)
        
        #take only first coefficient      
        t = t[1, :]
        p = p[1, :]
        
        MRSS, fitted, residuals = glm_diagnostics(beta, X, data_slice)

        beta = beta[:, 1]
        
        #insert into the proper slice
        beta_final[:, :, j] = beta.reshape(data_slice.shape[:-1])
        t_final[:, :, j] = t.reshape(data_slice.shape[:-1])
        p_final[:, :, j] = p.reshape(data_slice.shape[:-1])        
        residual_final[:, :, j, :] = residuals.reshape(data_slice.shape)
        
コード例 #5
0
        X_cond[:, 1] = hrf_matrix_1[:, j] # 1 more
        X_cond[:, 2] = hrf_matrix_2[:, j] # 1 more
        X_cond[:, 3] = hrf_matrix_3[:, j] # 1 more
        X_cond[:, 4] = np.linspace(-1, 1, num = X.shape[0]) #drift # one 
        X_cond[:, 5:11] = fourier_creation(X.shape[0], 3)[:, 1:] # six more
        X_cond[:, 11:] = pca_addition


    #START CREATING MODELS

        ###################
        #   MODEL 1       #
        ###################
        # hrf (simple)

        beta1, t,df1, p = t_stat_mult_regression(data_slice, X[:, 0:2])
    
        MRSS1, fitted, residuals = glm_diagnostics(beta1, X[:, 0:2], data_slice)

        model1_slice = np.zeros(len(MRSS1))
    
        rank1 = npl.matrix_rank(X[:, 0:2])
    
        count = 0

        for value in MRSS1:
            model1_slice[count] = adjR2(value, np.array(data_slice[count, :]), df1, rank1)  
            count += 1


        adjr2_1 = adjr2_1 + model1_slice.tolist()
コード例 #6
0
    n_vols = data.shape[-1]
    convolve = np.loadtxt(hrf_data + i + "_hrf.txt")

    residual_final = np.zeros((data.shape))
    t_final = np.zeros((data.shape[:-1]))

    for j in range(data.shape[2]):

        data_slice = data[:, :, j, :]
        X = np.ones((n_vols, 6))
        X[:, 1] = convolve[:, j]
        X[:, 2] = np.linspace(-1, 1, num=X.shape[0])  #drift
        X[:, 3:] = fourier_creation(X.shape[0], 3)[:, 1:]

        beta, t, df, p = t_stat_mult_regression(data_slice, X)

        t = t[1, :]

        MRSS, fitted, residuals = glm_diagnostics(beta, X, data_slice)

        t_final[:, :, j] = t.reshape(data_slice.shape[:-1])

        residual_final[:, :, j, :] = residuals.reshape(data_slice.shape)

        np.save("../data/glm/t_stat/" + i + "_tstat.npy", t_final)
        np.save("../data/glm/residual/" + i + "_residual.npy", residual_final)

    sys.stdout.write("-")
    sys.stdout.flush()
sys.stdout.write("\n")
コード例 #7
0
    t_final1 = np.zeros((data_smooth.shape[:-1]))
    t_final2 = np.zeros((data_smooth.shape[:-1]))
    t_final3 = np.zeros((data_smooth.shape[:-1]))
    
    #Run per slice in order to correct for time
    for j in range(data_smooth.shape[2]):
        
        data_smooth_slice = data_smooth[:,:,j,:]
        data_rough_slice = data_rough[:,:,j,:]        
        #Create design matrix
        X = np.ones((n_vols,7))
        X[:,1] = convolve[:,j]
        X[:,2]=np.linspace(-1,1,num=X.shape[0]) #drift
        X[:,3:]=fourier_creation(X.shape[0],2)[:,1:]
        
        beta1,t1,df1,p1 = t_stat_mult_regression(data_rough_slice, X)
        beta2, t2, df2, p2 = t_stat(data_smooth_slice,convolve[:,j], c=[0,1] )
        beta3, t3, df3, p3 = t_stat(data_rough_slice,convolve[:,j], c=[0,1] )
        
        
        
        t1 = t1[1,:]
        t2 = t2.T
        t3= t3.T
                
        
        t_final1[:,:,j] = t1.reshape(data_rough_slice.shape[:-1])
        t_final2[:,:,j] = t2.reshape(data_smooth_slice.shape[:-1])
        t_final3[:,:,j] = t3.reshape(data_rough_slice.shape[:-1])