# Anderson-Darling test pvalue

**URL:** https://discourse.julialang.org/t/anderson-darling-test-pvalue/76929
**Category:** Statistics
**Tags:** question, hypothesis-tests
**Created:** [February 22, 2022, 6:31pm UTC](https://discourse.julialang.org/t/anderson-darling-test-pvalue/76929 "2022-02-22T18:31:35Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![as4831](https://avatars.discourse-cdn.com/v4/letter/a/cdc98d/32.png) [@as4831](https://discourse.julialang.org/u/as4831)
#### Post date: [February 22, 2022, 6:31pm UTC](https://discourse.julialang.org/t/anderson-darling-test-pvalue/76929/1 "2022-02-22T18:31:35Z")

</div>

Hi everyone, I’m using an Anderson-Darling test to check for normality and am unsure about the results. I am expecting to reject at the .01 level with a p-value around .008. The pvalue() call on the OneSampleADTest returns .323. When looking at the test summary the test statistic is 1.06, expected.

I’m new to Julia and am thinking I am causing the problem. Any reason the returned pvalue is different than what Agostino and Stephen’s would give?

---

<div class="post-metadata">

### Author: ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)
#### Post date: [February 22, 2022, 7:34pm UTC](https://discourse.julialang.org/t/anderson-darling-test-pvalue/76929/2 "2022-02-22T19:34:23Z")

</div>

Maybe you could double-check the results [using Pingouin](https://discourse.julialang.org/t/ann-pingouin-jl-a-simple-yet-exhaustive-statistical-package/48362).

---

<div class="post-metadata">

### Author: ![as4831](https://avatars.discourse-cdn.com/v4/letter/a/cdc98d/32.png) [@as4831](https://discourse.julialang.org/u/as4831)
#### Post date: [February 23, 2022, 4:04pm UTC](https://discourse.julialang.org/t/anderson-darling-test-pvalue/76929/3 "2022-02-23T16:04:37Z")

</div>

I did try this. I also double checked off excel, python and JMP. The test statistic is the same across all bu the returned p-value is different, in this case not significant, in Julia vs the others.

Pardon my formatting, still learning:  
using CSV  
using DataFrames  
using Statistics  
using StatsPlots  
using Distributions  
using HypothesisTests  
using Pingouin

`data = [6.67, -0.69, -2.03, -2.6, 2.19, -1.17, 9.93, -2.68, 10.41, -1.34, -0.16, -0.26, 1.67, -4.04, 6.46, 2.94, 7.32, -2.49, -1.26, -0.17, 7.06] mean_samp = mean(data) std_samp = std(data) d = Normal(mean_samp, std_samp) tested = OneSampleADTest(data, d) tested pvalue(tested) `  
Returns the right AD value but the pvalue returned is .34. Should be .008.

---

<div class="post-metadata">

### Author: ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)
#### Post date: [February 23, 2022, 4:28pm UTC](https://discourse.julialang.org/t/anderson-darling-test-pvalue/76929/4 "2022-02-23T16:28:22Z")

</div>

In this case, maybe you could open an issue in the `HypothesisTests.jl` github page.

---

<div class="post-metadata">

### Author: ![andreasnoack](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/andreasnoack/32/27_2.png) [@andreasnoack](https://discourse.julialang.org/u/andreasnoack)
#### Post date: [February 23, 2022, 4:33pm UTC](https://discourse.julialang.org/t/anderson-darling-test-pvalue/76929/5 "2022-02-23T16:33:52Z")

</div>

Before doing so it might be good to check [https://github.com/JuliaStats/HypothesisTests.jl/issues/74](https://github.com/JuliaStats/HypothesisTests.jl/issues/74) and [https://github.com/JuliaStats/HypothesisTests.jl/pull/118](https://github.com/JuliaStats/HypothesisTests.jl/pull/118) explain the discrepancy.

---

<div class="post-metadata">

### Author: ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)
#### Post date: [February 23, 2022, 10:37pm UTC](https://discourse.julialang.org/t/anderson-darling-test-pvalue/76929/6 "2022-02-23T22:37:12Z")

</div>

After some research it seems that the reference most programs use is:

_D’Agostino, R.B. and Stephens, M.A. (1986) Goodness-of-Fit Techniques; Marcel-Dekker: New York, USA_

The formulas can be easily implemented in Julia and the desired p-value of 0.0087 obtained for your data:

```julia
using Distributions

function AD(Zₛ)
    n = length(Zₛ)
    cf = cdf(Normal(0,1), Zₛ)
    (−n − 1/n * sum(((2i-1)*log(cf[i]) +(2*(n-i)+1)*log(1-cf[i])) for i in 1:n))
end

# D'Agostino and Stephens (1986)
function p_Agostino(adc)
    adc >= 0.6 ? exp(1.2937 - 5.709*adc + 0.0186*adc^2) :
    0.34 < adc ? exp(0.9177 - 4.279*adc - 1.38*adc^2) :
    0.20 < adc ? 1 - exp(8.318 + 42.796*adc - 59.938*adc^2) :
    1 - exp(-13.436 + 101.14*adc - 223.73*adc^2)
end

X = [6.67, -0.69, -2.03, -2.6, 2.19, -1.17, 9.93, -2.68, 10.41, -1.34, -0.16, -0.26, 1.67, -4.04, 6.46, 2.94, 7.32, -2.49, -1.26, -0.17, 7.06]

sort!(X)
X̄ = mean(X)
σₓ = std(X)
Zₛ = (X .- X̄)/σₓ # Z-scores
n = length(X)
adc = AD(Zₛ)*(1 + 0.75/n + 2.25/(n*n)) # correction for small sample sizes
p_Agostino(adc) # p-value = 0.0087

```
