Github user sryza commented on a diff in the pull request:

    https://github.com/apache/spark/pull/7278#discussion_r34196274
  
    --- Diff: 
mllib/src/test/scala/org/apache/spark/mllib/stat/HypothesisTestSuite.scala ---
    @@ -153,4 +153,166 @@ class HypothesisTestSuite extends SparkFunSuite with 
MLlibTestSparkContext {
           Statistics.chiSqTest(sc.parallelize(continuousFeature, 2))
         }
       }
    +
    +  test("Anderson-Darling test for 1 sample") {
    +    /*
    +      Data generated with R
    +      > sessionInfo() #truncated
    +        R version 3.2.0 (2015-04-16)
    +        Platform: x86_64-apple-darwin13.4.0 (64-bit)
    +        Running under: OS X 10.10.2 (Yosemite)
    +      > set.seed(10)
    +      > dataNorm <- rnorm(20)
    +      > dataExp <- rexp(20)
    +      > dataUnif <- runif(20)
    +      > mean(dataNorm)
    +      [1] -0.06053267
    +      > sd(dataNorm)
    +      [1] 0.7999093
    +      > mean(dataExp)
    +      [1] 1.044636
    +      > sd(dataExp)
    +      [1] 0.96727
    +      > mean(dataUnif)
    +      [1] 0.4420219
    +      > sd(dataUnif)
    +      [1] 0.2593285
    +     */
    +
    +    val dataNorm = sc.parallelize(
    +      Array(0.0187461709418264, -0.184252542069064, -1.37133054992251,
    +      -0.599167715783718, 0.294545126567508, 0.389794300700167, 
-1.20807617542949,
    +      -0.363676017470862, -1.62667268170309, -0.256478394123992, 
1.10177950308713,
    +      0.755781508027337, -0.238233556018718, 0.98744470341339, 
0.741390128383824,
    +      0.0893472664958216, -0.954943856152377, -0.195150384667239, 
0.92552126209408,
    +      0.482978524836611)
    +    )
    +    val dataExp = sc.parallelize(
    +      Array(0.795082630547595, 1.39629918233218, 1.39810742601556, 
1.11045944034578,
    +        0.170421596598791, 1.91878133072498, 0.166443939786404, 
0.97028998914142, 0.010571192484349,
    +        2.79300971312409, 2.35461177957702, 0.667238388210535, 
0.522243486717343, 0.146712897811085,
    +        0.751234306178963, 2.28856621111248, 0.0688535687513649, 
0.282713153399527,
    +        0.0514786350540817, 3.02959313971882)
    +    )
    +    val dataUnif = sc.parallelize(
    +      Array(0.545859839767218, 0.372763097286224, 0.961302414536476, 
0.257341569056734,
    +        0.207951683318242, 0.861382439732552, 0.464391982648522, 
0.222867433447391,
    +        0.623549601528794, 0.203647700604051, 0.0196734135970473, 
0.797993005951867,
    +        0.274318896699697, 0.166609104024246, 0.170151718193665, 
0.4885059366934,
    +        0.711409077281132, 0.591934921452776, 0.517156876856461, 
0.381627685856074)
    +    )
    +
    +    /* normality test in R
    +    > library(nortest)
    +    > ad.test(datNorm)
    +
    +            Anderson-Darling normality test
    +
    +    data:  datNorm
    +    A = 0.27523, p-value = 0.6216
    +
    +    > ad.test(datExp)
    +
    +            Anderson-Darling normality test
    +
    +    data:  datExp
    +    A = 0.79034, p-value = 0.03336
    +
    +    > ad.test(datUnif)
    +
    +            Anderson-Darling normality test
    +
    +    data:  datUnif
    +    A = 0.31831, p-value = 0.5114
    +
    +    */
    +
    +    val RNormADStats = Map("norm" -> 0.27523, "exp" -> 0.79034, "unif" -> 
0.31831)
    +    val RParams = Map(
    +      "norm" ->(-0.06053267, 0.7999093),
    +      "exp" ->(1.044636, 0.96727),
    +      "unif" ->(0.4420219, 0.2593285)
    +    )
    +
    +
    +    val ADTestNormNorm = ADTest.testOneSample(dataNorm, "norm")
    +    assert(ADTestNormNorm.statistic ~== RNormADStats("norm") relTol 1e-4)
    +    val ADTestExpNorm = Statistics.andersonDarlingTest(dataExp, "norm")
    +    assert(ADTestExpNorm.statistic ~== RNormADStats("exp") relTol 1e-4)
    +    val ADTestUnifNorm = Statistics.andersonDarlingTest(dataUnif, "norm")
    +    assert(ADTestUnifNorm.statistic ~== RNormADStats("unif") relTol 1e-4)
    +
    +    // Testing passing in parameters estimated in R vs estimating directly
    +    assert(
    +      Statistics.andersonDarlingTest(
    +        dataNorm,
    +        "norm",
    +        RParams("norm")._1,
    +        RParams("norm")._2
    +      ).statistic
    +      ~== ADTestNormNorm.statistic relTol 1e-4
    +    )
    +    assert(
    +      Statistics.andersonDarlingTest(
    +        dataExp,
    +        "norm",
    +        RParams("exp")._1,
    +        RParams("exp")._2
    +      ).statistic
    +      ~== ADTestExpNorm.statistic relTol 1e-4
    +    )
    +    assert(
    +      Statistics.andersonDarlingTest(
    +        dataUnif,
    +        "norm",
    +        RParams("unif")._1,
    +        RParams("unif")._2
    +      ).statistic
    +      ~== ADTestUnifNorm.statistic relTol 1e-4
    +    )
    +
    +    /*
    +      normality test in scipy: comparing critical values
    +      >>> from scipy.stats import anderson
    +      >>> # drop in values as arrays
    +      ...
    +    >>> anderson(dataNorm, "norm")
    +    (0.27523090925717852, array([ 0.506,  0.577,  0.692,  0.807,  0.96 ]),
    +    array([ 15. ,  10. ,   5. ,   2.5,   1. ]))
    +    >>> anderson(dataExp, "expon")
    +    (0.45714575153590431, array([ 0.895,  1.047,  1.302,  1.559,  1.9  ]),
    +    array([ 15. ,  10. ,   5. ,   2.5,   1. ]))
    +    */
    +    val SciPyNormCVs = Array(0.506, 0.577, 0.692, 0.807, 0.96)
    --- End diff --
    
    variable names should be lower case


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to