Skip to content

Instantly share code, notes, and snippets.

@JosepER
Created September 9, 2021 07:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JosepER/f0c6c8e79017b28eac9693bb5581bcb0 to your computer and use it in GitHub Desktop.
Save JosepER/f0c6c8e79017b28eac9693bb5581bcb0 to your computer and use it in GitHub Desktop.
An R function wrapping over Julia code for weighted Atkinson index
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