Related to this question, with a new wrinkle - my data is zero-in flated, so I'm running into this: image.png
I need a way to make rank
discontinuous, so equivalent values are given the same rank. Eg for [1,0,0,2,0,1]
, I'd need ranks [4,1,1,6,1,4]
. Though really, as long as all zeros get rank 1, that should be fine as a short-term solution. Here's a mock up of that solution
function getrank(v; flattenzeros=true)
r = invperm(sortperm(v))
if flattenzeros
z = findall(iszero, v)
r[z] .= 1
end
return r
end
function invnormaltransform(v; μ=0, σ=1, c=3/8, flattenzeros=true)
rank = getrank(v; flattenzeros)
return [norminvcdf(μ, σ, (x - c) / (N - 2c + 1)) for x in rank]
end
which gives me image.png
Last updated: Dec 28 2024 at 04:38 UTC