有没有更简洁的方法来计算VBA的Anderson-Darling A平方统计量的P值?

时间:2017-01-17 16:22:01

标签: excel vba excel-vba statistics

我在VBA for Excel中有两位代码。一个计算Anderson-Darling测试的A平方统计量,这一位代码计算A平方统计量的P值。我很好奇是否有更简洁的方法或更有效的方法来计算VBA中的这个值:

Function AndDarP(AndDar, Elements)

    'Calculates P value for level of significance for the
    'Anderson-Darling Test for Normality

    'AndDar is the Anderson-Darling Test Statistic
    'Elements is the count of elements used in the
    'Anderson-Darling test statistic.

    'based on calculations at
    'http://www.kevinotto.com/RSS/Software/Anderson-Darling%20Normality%20Test%20Calculator.xls
    'accessed 21 May 2010
    'www.kevinotto.com
    'kevin_n_otto@yahoo.com
    'Version 6.0
    'Permission to freely distribute and modify when properly
    'referenced and contact information maintained.
    '
    '"Keep in mind the test assumes normality, and is looking for sufficient evidence to reject normality.
    'That is, a large p-value (often p > alpha = 0.05) would indicate normality.
    ' * * *
    'Test Hypotheses:
    'Ho: Data is sampled from a population that is normally distributed
    '(no difference between the data and normal data).
    'Ha: Data is sampled from a population that is not normally distributed"

    Dim M As Double

    M = AndDar * (1 + 0.75 / Elements + 2.25 / Elements ^ 2)

    Select Case M
        Case Is < 0.2
        AndDarP = 1 - Exp(-13.436 + 101.14 * M - 223.73 * M ^ 2)
        Case Is < 0.34
        AndDarP = 1 - Exp(-8.318 + 42.796 * M - 59.938 * M ^ 2)
        Case Is < 0.6
        AndDarP = Exp(0.9177 - 4.279 * M - 1.38 * M ^ 2)
        Case Is < 13
        AndDarP = Exp(1.2937 - 5.709 * M + 0.0186 * M ^ 2)
        Case Else
        AndDarP = 0
    End Select
End Function

0 个答案:

没有答案