hello can anyone help me with this? i try use makesens 1.0 for the first time to calculate mann kendall test and i have several error such as overflow and divison by zero. i search the answer of this error in forum, but i just solve the overflow issues. now, my problem is the division by zero issues. i attach the code below (the yellow line is an issue):
Private Sub MannKendall(ByVal nYears As Integer, x() As Double, s As Integer, Z As Double, signif As String)
'Calculates the MannKendall test
'Calls the function tiedSum
'Uses the string constants S001, S01, S05 and S1
Dim absS As Integer 'value of absS
Dim varS As Double 'the variance of S
Dim absZ As Double 'value of abs(Z)
Dim k As Integer, j As Integer 'counters for slopes
Dim n As Long 'number of true values in x()
Z = MissingValue ' returns MissingValue for Z
' if they are not calculated
'Computing of the Mann-Kendall statistic S.
signif = ""
n = IIf(x(nYears) <> MissingValue, 1, 0)
s = 0
For k = 1 To nYears - 1
If x(k) <> MissingValue Then
n = n + 1
For j = k + 1 To nYears
If x(j) <> MissingValue Then
s = s + Sgn(x(j) - x(k))
End If
Next j
End If
Next k
If n < 4 Then
'If n is less than 4, the method can not be used at all
Exit Sub
ElseIf n < MinMannKendNorm Then
'If n is between 4 and 10, S is compared directly to Mann-Kendall statistics for S
absS = Abs(s)
signif = Switch(absS >= S_001, S001, absS >= S_01, S01, absS >= S_05, S05, absS >= S_1, S1, True, "")
Else 'n>=MinMannKendNorm
'If n is at least 10, the normal distribution is used
'Firstly the variance VAR(S) is calculated
'The correction term for ties is calculated by the function tiedSum
varS = (n * (n - 1) * (2 * n + 5) - tiedSum(nYears, x)) / 18#
'Calculation of test statistic Z using S and its variance VAR(S)
Z = Switch(s > 0, (s - 1) / Sqr(varS), s < 0, (s + 1) / Sqr(varS), s = 0, 0#)
'The absolute value of Z is compared to critical value Z[1-alpha/2]
'which is obtained from the standard normal table. The presence and
'significance of the trend is evaluated by testing four different
'levels of significance: '0.001, 0.01, 0.05 and 0.1
absZ = Abs(Z)
signif = Switch(absZ > 3.292, S001, absZ > 2.576, S01, absZ > 1.96, S05, absZ > 1.645, S1, True, "")
End If
End Sub 'MannKendall
TIA
Private Sub MannKendall(ByVal nYears As Integer, x() As Double, s As Integer, Z As Double, signif As String)
'Calculates the MannKendall test
'Calls the function tiedSum
'Uses the string constants S001, S01, S05 and S1
Dim absS As Integer 'value of absS
Dim varS As Double 'the variance of S
Dim absZ As Double 'value of abs(Z)
Dim k As Integer, j As Integer 'counters for slopes
Dim n As Long 'number of true values in x()
Z = MissingValue ' returns MissingValue for Z
' if they are not calculated
'Computing of the Mann-Kendall statistic S.
signif = ""
n = IIf(x(nYears) <> MissingValue, 1, 0)
s = 0
For k = 1 To nYears - 1
If x(k) <> MissingValue Then
n = n + 1
For j = k + 1 To nYears
If x(j) <> MissingValue Then
s = s + Sgn(x(j) - x(k))
End If
Next j
End If
Next k
If n < 4 Then
'If n is less than 4, the method can not be used at all
Exit Sub
ElseIf n < MinMannKendNorm Then
'If n is between 4 and 10, S is compared directly to Mann-Kendall statistics for S
absS = Abs(s)
signif = Switch(absS >= S_001, S001, absS >= S_01, S01, absS >= S_05, S05, absS >= S_1, S1, True, "")
Else 'n>=MinMannKendNorm
'If n is at least 10, the normal distribution is used
'Firstly the variance VAR(S) is calculated
'The correction term for ties is calculated by the function tiedSum
varS = (n * (n - 1) * (2 * n + 5) - tiedSum(nYears, x)) / 18#
'Calculation of test statistic Z using S and its variance VAR(S)
Z = Switch(s > 0, (s - 1) / Sqr(varS), s < 0, (s + 1) / Sqr(varS), s = 0, 0#)
'The absolute value of Z is compared to critical value Z[1-alpha/2]
'which is obtained from the standard normal table. The presence and
'significance of the trend is evaluated by testing four different
'levels of significance: '0.001, 0.01, 0.05 and 0.1
absZ = Abs(Z)
signif = Switch(absZ > 3.292, S001, absZ > 2.576, S01, absZ > 1.96, S05, absZ > 1.645, S1, True, "")
End If
End Sub 'MannKendall
TIA