def test_center(): data = np.random.rand(1000) * 2 * np.pi try: assert_allclose(pycircstat.mean(pycircstat.center(data)), 0, rtol=1e-3, atol=1e-3) except: assert_allclose(pycircstat.mean(pycircstat.center(data)), 2 * np.pi, rtol=1e-3, atol=1e-3)
def corr_circular_(alpha1, alpha2): axis = None from pycircstat import center from scipy.stats import norm alpha1_bar, alpha2_bar = center(alpha1, alpha2, axis=axis) num = np.sum(np.sin(alpha1_bar) * np.sin(alpha2_bar), axis=axis) den = np.sqrt( np.sum(np.sin(alpha1_bar)**2, axis=axis) * np.sum(np.sin(alpha2_bar)**2, axis=axis)) rho = num / den # pvalue l20 = np.mean(np.sin(alpha1 - alpha1_bar)**2) l02 = np.mean(np.sin(alpha2 - alpha2_bar)**2) l22 = np.mean( (np.sin(alpha1 - alpha1_bar)**2) * (np.sin(alpha2 - alpha2_bar)**2)) ts = np.sqrt((float(len(alpha1)) * l20 * l02) / l22) * rho pval = 2.0 * (1.0 - norm.cdf(np.abs(ts))) return rho, pval
def center(x): x['phase'] = circ.center(x.phase) return x