<commit_before>from numpy.testing import assert_, assert_raises
from scipy import stats
import nose
from statsmodels.stats._lilliefors import lilliefors
import numpy as np

class TestLilliefors(object):

    def test_normal(self):
        np.random.seed(3975)
        x_n = stats.norm.rvs(size=500)
        d_ks, p = lilliefors(x_n, dist='norm')
        assert_(p > 0.05)

    def test_expon(self):
        np.random.seed(3975)
        x_e = stats.expon.rvs(size=500)
        d_ks, p = lilliefors(x_e, dist='exp')
        assert_(p > 0.05)

    def test_pval_bounds(self):
        x = np.arange(1,10)
        d_ks_n, p_n = lilliefors(x, dist='norm')
        d_ks_e, p_e = lilliefors(x, dist='exp')
        assert_(p_n < 1)
        assert_(p_e < 1)<commit_msg>tests ref. R Lilliefors implementations<commit_after>'''
Test Lilliefors corrected K-S tests for normality and exponential distributions

Reference values from R packages:
    `nortest` (lillie.test)
    `KScorrect` (LcKS)

Note : p-values rounded to within the bounds of the Lilliefors tables.
        R implementation provides more precise p-values with a Monte Carlo
        simulation.

<NAME>
2 August 2017
'''

from numpy.testing import assert_, assert_raises, assert_almost_equal
from scipy import stats
import nose
from statsmodels.stats._lilliefors import lilliefors
import numpy as np

class TestLilliefors(object):

    def test_normal(self):
        np.random.seed(3975)
        x_n = stats.norm.rvs(size=500)
        d_ks_norm, p_norm = lilliefors(x_n, dist='norm')
        # shift normal distribution > 0 to exactly mirror R `KScorrect` test
        # R `KScorrect` requires all values tested for exponential
        # distribution to be > 0
        d_ks_exp, p_exp = lilliefors(x_n+np.abs(x_n.min()) + 0.001, dist='exp')
        # assert normal
        assert_almost_equal(d_ks_norm, 0.025957, decimal=3)
        assert_almost_equal(p_norm, 0.2000, decimal=3)
        # assert exp
        assert_almost_equal(d_ks_exp, 0.3436007, decimal=3)
        assert_almost_equal(p_exp, 0.01, decimal=3)


    def test_expon(self):
        np.random.seed(3975)
        x_e = stats.expon.rvs(size=500)
        d_ks_norm, p_norm = lilliefors(x_e, dist='norm')
        d_ks_exp, p_exp = lilliefors(x_e, dist='exp')
        # assert normal
        assert_almost_equal(d_ks_norm, 0.15581, decimal=3)
        assert_almost_equal(p_norm, 2.2e-16, decimal=3)
        # assert exp
        assert_almost_equal(d_ks_exp, 0.02763748, decimal=3)
        assert_almost_equal(p_exp, 0.200, decimal=3)

    def test_pval_bounds(self):
        x = np.arange(1,10)
        d_ks_n, p_n = lilliefors(x, dist='norm')
        d_ks_e, p_e = lilliefors(x, dist='exp')
        assert_almost_equal(p_n, 0.200, decimal=7)
        assert_almost_equal(p_e, 0.200, decimal=7)
{'fraction_non_alphanumeric': 0.10363247863247864, 'fraction_numerical': 0.041666666666666664, 'mean_word_length': 3.03012912482066, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '662983', 'n_tokens_mistral': 1103, 'n_tokens_neox': 1011, 'n_words': 229}