The following is the estimate for
$\beta$ (Sen's slope):
\[Beta] = Median[Flatten[Table[(data[[i]] - data[[j]])/(i - j), {i, 1, n - 1}, {j, i + 1, n}]]]
It's the median of all pairwise estimates of slope.
And you need "==" instead of "=" for "S==0" in the Piecewise
function.
Also, S
can be determined in the following manner:
S = Binomial[n, 2] KendallTau[Range[n], data]