Пример #1
0
def ttest(x):
    """
    returns the t-test for each row of the data x
    """
    import nipy.neurospin.group.onesample as fos
    t = fos.stat(x.T,id='student',axis=0)
    return np.squeeze(t)
def compare_with_nipy():
    """
    Check whether we obtain the same results as nipy
    """
    import nipy.neurospin.group.onesample as fos
    nsamples = 15
    ndata = 1000
    
    vardata = np.random.rand(ndata,nsamples)
    data = np.zeros((ndata, nsamples))
    for i in range(ndata):
        data[i] = generate_data(0, 1, vardata[i])
        
    # my computation
    t1 =  t_stat(data)
    t2 =  mfx_t_stat(data,vardata)

    #nipy model
    t3 = fos.stat(data, id='student', axis=1)
    t4 = np.squeeze(fos.stat_mfx(data, vardata, id='student_mfx', axis=1))
    diff = t4-t2
    maxdiff = (diff**2).max()
    if maxdiff>1:
	i = np.abs(diff).argmax()
	print t1[i], t2[i], t4[i]
	print mfx_t_stat(np.array([data[i]]),np.array([vardata[i]]), niter=20)
    print ((t1-t2)**2).sum(), ((t1-t4)**2).sum() 
Пример #3
0
def test_onesample_stat():
    dx, dy, dz = 3, 4, 2
    nvox = dx*dy*dz
    nsub = 12
    # Make surrogate data 
    aux = np.arange(nvox)
    x = np.reshape(aux.repeat(nsub), [dx, dy, dz, nsub])
    # Gold standard 
    y_target = np.inf * np.ones(nvox)
    y_target[0] = 0.0
    # Test: input C-contiguous, data owner, axis=3
    y = onesample.stat(x, axis=3).reshape(nvox)
    assert_equal(y, y_target)
    # Test: input F-contiguous, not owner, axis=0 
    y = onesample.stat(x.T, axis=0).reshape(nvox)
    assert_equal(y, y_target)
    # Test: input C-contiguous, data owner, axis=0
    xT = x.T.copy()
    y = onesample.stat(xT, axis=0).reshape(nvox)
    assert_equal(y, y_target)