pyMannKendall icon indicating copy to clipboard operation
pyMannKendall copied to clipboard

NaN output in 'Hamed and Rao Modified MK Test'

Open joaocandre opened this issue 1 year ago • 1 comments

I'm running a modified MK test on a couple of short time series:

import pymannkendall as mk

series1 = [0.41625778, 0.40488883, 0.43044564, 0.44369687, 0.46613348, 0.44420775, 0.45091315, 0.48484614, 0.40252088, 0.43944978, 0.51613973, 0.49302274]
series2 = [0.35257984, 0.38692909, 0.39669828, 0.36296244,0.42035612,0.39374964, 0.41100085, 0.43182076, 0.40815853, 0.45394297, 0.41584767, 0.47399517]

print(mk.hamed_rao_modification_test(series1))
print(mk.hamed_rao_modification_test(series2))

And I'm running into a weird result with the second time series, where var_s has a negative value and z and p values become NaN as a result:

Modified_Mann_Kendall_Test_Hamed_Rao_Approach(trend='increasing', h=True, p=0.03352416523500468, z=2.125748992103599, Tau=0.48484848484848486, s=32.0, var_s=212.66666666666666, slope=0.0070362813636363625, intercept=0.40525276250000003)
/home/joao/.local/lib/python3.8/site-packages/pymannkendall/pymannkendall.py:99: RuntimeWarning: invalid value encountered in sqrt
  z = (s - 1)/np.sqrt(var_s)
Modified_Mann_Kendall_Test_Hamed_Rao_Approach(trend='no trend', h=False, p=nan, z=nan, Tau=0.6666666666666666, s=44.0, var_s=-8.737179487179525, slope=0.008305347500000004, intercept=0.36390027875)

joaocandre avatar Jun 05 '23 14:06 joaocandre