def test_xprob_yprob(self): p2 = self.probs + numpy.random.uniform(-1, 1, size=len(self.probs)) scales = {'fitlogs': None, 'fitprobs': 'both'} x, y = self.probs, p2, x_, y_, res = viz.fit_line(x, y, xhat=x[::8], estimate_ci=True, **scales) nptest.assert_allclose(y_, self.known_y_probprob, rtol=0.0001) known_res = { 'slope': 0.98467862838225351, 'intercept': 0.0013327049076583583, 'yhat_lo': numpy.array([ 1.96759603, 24.66922946, 46.88723664, 68.88913508, 91.58436332 ]), 'yhat_hi': numpy.array([ 2.28593917, 25.24921351, 47.60781632, 70.11543855, 92.54803847 ]), } self.check_res(res, known_res)
def test_xlinear_ylog(self): scales = {"fitlogs": "y", "fitprobs": None} x, y = self.zscores, self.data x_, y_, res = viz.fit_line(x, y, xhat=x[::8], estimate_ci=True, **scales) nptest.assert_allclose(y_, self.known_y_linlog, rtol=0.0001) known_res = { "slope": 0.55515014824534514, "intercept": 2.1749556618678434, "yhat_lo": numpy.array([2.4355, 5.6436, 8.1653, 11.3136, 18.1000]), "yhat_hi": numpy.array([3.1348, 6.3072, 8.7495, 12.2324, 21.2824]), } self.check_res(res, known_res)
def test_xlinear_ylinear(self): scales = {"fitlogs": None, "fitprobs": None} x, y = self.zscores, self.data x_, y_, res = viz.fit_line(x, y, xhat=x[::8], estimate_ci=True, **scales) nptest.assert_allclose(y_, self.known_y_linlin, rtol=0.0001) known_res = { "slope": 5.3404377026700995, "intercept": 10.114857142857147, "yhat_lo": numpy.array([-2.9223, 5.4807, 9.1090, 12.0198, 16.2376]), "yhat_hi": numpy.array([0.4983, 7.0448, 10.2715, 13.4877, 18.8306]), } self.check_res(res, known_res)
def test_xlinear_yprob(self): scales = {"fitlogs": None, "fitprobs": "y"} x, y = self.data, self.probs x_, y_, res = viz.fit_line(x, y, xhat=x[::8], estimate_ci=True, **scales) nptest.assert_allclose(y_, self.known_y_linprob, rtol=0.0001) known_res = { "slope": 0.16920340891421964, "intercept": -1.7114683092517717, "yhat_lo": numpy.array([5.6382, 18.9842, 36.0326, 54.0282, 92.8391]), "yhat_hi": numpy.array([12.6284, 28.2687, 44.6934, 61.8816, 97.1297]), } self.check_res(res, known_res)
def test_xlinear_ylinear(self): scales = {'fitlogs': None, 'fitprobs': None} x, y = self.zscores, self.data x_, y_, res = viz.fit_line(x, y, xhat=x[::8], estimate_ci=True, **scales) nptest.assert_allclose(y_, self.known_y_linlin, rtol=0.0001) known_res = { 'slope': 5.3404377026700995, 'intercept': 10.114857142857147, 'yhat_lo': numpy.array([ -2.9223, 5.4807, 9.109 , 12.0198, 16.2376]), 'yhat_hi': numpy.array([ 0.4983, 7.0448, 10.2715, 13.4877, 18.8306]), } self.check_res(res, known_res)
def test_xlog_ylog(self): scales = {'fitlogs': 'both', 'fitprobs': None} x, y = self.data, self.y x_, y_, res = viz.fit_line(x, y, xhat=x[::8], estimate_ci=True, **scales) nptest.assert_allclose(y_, self.known_y_loglog, rtol=0.0001) known_res = { 'slope': 1.9695339470891058, 'intercept': -4.4267200322534261, 'yhat_lo': numpy.array([ 0.033559, 0.32797 , 0.777473, 1.331504, 3.811647]), 'yhat_hi': numpy.array([ 0.061867, 0.422956, 0.892383, 1.48953 , 4.842235]), } self.check_res(res, known_res)
def test_xlog_yprob(self): scales = {'fitlogs': 'x', 'fitprobs': 'y'} x, y = self.data, self.probs x_, y_, res = viz.fit_line(x, y, xhat=x[::8], estimate_ci=True, **scales) nptest.assert_allclose(y_, self.known_y_logprob, rtol=0.0001) known_res = { 'slope': 1.7385543724819046, 'intercept': -3.7812786758946113, 'yhat_lo': numpy.array([0.187555, 19.859832, 46.267537, 64.085292, 89.551801]), 'yhat_hi': numpy.array([1.030230, 26.174702, 50.963065, 68.949137, 94.089655]), } self.check_res(res, known_res)
def test_xlog_ylog(self): scales = {"fitlogs": "both", "fitprobs": None} x, y = self.data, self.y x_, y_, res = viz.fit_line(x, y, xhat=x[::8], estimate_ci=True, **scales) nptest.assert_allclose(y_, self.known_y_loglog, rtol=0.0001) known_res = { "slope": 1.9695339470891058, "intercept": -4.4267200322534261, "yhat_lo": numpy.array([0.033559, 0.327970, 0.777473, 1.331504, 3.811647]), "yhat_hi": numpy.array([0.061867, 0.422956, 0.892383, 1.489530, 4.842235]), } self.check_res(res, known_res)
def test_xlog_ylinear(self): scales = {'fitlogs': 'x', 'fitprobs': None} x, y = self.data, self.zscores x_, y_, res = viz.fit_line(x, y, xhat=x[::8], estimate_ci=True, **scales) nptest.assert_allclose(y_, self.known_y_loglin, rtol=0.0001) known_res = { 'slope': 1.7385543724819053, 'intercept': -3.7812786758946122, 'yhat_lo': numpy.array([-2.88948 , -0.846565, -0.093696, 0.360738, 1.255963]), 'yhat_hi': numpy.array([-2.310246, -0.63795 , 0.024143, 0.494404, 1.561183]), } self.check_res(res, known_res)
def test_xprob_ylinear(self): scales = {'fitlogs': None, 'fitprobs': 'x'} x, y = self.probs, self.data x_, y_, res = viz.fit_line(x, y, xhat=x[::8], estimate_ci=True, **scales) nptest.assert_allclose(y_, self.known_y_problin, rtol=0.0001) known_res = { 'slope': 5.3404377026700995, 'intercept': 10.114857142857147, 'yhat_lo': numpy.array([-2.92233134, 5.48065673, 9.1090198 , 12.01977856, 16.23762957]), 'yhat_hi': numpy.array([ 0.49826723, 7.04480065, 10.27146083, 13.48770383, 18.83061329]), } self.check_res(res, known_res)
def test_xlinear_ylog(self): scales = {'fitlogs': 'y', 'fitprobs': None} x, y = self.zscores, self.data x_, y_, res = viz.fit_line(x, y, xhat=x[::8], estimate_ci=True, **scales) nptest.assert_allclose(y_, self.known_y_linlog, rtol=0.0001) known_res = { 'slope': 0.55515014824534514, 'intercept': 2.1749556618678434, 'yhat_lo': numpy.array([ 2.4355, 5.6436, 8.1653, 11.3136, 18.1000]), 'yhat_hi': numpy.array([ 3.1348, 6.3072, 8.7495, 12.2324, 21.2824]), } self.check_res(res, known_res)
def test_xprob_ylog(self): scales = {'fitlogs': 'y', 'fitprobs': 'x'} x, y = self.probs, self.data x_, y_, res = viz.fit_line(x, y, xhat=x[::8], estimate_ci=True, **scales) nptest.assert_allclose(y_, self.known_y_problog, rtol=0.0001) known_res = { 'intercept': 2.1749556618678434, 'slope': 0.55515014824534525, 'yhat_lo': numpy.array([2.43550106, 5.6436203 , 8.16525601, 11.31358231, 18.09998664]), 'yhat_hi': numpy.array([3.13484803, 6.30722509, 8.74945323, 12.23244498, 21.28240831]), } self.check_res(res, known_res)
def test_xlinear_yprob(self): scales = {'fitlogs': None, 'fitprobs': 'y'} x, y = self.data, self.probs x_, y_, res = viz.fit_line(x, y, xhat=x[::8], estimate_ci=True, **scales) nptest.assert_allclose(y_, self.known_y_linprob, rtol=0.0001) known_res = { 'slope': 0.16920340891421964, 'intercept': -1.7114683092517717, 'yhat_lo': numpy.array([ 5.6382, 18.9842, 36.0326, 54.0282, 92.8391]), 'yhat_hi': numpy.array([ 12.6284, 28.2687, 44.6934, 61.8816, 97.1297]), } self.check_res(res, known_res)
def test_xlinear_ylinear_no_ci(self): known_y_linlin_no_ci = numpy.array( [ -0.89650596, 1.20256093, 2.45912768, 3.39459245, 4.15976331, 4.81895346, 5.40596572, 5.94094748, 6.43698357, 6.90313142, 7.34598503, 7.77055185, 8.18077912, 8.57988686, 8.97059045, 9.35525614, 9.73601589, 10.11485714, 10.49369839, 10.87445814, 11.25912384, 11.64982743, 12.04893516, 12.45916243, 12.88372926, 13.32658287, 13.79273071, 14.28876680, 14.82374857, 15.41076083, 16.06995097, 16.83512184, 17.77058661, 19.02715336, 21.12622025, ] ) scales = {"fitlogs": None, "fitprobs": None} x, y = self.zscores, self.data x_, y_, res = viz.fit_line(x, y, **scales) nptest.assert_array_almost_equal(y_, known_y_linlin_no_ci) known_res = { "slope": 5.3404377026700995, "intercept": 10.114857142857147, "yhat_lo": None, "yhat_hi": None, } self.check_res(res, known_res)
def test_xprob_yprob(self): p2 = self.probs + numpy.random.uniform(-1, 1, size=len(self.probs)) scales = {'fitlogs': None, 'fitprobs': 'both'} x, y = self.probs, p2, x_, y_, res = viz.fit_line(x, y, xhat=x[::8], estimate_ci=True, **scales) nptest.assert_allclose(y_, self.known_y_probprob, rtol=0.0001) known_res = { 'slope': 0.98467862838225351, 'intercept': 0.0013327049076583583, 'yhat_lo': numpy.array([1.96759603, 24.66922946, 46.88723664, 68.88913508, 91.58436332]), 'yhat_hi': numpy.array([2.28593917, 25.24921351, 47.60781632, 70.11543855, 92.54803847]), } self.check_res(res, known_res)
def test_xprob_ylog(self): scales = {"fitlogs": "y", "fitprobs": "x"} x, y = self.probs, self.data x_, y_, res = viz.fit_line(x, y, xhat=x[::8], estimate_ci=True, **scales) nptest.assert_allclose(y_, self.known_y_problog, rtol=0.0001) known_res = { "intercept": 2.1749556618678434, "slope": 0.55515014824534525, "yhat_lo": numpy.array( [2.43550106, 5.64362030, 8.16525601, 11.31358231, 18.09998664] ), "yhat_hi": numpy.array( [3.13484803, 6.30722509, 8.74945323, 12.23244498, 21.28240831] ), } self.check_res(res, known_res)
def test_xprob_ylinear(self): scales = {"fitlogs": None, "fitprobs": "x"} x, y = self.probs, self.data x_, y_, res = viz.fit_line(x, y, xhat=x[::8], estimate_ci=True, **scales) nptest.assert_allclose(y_, self.known_y_problin, rtol=0.0001) known_res = { "slope": 5.3404377026700995, "intercept": 10.114857142857147, "yhat_lo": numpy.array( [-2.92233134, 5.48065673, 9.10901980, 12.01977856, 16.23762957] ), "yhat_hi": numpy.array( [0.49826723, 7.04480065, 10.27146083, 13.48770383, 18.83061329] ), } self.check_res(res, known_res)
def test_xlog_yprob(self): scales = {"fitlogs": "x", "fitprobs": "y"} x, y = self.data, self.probs x_, y_, res = viz.fit_line(x, y, xhat=x[::8], estimate_ci=True, **scales) nptest.assert_allclose(y_, self.known_y_logprob, rtol=0.0001) known_res = { "slope": 1.7385543724819046, "intercept": -3.7812786758946113, "yhat_lo": numpy.array( [0.187555, 19.859832, 46.267537, 64.085292, 89.551801] ), "yhat_hi": numpy.array( [1.030230, 26.174702, 50.963065, 68.949137, 94.089655] ), } self.check_res(res, known_res)
def test_xlog_ylinear(self): scales = {"fitlogs": "x", "fitprobs": None} x, y = self.data, self.zscores x_, y_, res = viz.fit_line(x, y, xhat=x[::8], estimate_ci=True, **scales) nptest.assert_allclose(y_, self.known_y_loglin, rtol=0.0001) known_res = { "slope": 1.7385543724819053, "intercept": -3.7812786758946122, "yhat_lo": numpy.array( [-2.889480, -0.846565, -0.093696, 0.360738, 1.255963] ), "yhat_hi": numpy.array( [-2.310246, -0.637950, 0.024143, 0.494404, 1.561183] ), } self.check_res(res, known_res)
def test_xlinear_ylinear_no_ci(self): known_y_linlin_no_ci = numpy.array([ -0.89650596, 1.20256093, 2.45912768, 3.39459245, 4.15976331, 4.81895346, 5.40596572, 5.94094748, 6.43698357, 6.90313142, 7.34598503, 7.77055185, 8.18077912, 8.57988686, 8.97059045, 9.35525614, 9.73601589, 10.11485714, 10.49369839, 10.87445814, 11.25912384, 11.64982743, 12.04893516, 12.45916243, 12.88372926, 13.32658287, 13.79273071, 14.2887668 , 14.82374857, 15.41076083, 16.06995097, 16.83512184, 17.77058661, 19.02715336, 21.12622025 ]) scales = {'fitlogs': None, 'fitprobs': None} x, y = self.zscores, self.data x_, y_, res = viz.fit_line(x, y, **scales) nptest.assert_array_almost_equal(y_, known_y_linlin_no_ci) known_res = { 'slope': 5.3404377026700995, 'intercept': 10.114857142857147, 'yhat_lo': None, 'yhat_hi': None, } self.check_res(res, known_res)
def test_custom_xhat(self): x, y = self.zscores, self.data x_, y_, res = viz.fit_line(x, y, xhat=self.custom_xhat) nptest.assert_array_almost_equal(y_, self.known_custom_yhat)
def test_bad_fitprobs(self): with pytest.raises(ValueError): x, y = self.zscores, self.data x_, y_, res = viz.fit_line(x, y, fitprobs="junk")
def test_bad_fitprobs(self): with pytest.raises(ValueError): x, y = self.zscores, self.data x_, y_, res = viz.fit_line(x, y, fitprobs='junk')