def test_surrogate_analysis_fdr(): rng = np.random.RandomState(0) data = np.load("../examples/data/eeg_32chans_10secs.npy") ts1 = data[0, 0:512].ravel() ts2 = data[1, 0:512].ravel() p_val, surr_vals, surrogates, r_value = surrogate_analysis( ts1, ts2, num_surr=1000, estimator_func=None, ts1_no_surr=False, rng=rng) num_ts = 2 num_pvals = num_ts * (num_ts - 1) / 2.0 num_pvals = np.int32(num_pvals) p_vals = np.ones([num_pvals, 1]) * p_val h, crit_p = fdr(p_vals, 0.01, 'pdep') expected_result = np.load("data/test_ts_surrogates_fdr_h.npy") assert h == expected_result expected_result = np.load("data/test_ts_surrogates_fdr_crit_p.npy") assert crit_p == expected_result
def test_surrogate_analysis(): rng = np.random.RandomState(0) data = np.load("../examples/data/eeg_32chans_10secs.npy") ts1 = data[0, 0:512].ravel() ts2 = data[1, 0:512].ravel() p_vals, surr_vals, surrogates, r_value = surrogate_analysis( ts1, ts2, num_surr=1000, estimator_func=None, ts1_no_surr=False, rng=rng) expected_result = np.load("data/test_ts_surrogates.npy").squeeze() np.testing.assert_array_equal(surrogates, expected_result) expected_result = np.load("data/test_ts_surrogates_p_val.npy").squeeze() assert p_vals == expected_result np.save("/tmp/out.npy", surr_vals) expected_result = np.load("data/test_ts_surrogates_corr.npy").squeeze() np.testing.assert_array_almost_equal(surr_vals, expected_result)
def test_surrogate_analysis2(): rng = np.random.RandomState(0) data = np.load("../examples/data/eeg_32chans_10secs.npy") ts1 = data[0, 0:512].ravel() ts2 = data[1, 0:512].ravel() p_val, surr_vals, surrogates, r_value = surrogate_analysis( ts1, ts2, num_surr=1000, ts1_no_surr=True, rng=rng) expected_result = np.load("data/test_ts_surrogates2.npy") np.testing.assert_array_equal(surrogates, expected_result) expected_result = np.load("data/test_ts_surrogates2_p_val.npy") assert p_val == expected_result
def test_surrogate_analysis2_fdr(): rng = np.random.RandomState(0) data = np.load("../examples/data/eeg_32chans_10secs.npy") ts1 = data[0, 0:512].ravel() ts2 = data[1, 0:512].ravel() p_val, surr_vals, surrogates, r_value = surrogate_analysis( ts1, ts2, num_surr=1000, ts1_no_surr=True, rng=rng) num_ts = 2 p_vals = np.ones([num_ts * (num_ts - 1) / 2, 1]) * p_val h, crit_p = fdr(p_vals, 0.01, 'pdep') expected_result = np.load("data/test_ts_surrogates2_fdr_h.npy") assert h == expected_result
# -*- coding: utf-8 -*- import numpy as np np.set_printoptions(precision=3, linewidth=256) from dyfunconn.ts import fdr, surrogate_analysis if __name__ == "__main__": rng = np.random.RandomState(0) data = np.load( "/home/makism/Github/dyfunconn/examples/data/eeg_32chans_10secs.npy") ts1 = data[0, :].ravel() ts2 = data[1, :].ravel() p_val, corr_surr, surrogates, r_value = surrogate_analysis( ts1, ts2, num_surr=1000, ts1_no_surr=True, rng=rng) num_ts = 2 p_vals = np.ones([num_ts * (num_ts - 1) / 2, 1]) * p_val q = 0.01 method = 'pdep' h, crit_p = fdr(p_vals, q, method) print("p-value: {0}, h: {1} (critical p-value: {2})".format( p_val, h, crit_p))