예제 #1
0
OUTPUT = os.path.join(INPUT, "univariate_analysis")
X = np.load(os.path.join(INPUT, "X.npy"))
y = np.load(os.path.join(INPUT, "y.npy"))

Z = X[:, :3]
Y = X[:, 3:]
assert np.sum(mask_arr) == Y.shape[1]

DesignMat = np.zeros((Z.shape[0], Z.shape[1] + 1))  # y, intercept, age, sex
DesignMat[:, 0] = (y.ravel() - y.ravel().mean())  # y
DesignMat[:, 1] = 1  # intercept
DesignMat[:, 2] = Z[:, 1]  # age
DesignMat[:, 3] = Z[:, 2]  # sex

muols = MUOLS(Y=Y, X=DesignMat)
muols.fit()
tvals, pvals, dfs = muols.t_test(contrasts=[1, 0, 0, 0], pval=True)
np.savez(os.path.join(OUTPUT, "pvals", "pvals.npz"), pvals[0])
np.savez(os.path.join(OUTPUT, "tvals", "tvals.npz"), tvals[0])
np.savez(os.path.join(OUTPUT, "log10pvals", "log10pvals.npz"),
         -np.log10(pvals[0]))

create_texture.create_texture_file(OUTPUT=os.path.join(OUTPUT, "pvals"),
                                   TEMPLATE_PATH=TEMPLATE_PATH,
                                   MASK_PATH=MASK_PATH,
                                   beta_path=os.path.join(
                                       OUTPUT, "pvals", "pvals.npz"),
                                   penalty_start=3,
                                   threshold=False)

create_texture.create_texture_file(OUTPUT=os.path.join(OUTPUT, "tvals"),
예제 #2
0
print "ok read"

#############################################################################
## BASIC MULM
DesignMat = np.zeros((Z.shape[0], Z.shape[1] + 1))
DesignMat[:, 0] = (y.ravel() - y.ravel().mean())  # y
DesignMat[:, 1] = 1  # intercept
DesignMat[:, 2] = Z[:, 1]  # age
DesignMat[:, 3] = Z[:, 2]  # gender

contrasts = np.array([[1, 0, 0, 0]])

from mulm import MUOLS
muols = MUOLS(Y=X, X=DesignMat)
muols.fit(block=True)
print "ok fit"
tvals, pvals, dfs = muols.t_test(contrasts=contrasts,
                                 pval=True,
                                 two_tailed=True)
print "ok t_test"
del muols
arr = np.zeros(mask_arr.shape)
arr[mask_arr] = pvals[0]
out_im = nib.Nifti1Image(arr, affine=mask_ima.get_affine())
out_im.to_filename(os.path.join(OUTPUT_UNIVARIATE, "pval_adrs.nii.gz"))

p_log10 = -np.log10(pvals)
arr = np.zeros(mask_arr.shape)
arr[mask_arr] = p_log10[0]
out_im = nib.Nifti1Image(arr, affine=mask_ima.get_affine())
Y = np.random.randn(n, py_info + py_noize)
# Causal model: add X on the first py_info variable
Y[:, :py_info] += np.dot(X, beta)
np.save(f, Y)
del Y

contrasts = np.identity(X.shape[1])

## Read data Y as a memory map
##############################
Y_memmap = np.load(f + '.npy', mmap_mode='r')

# univariate analysis: fit by blocks of 2**26 elements
muols = MUOLS(Y=Y_memmap, X=X)
time1 = time.time()
muols.fit(block=True, max_elements=2 ** 26)
time2 = time.time()
tvals, pvals, dfs = muols.t_test(contrasts=contrasts,
                                 pval=True,
                                 two_tailed=True)
print time2 - time1
del muols

# univariate analysis: fit by blocks of 2**27 elements
muols = MUOLS(Y=Y_memmap, X=X)
time3 = time.time()
muols.fit(block=True, max_elements=2 ** 27)
time4 = time.time()
tvals, pvals, dfs = muols.t_test(contrasts=contrasts,
                                 pval=True,
                                 two_tailed=True)
# Causal model: add X on the first py_info variable
Y[:, :py_info] += np.dot(X, beta)
print("Save matrix to disk")
np.save(f, Y)
del Y

contrasts = np.identity(X.shape[1])

## Read data Y as a memory map
##############################
Y_memmap = np.load(f + '.npy', mmap_mode='r')

# univariate analysis: fit by blocks of 2**27 elements
muols = MUOLS(Y=Y_memmap, X=X)
time3 = time.time()
muols.fit(block=True, max_elements=2**27)
time4 = time.time()
tvals, pvals, dfs = muols.t_test(contrasts=contrasts,
                                 pval=True,
                                 two_tailed=True)
print("Mmap by block(max_elements=2 ** 27): ", time4 - time3)
del muols

# univariate analysis: fit in one go
muols = MUOLS(Y=Y_memmap, X=X)
time5 = time.time()
muols.fit(block=False)
time6 = time.time()
tvals, pvals, dfs = muols.t_test(contrasts=contrasts,
                                 pval=True,
                                 two_tailed=True)