Search code examples
matlabstatisticskernel-density

Does the MATLAB ksdensity function perform the boundary correction?


One who is familiar with kernel density estimation should know that there exist some methods for boundary correction. The ksdensity function has the capacity for the [L U] bounded support. Then, my question is, "what boundary correction method is used here?" Reflection or renormalization?


Solution

  • I don't know how renormalization is done traditionally in KDE estimation, but by judging from this piece of the code in ksdensity that deals with support (Run type ksdensity or edit ksdensity in your MATLAB command window)

    function ty = apply_support(yData,L,U)
    % Compute transformed values of data
    if L==-Inf && U==Inf    % unbounded support
        ty = yData;
    elseif L==0 && U==Inf   % positive support
        ty = log(yData);
    else                    % finite support [L, U]
        ty = log(yData-L) - log(U-yData);    % same as log((y-L)./(U-y))
    end
    

    I would expect the bound support output ty = log(yData-L) - log(U-yData) to be a normalized and log-scaled version of the original signal yData.