Open kingjr opened 5 years ago
@qasfb
import numpy as np import matplotlib.pyplot as plt from scipy.stats import norm, ttest_1samp %matplotlib inline # Fake data for clarity n_times = 200 time = np.linspace(-.100, 1., n_times) word_length = norm.pdf(time, .150, .05) word_freq = norm.pdf(time, .400, .15) * 3 E = list() for subject in range(102): length = word_length + np.random.randn(n_times) freq = word_freq + np.random.randn(n_times) plt.plot(time, length, color='C0', lw=.1) plt.plot(time, freq, color='C1', lw=.1) E.append([length, freq]) E = np.array(E) plt.plot(time, np.mean(E, 0)[0], color='C0') plt.plot(time, np.mean(E, 0)[1], color='C1') # example stat baseline = 0 t150 = 40 t400 = 60 length, freq = 0, 1 for t in (0., .150, .400): t_idx = np.where(time>=t)[0][0] mean_length = E[:, length, t_idx].mean(0) std_length = E[:, length, t_idx].std(0) mean_freq = E[:, freq, t_idx].mean(0) std_freq = E[:, freq, t_idx].std(0) tval, pval = ttest_1samp(E[:, length, t_idx] - E[:, freq, t_idx], 0) print('at %.3f ms, word freq (mean=%.3f +/- %.3f) != word length (mean=%.3f +/- %.3f): t=%.2f p=%.5f' % ( t, mean_length, std_length, mean_freq, std_freq, tval, pval))
@qasfb