def test_2d_wo_missing(self): # Test corrcoef on 1 2D variable w/o missing values x = self.data.reshape(3, 4) assert_almost_equal(np.corrcoef(x), corrcoef(x)) assert_almost_equal(np.corrcoef(x, rowvar=False), corrcoef(x, rowvar=False)) with catch_warn_mae(): warnings.simplefilter("ignore") assert_almost_equal(np.corrcoef(x, rowvar=False, bias=True), corrcoef(x, rowvar=False, bias=True))
def test_1d_wo_missing(self): # Test cov on 1D variable w/o missing values x = self.data assert_almost_equal(np.corrcoef(x), corrcoef(x)) assert_almost_equal(np.corrcoef(x, rowvar=False), corrcoef(x, rowvar=False)) assert_almost_equal(np.corrcoef(x, rowvar=False, bias=True), corrcoef(x, rowvar=False, bias=True))
def test_2d_wo_missing(self): # Test corrcoef on 1 2D variable w/o missing values x = self.data.reshape(3, 4) assert_almost_equal(np.corrcoef(x), corrcoef(x)) assert_almost_equal(np.corrcoef(x, rowvar=False), corrcoef(x, rowvar=False)) assert_almost_equal(np.corrcoef(x, rowvar=False, bias=True), corrcoef(x, rowvar=False, bias=True))
def test_1d_w_missing(self): # Test corrcoef 1 1D variable w/missing values x = self.data x[-1] = masked x -= x.mean() nx = x.compressed() assert_almost_equal(np.corrcoef(nx), corrcoef(x)) assert_almost_equal(np.corrcoef(nx, rowvar=False), corrcoef(x, rowvar=False)) with catch_warn_mae(): warnings.simplefilter("ignore") assert_almost_equal(np.corrcoef(nx, rowvar=False, bias=True), corrcoef(x, rowvar=False, bias=True)) try: corrcoef(x, allow_masked=False) except ValueError: pass # 2 1D variables w/ missing values nx = x[1:-1] assert_almost_equal(np.corrcoef(nx, nx[::-1]), corrcoef(x, x[::-1])) assert_almost_equal(np.corrcoef(nx, nx[::-1], rowvar=False), corrcoef(x, x[::-1], rowvar=False)) with catch_warn_mae(): warnings.simplefilter("ignore") # ddof and bias have no or negligible effect on the function assert_almost_equal(np.corrcoef(nx, nx[::-1]), corrcoef(x, x[::-1], bias=1)) assert_almost_equal(np.corrcoef(nx, nx[::-1]), corrcoef(x, x[::-1], ddof=2))
def test_ddof(self): # ddof raises DeprecationWarning x, y = self.data, self.data2 expected = np.corrcoef(x) expected2 = np.corrcoef(x, y) with catch_warn_mae(): warnings.simplefilter("always") assert_warns(DeprecationWarning, corrcoef, x, ddof=-1) warnings.simplefilter("ignore") # ddof has no or negligible effect on the function assert_almost_equal(np.corrcoef(x, ddof=0), corrcoef(x, ddof=0)) assert_almost_equal(corrcoef(x, ddof=-1), expected) assert_almost_equal(corrcoef(x, y, ddof=-1), expected2) assert_almost_equal(corrcoef(x, ddof=3), expected) assert_almost_equal(corrcoef(x, y, ddof=3), expected2)
def test_2d_w_missing(self): # Test corrcoef on 2D variable w/ missing value x = self.data x[-1] = masked x = x.reshape(3, 4) test = corrcoef(x) control = np.corrcoef(x) assert_almost_equal(test[:-1, :-1], control[:-1, :-1]) with catch_warn_mae(): warnings.simplefilter("ignore") # ddof and bias have no or negligible effect on the function assert_almost_equal(corrcoef(x, ddof=-2)[:-1, :-1], control[:-1, :-1]) assert_almost_equal(corrcoef(x, ddof=3)[:-1, :-1], control[:-1, :-1]) assert_almost_equal(corrcoef(x, bias=1)[:-1, :-1], control[:-1, :-1])
def test_2d_with_missing(self): # Test corrcoef on 2D variable w/ missing value x = self.data x[-1] = masked x = x.reshape(3, 4) test = corrcoef(x) control = np.corrcoef(x) assert_almost_equal(test[:-1, :-1], control[:-1, :-1]) with suppress_warnings() as sup: sup.filter(DeprecationWarning, "bias and ddof have no effect") # ddof and bias have no or negligible effect on the function assert_almost_equal( corrcoef(x, ddof=-2)[:-1, :-1], control[:-1, :-1]) assert_almost_equal( corrcoef(x, ddof=3)[:-1, :-1], control[:-1, :-1]) assert_almost_equal( corrcoef(x, bias=1)[:-1, :-1], control[:-1, :-1])
def test_2d_w_missing(self): # Test corrcoef on 2D variable w/ missing value x = self.data x[-1] = masked x = x.reshape(3, 4) test = corrcoef(x) control = np.corrcoef(x) assert_almost_equal(test[:-1, :-1], control[:-1, :-1]) with catch_warn_mae(): warnings.simplefilter("ignore") # ddof and bias have no or negligible effect on the function assert_almost_equal( corrcoef(x, ddof=-2)[:-1, :-1], control[:-1, :-1]) assert_almost_equal( corrcoef(x, ddof=3)[:-1, :-1], control[:-1, :-1]) assert_almost_equal( corrcoef(x, bias=1)[:-1, :-1], control[:-1, :-1])
def test_2d_w_missing(self): # Test corrcoef on 2D variable w/ missing value x = self.data x[-1] = masked x = x.reshape(3, 4) test = corrcoef(x) control = np.corrcoef(x) assert_almost_equal(test[:-1, :-1], control[:-1, :-1])
def test_bias(self): x, y = self.data, self.data2 expected = np.corrcoef(x) # bias raises DeprecationWarning with catch_warn_mae(): warnings.simplefilter("always") assert_warns(DeprecationWarning, corrcoef, x, y, True, False) assert_warns(DeprecationWarning, corrcoef, x, y, True, True) assert_warns(DeprecationWarning, corrcoef, x, bias=False) warnings.simplefilter("ignore") # bias has no or negligible effect on the function assert_almost_equal(corrcoef(x, bias=1), expected)
def test_bias(self): x, y = self.data, self.data2 expected = np.corrcoef(x) # bias raises DeprecationWarning with suppress_warnings() as sup: warnings.simplefilter("always") assert_warns(DeprecationWarning, corrcoef, x, y, True, False) assert_warns(DeprecationWarning, corrcoef, x, y, True, True) assert_warns(DeprecationWarning, corrcoef, x, bias=False) sup.filter(DeprecationWarning, "bias and ddof have no effect") # bias has no or negligible effect on the function assert_almost_equal(corrcoef(x, bias=1), expected)
def G_reg1d(xx, yy, ww=None): """ description needed ww: weights """ rtn = [] ab = polyfit(xx, yy, 1, w=ww) rtn.append(ab[0]) rtn.append(ab[1]) rtn.append(std(yy) / std(xx)) rtn.append(mean(yy) - rtn[2] * mean(xx)) r = corrcoef(xx, yy) rr = r[0, 1] * r[0, 1] rtn.append(rr) return rtn
def G_reg1d(xx, yy, ww=None): ''' 计算斜率和截距 ww: weights ''' rtn = [] ab = polyfit(xx, yy, 1, w=ww) rtn.append(ab[0]) rtn.append(ab[1]) rtn.append(std(yy) / std(xx)) rtn.append(mean(yy) - rtn[2] * mean(xx)) r = corrcoef(xx, yy) rr = r[0, 1] * r[0, 1] rtn.append(rr) return rtn
def test_1d_w_missing(self): "Test corrcoef 1 1D variable w/missing values" x = self.data x[-1] = masked x -= x.mean() nx = x.compressed() assert_almost_equal(np.corrcoef(nx), corrcoef(x)) assert_almost_equal(np.corrcoef(nx, rowvar=False), corrcoef(x, rowvar=False)) assert_almost_equal(np.corrcoef(nx, rowvar=False, bias=True), corrcoef(x, rowvar=False, bias=True)) # try: corrcoef(x, allow_masked=False) except ValueError: pass # # 2 1D variables w/ missing values nx = x[1:-1] assert_almost_equal(np.corrcoef(nx, nx[::-1]), corrcoef(x, x[::-1])) assert_almost_equal(np.corrcoef(nx, nx[::-1], rowvar=False), corrcoef(x, x[::-1], rowvar=False)) assert_almost_equal(np.corrcoef(nx, nx[::-1], rowvar=False, bias=True), corrcoef(x, x[::-1], rowvar=False, bias=True))
def test_1d_w_missing(self): # Test corrcoef 1 1D variable w/missing values x = self.data x[-1] = masked x -= x.mean() nx = x.compressed() assert_almost_equal(np.corrcoef(nx), corrcoef(x)) assert_almost_equal(np.corrcoef(nx, rowvar=False), corrcoef(x, rowvar=False)) assert_almost_equal(np.corrcoef(nx, rowvar=False, bias=True), corrcoef(x, rowvar=False, bias=True)) # try: corrcoef(x, allow_masked=False) except ValueError: pass # # 2 1D variables w/ missing values nx = x[1:-1] assert_almost_equal(np.corrcoef(nx, nx[::-1]), corrcoef(x, x[::-1])) assert_almost_equal(np.corrcoef(nx, nx[::-1], rowvar=False), corrcoef(x, x[::-1], rowvar=False)) assert_almost_equal(np.corrcoef(nx, nx[::-1], rowvar=False, bias=True), corrcoef(x, x[::-1], rowvar=False, bias=True))
def test_ddof(self): "Test ddof keyword" x = self.data assert_almost_equal(np.corrcoef(x, ddof=0), corrcoef(x, ddof=0))
def test_ddof(self): # Test ddof keyword x = self.data assert_almost_equal(np.corrcoef(x, ddof=0), corrcoef(x, ddof=0))