Created
September 9, 2021 07:04
-
-
Save JosepER/f0c6c8e79017b28eac9693bb5581bcb0 to your computer and use it in GitHub Desktop.
An R function wrapping over Julia code for weighted Atkinson index
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
weighted_atkinson_jl <- function(x, weights, epsilon, na.rm = FALSE){ | |
JuliaCall::julia_call("weighted_atkinson", x, weights, epsilon, na.rm) | |
} | |
julia_weighted_atkinson_function <- JuliaCall::julia_eval("function weighted_atkinson(v, w, ϵ::Real, skipmissing::Bool) | |
if skipmissing | |
w = w[findall(!ismissing, v)] | |
v = v[findall(!ismissing, v)] | |
end | |
v = v/Statistics.mean(v) | |
w = w/sum(w) | |
if ϵ == 1 | |
w = w[v .!= 0] | |
v = v[v .!= 0] | |
return 1 - (prod(exp.(w.*log.(v)))/sum(v .* w/sum(w)) ) | |
elseif ϵ < 1 | |
return 1-(sum(((v/sum(v.*w/sum(w))).^(1-ϵ)).*w/sum(w))).^(1/(1-ϵ)) | |
else | |
w = w[v .!= 0] | |
v = v[v .!= 0] | |
return 1-(sum(((v/sum(v.*w/sum(w))).^(1-ϵ)).*w/sum(w))).^(1/(1-ϵ)) | |
end | |
end ") | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment