Makesens 1.0

rnldy

New Member
Joined
Nov 20, 2022
Messages
8
Office Version
  1. 365
  2. 2013
  3. 2010
Platform
  1. Windows
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(n), S001, absS >= S_01(n), S01, absS >= S_05(n), S05, absS >= S_1(n), 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
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
update: i found the problem, but it's not over yet. the error show up because i have all zero data ini one column.

but it is not solve anything cause i i need that zero data. is there any solutions?
 
Upvote 0

Forum statistics

Threads
1,223,164
Messages
6,170,444
Members
452,326
Latest member
johnshaji

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top