Add cdf and quantile methods for UnivariateKDE
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 45/100
Research direction
Start at the UnivariateKDE entry point and review how the kde grid and density values are represented. Use the proposed trapezoid-rule grid, normalization, and linear interpolation approach as the reference for both cdf and quantile methods. Done means both methods are available with behavior consistent with the stated interpolation approach.
Written by the indexing model from the issue text.
Description
I propose adding methods for evaluating the cdf and the quantiles of a UnivariateKDE object.
Background
Kernel estimators are the go-to class of estimators for nonparametric density estimation in one dimension, owing to their speed and good practical performance. Not only would a cdf method based on the result of an interpolated kde object be of independent interest for visualization purposes, but being able to evaluate the cdf is a necessity for some statistical models such as those based on copulas.
In the world of copulas, dependence structure and marginal distributions are modeled separately, and kernel estimators are commonly employed when estimating the required univariate marginals. However, estimation of the copula itself requires evaluation of the resulting cdf estimate.
Proposed changes
Adding convenience functions for computing the cdf and the quantile function. In particular, my proposed solution is to construct both the cdf and the quantile function via linear interpolation, e.g. as in the spatstat R package.
A basic implementation would be something akin to
using KernelDensity, Interpolations
x = randn(10^4)
k = kde(x)
# First compute Fhat on the midpoints grid, then linearly interpolate the result
dt = step(k.x)
F_grid = Vector{Float64}(undef, length(k.x))
F_grid[1] = 0.0
for j = 2:length(k.x) # compute Fhat at grid via the trapezoid rule
F_grid[j] = F_grid[j-1] + 0.5 * (k.density[j] + k.density[j-1]) * dt
end
F_grid = F_grid / F_grid[end] # normalize so that F is a proper cdf
F_interp = linear_interpolation(k.x, F_grid, extrapolation_bc=Flat()) # the estimated cdf
The approach to computing the quantile function is similar. This would not add any additional dependencies as KernelDensity already depends on Distributions and Interpolations.
Other approaches
There are other ways of constructing estimates of the cdf based on tabulated data. However, I find the linear interpolation method the most appealing due to the inherent symmetry between linear interpolation of the cdf and of the quantile function, i.e. interpolation and the generalized inverse commutes for linear interpolation, which will not necessarily be the case for higher-order interpolants.
Implementation
If there is interest in including these methods in KernelDensity.jl, I'd be happy to create a PR.
- Dominant language
- Julia
- Stars
- 213
- Forks
- 45
- PR merge metrics
- No merged PRs in 30d
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from JuliaStats/KernelDensity.jl
-
Difficulty 2/5 1-3 hours Newbie friendliness 50/100
JuliaStats/KernelDensity.jl#129 ·
-
Difficulty 5/5 Over a week Newbie friendliness 35/100
JuliaStats/KernelDensity.jl#128 ·
-
Difficulty 5/5 Over a week Newbie friendliness 25/100
JuliaStats/KernelDensity.jl#126 · 7 comments ·
-
Difficulty 5/5 Over a week Newbie friendliness 30/100
JuliaStats/KernelDensity.jl#125 · 5 comments ·
-
Difficulty 3/5 1-2 days Newbie friendliness 42/100
JuliaStats/KernelDensity.jl#124 ·
All issues in JuliaStats/KernelDensity.jl
Similar issues
-
docs
Difficulty 1/5 Under an hour Newbie friendliness 88/100
-
path: splitext treats directory references and leading dots as extensionsPossibly taken @Hiten0305l claimed this today. Open
Difficulty 2/5 Half a day Newbie friendliness 72/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
JuliaRegistries/RegistryCI.jl#758 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
JuliaParallel/Hwloc.jl#93 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
Maintainers usually reply within 1 day