Repository: scipy/scipy
File: scipy/stats/tests/test_mstats_basic.py (Python)

Code before:
             [nan, 6, 11, 4, 17,nan, 6, 1, 1, 2, 5, 1, 1]]
        x = ma.fix_invalid(x)
        result = mstats.friedmanchisquare(*x)
        assert_almost_equal(result[0], 2.0156, 4)
        assert_almost_equal(result[1], 0.5692, 4)

        # test for namedtuple attributes
        attributes = ('statistic', 'pvalue')
        check_named_results(result, attributes, ma=True)

        # copied from `test_stats.py`
        array = np.asarray
        x1 = [array([0.763, 0.599, 0.954, 0.628, 0.882, 0.936, 0.661, 0.583,
                     0.775, 1.0, 0.94, 0.619, 0.972, 0.957]),
              array([0.768, 0.591, 0.971, 0.661, 0.888, 0.931, 0.668, 0.583,
                     0.838, 1.0, 0.962, 0.666, 0.981, 0.978]),
              array([0.771, 0.590, 0.968, 0.654, 0.886, 0.916, 0.609, 0.563,
                     0.866, 1.0, 0.965, 0.614, 0.9751, 0.946]),
              array([0.798, 0.569, 0.967, 0.657, 0.898, 0.931, 0.685, 0.625,
                     0.875, 1.0, 0.962, 0.669, 0.975, 0.970])]

        # From "Bioestadistica para las ciencias de la salud" Xf=18.95 p<0.001:
        x2 = [array([4, 3, 5, 3, 5, 3, 2, 5, 4, 4, 4, 3]),
              array([2, 2, 1, 2, 3, 1, 2, 3, 2, 1, 1, 3]),
              array([2, 4, 3, 3, 4, 3, 3, 4, 4, 1, 2, 1]),
              array([3, 5, 4, 3, 4, 4, 3, 3, 3, 4, 4, 4])]

        # From Jerrorl H. Zar, "Biostatistical Analysis"(example 12.6),
        # Xf=10.68, 0.005 < p < 0.01:
        # Probability from this example is inexact
        # using Chisquare approximation of Friedman Chisquare.
        x3 = [array([7.0, 9.9, 8.5, 5.1, 10.3]),
              array([5.3, 5.7, 4.7, 3.5, 7.7]),
              array([4.9, 7.6, 5.5, 2.8, 8.4]),
              array([8.8, 8.9, 8.1, 3.3, 9.1])]

        # test using mstats
        assert_array_almost_equal(mstats.friedmanchisquare(x1[0], x1[1],
                                                           x1[2], x1[3]),
                                  (10.2283464566929, 0.0167215803284414))
        # the following fails
        # assert_array_almost_equal(mstats.friedmanchisquare(x2[0],x2[1],x2[2],x2[3]),
        #                           (18.9428571428571, 0.000280938375189499))

        assert_array_almost_equal(mstats.friedmanchisquare(x3[0], x3[1],
                                                           x3[2], x3[3]),
                                  (10.68, 0.0135882729582176))
        assert_raises(ValueError, mstats.friedmanchisquare,x3[0],x3[1])


def test_regress_simple():

Review comment (suggestion):
```suggestion
        # x2 = [array([4, 3, 5, 3, 5, 3, 2, 5, 4, 4, 4, 3]),
        #       array([2, 2, 1, 2, 3, 1, 2, 3, 2, 1, 1, 3]),
        #       array([2, 4, 3, 3, 4, 3, 3, 4, 4, 1, 2, 1]),
        #       array([3, 5, 4, 3, 4, 4, 3, 3, 3, 4, 4, 4])]
```

Code after:
             [nan, 6, 11, 4, 17,nan, 6, 1, 1, 2, 5, 1, 1]]
        x = ma.fix_invalid(x)
        result = mstats.friedmanchisquare(*x)
        assert_almost_equal(result[0], 2.0156, 4)
        assert_almost_equal(result[1], 0.5692, 4)

        # test for namedtuple attributes
        attributes = ('statistic', 'pvalue')
        check_named_results(result, attributes, ma=True)

        # copied from `test_stats.py`
        array = np.ma.asarray
        x1 = [array([0.763, 0.599, 0.954, 0.628, 0.882, 0.936, 0.661,
                     0.583, 0.775, 1.0, 0.94, 0.619, 0.972, 0.957]),
              array([0.768, 0.591, 0.971, 0.661, 0.888, 0.931, 0.668,
                     0.583, 0.838, 1.0, 0.962, 0.666, 0.981, 0.978]),
              array([0.771, 0.590, 0.968, 0.654, 0.886, 0.916, 0.609,
                     0.563, 0.866, 1.0, 0.965, 0.614, 0.9751, 0.946]),
              array([0.798, 0.569, 0.967, 0.657, 0.898, 0.931, 0.685,
                     0.625, 0.875, 1.0, 0.962, 0.669, 0.975, 0.970])]

        # From "Bioestadistica para las ciencias de la salud" Xf=18.95 p<0.001:
        # x2 = [array([4, 3, 5, 3, 5, 3, 2, 5, 4, 4, 4, 3]),
        #       array([2, 2, 1, 2, 3, 1, 2, 3, 2, 1, 1, 3]),
        #       array([2, 4, 3, 3, 4, 3, 3, 4, 4, 1, 2, 1]),
        #       array([3, 5, 4, 3, 4, 4, 3, 3, 3, 4, 4, 4])]

        # From Jerrorl H. Zar, "Biostatistical Analysis"(example 12.6),
        # Xf=10.68, 0.005 < p < 0.01:
        # Probability from this example is inexact
        # using Chisquare approximation of Friedman Chisquare.
        x3 = [array([7.0, 9.9, 8.5, 5.1, 10.3]),
              array([5.3, 5.7, 4.7, 3.5, 7.7]),
              array([4.9, 7.6, 5.5, 2.8, 8.4]),
              array([8.8, 8.9, 8.1, 3.3, 9.1])]

        # test using mstats
        assert_array_almost_equal(mstats.friedmanchisquare(*x1),
                                  (10.2283464566929, 0.0167215803284414))

        # the following fails
        # assert_array_almost_equal(mstats.friedmanchisquare(*x2),
        #                           (18.9428571428571, 0.000280938375189499))

        assert_array_almost_equal(mstats.friedmanchisquare(*x3),
                                  (10.68, 0.0135882729582176))
        assert_raises(ValueError, mstats.friedmanchisquare, x3[0], x3[1])


def test_regress_simple():
    # Regress a line with sinusoidal noise. Test for #1273.