bwe

bwe estimates the bandwidth smoothing parameter for kernel density estimation.

Syntax

Description

example

bw =bwe(X) Bandwidth and kernel density estimates for a univariate normal sample.

example

bw =bwe(X, bwopt) Bandwidth and kernel density estimates for a univariate mixture of two normals.

Examples

expand all

  • Bandwidth and kernel density estimates for a univariate normal sample.
  • % the normal probability density function
    npdf = @(x) (exp(-0.5*x.^2)/sqrt(2*pi));
    % normal kernel density
    nkde = @(x,unidata,h) mean(npdf((x-unidata)/h)/h); % kernel density
    % a univariate normal sample
    unidata = randn(200,1);
    % bandwidth estimation
    h = bwe(unidata);
    % plot of kernel density with estimated bandwidth
    warning('off');
    fplot(@(x) nkde(x,unidata,h),[-10,10],'r')
    % plot of the true density
    hold on
    fplot(@(x) (npdf(x)) ,[-10,10],'k')
    % plot of the data
    plot(unidata,npdf(unidata),'xb')
    warning('on');
    axis manual;
    title(['estimated bandwidth: ' num2str(h) ]);
    legend('estimated density','true density','data');

  • Bandwidth and kernel density estimates for a univariate mixture of two normals.
  • The smoothing is shown for various bandwidth values.

    % the normal probability density function
    npdf = @(x) (exp(-0.5*x.^2)/sqrt(2*pi));
    % normal kernel density
    nkde = @(x,unidata,h) mean(npdf((x-unidata)/h)/h); % kernel density
    % mixture of two univariate normal samples
    unidata = [randn(100,1)-5 ; randn(100,1)+5];
    i=0;
    for smfact = 1:3:7
    i=i+1;
    % bandwidth estimation
    h = bwe(unidata) / smfact;
    subplot(3,1,i);
    % plot of kernel density with estimated bandwidth
    warning('off');
    fplot(@(x) nkde(x,unidata,h),[-10,10],'r')
    % plot of the true density
    hold on;
    fplot(@(x) (npdf(x-5) + npdf(x+5)),[-10,10],'k')
    % plot of the data
    plot(unidata,(npdf(unidata-5) + npdf(unidata+5)),'xb')
    warning('on');
    if i == 1
    xlabel(['bw0 = ' num2str(h) ' (estimated from the data)' ]);
    else
    xlabel(['bw0 / ' num2str(i) ' = ' num2str(h) ]);
    end
    end

    Related Examples

    expand all

  • Bandwidth and kernel density estimates for a bivariate dataset.
  • load fishery;
    X = fishery{:,:};
    X = X+10^(-8)*abs(randn(677,2)); % some jittering to avoid dplicate points
    h = bwe(X)
    h = bwe(X,'scott')
    h = bwe(X,'normal')
    h = bwe(X,'robust')

    Input Arguments

    expand all

    X — Input data. Vector or matrix.

    The data to be smoothed by kernel density estimation.

    Data Types: single| double

    Optional Arguments

    bwopt — Estimation method. String.

    Default is Scott's rule.

    Other options are: - 'normal', the normal reference rule, applied only for d=1. It is valid if the underlying density being estimated is Gaussian.

    - 'robust', is the normal reference rule, applicable in presence of outliers, again for d=1.

    Example: 'method','robust'

    Data Types: char

    Output Arguments

    expand all

    bw —bandwidth estimate. Vector or Scalar

    It is a scalar if the data is uni-dimensional, otherwise is a vector with a bandwidth value for each dimension.

    References

    Bowman, A.W. and Azzalini, A. (1997), "Applied Smoothing Techniques for Data Analysis", Oxford University Press.

    Silverman, B.W. (1998), "Density Estimation for Statistics and Data Analysis", Chapman & Hall/CRC, London. [pp. 48]

    See Also

    This page has been automatically generated by our routine publishFS