“Kernel density estimate” statistics

Contents:

kdestats.conflevel(kde, frac, ftol=1e-06, tol=1e-06, usespline=False, verbose=False, maxiter=None)[source]

Determine the lower and upper confidence levels required to enclose a given fraction ‘frac’ of a KDE object’s dataset(s) to within a tolerance ftol.

kdestats.confmap(map, frac, **kw)[source]

Return the confidence level of a 2D histogram or array that encloses the specified fraction of the total sum.

INPUTS:
map : 1D or 2D numpy array

Probability map (from hist2d or kde)

frac : float, 0 <= frac <= 1

desired fraction of enclosed energy of map

OPTIONS:
ordinate : None or 1D array

If 1D map, interpolates onto the desired value. This could cause problems when you aren’t just setting upper/lower limits....

kdestats.findkdeval(kde, val, guess=None, tol=1e-06, maxiter=1000, verbose=False)[source]

Find the “x”-value such that kde(x)=val +/- tol

Without a specified guess for a monomodal distribution, tends to find the lower of the two possible values.

Uses scipy.stats.gaussian_kde objects

kdestats.kde_max(kde, tol=0.001)[source]

Determine the maximum value of a KDE INPUT: scipy.stats.kde object

kdestats.kdehist2(x, y, npts, xrange=None, yrange=None)[source]

Generate a 2D histogram map from data, using Gaussian KDEs

INPUTS:
x : seq

X data

y : seq

Y data

npts : int or 2-seq

number of points across final histogram, or [nx, ny]

OPTIONAL_INPUTS:
 
xrange : 2-seq

[x_min, x_max] values for final histogram

yrange : 2-seq

[y_min, y_max] values for final histogram

RETURNS:

[kdehist, xbins, ybins]

EXAMPLE:
import kdestats as kde
import numpy as np
import pylab as py

covmat = [[1., 1.5], [1.5, 4.]]
xy = np.random.multivariate_normal([0, 0], covmat, [1e4])
kdehist = kde.kdehist2(xy[:,0], xy[:,1], [30, 30])
clevels = kde.confmap(kdehist[0], [.6827,.9545,.9973])

py.figure()  # Plot 1-, 2-, and 3-sigma contours
c = py.contour(kdehist[1], kdehist[2], kdehist[0], clevels)

Previous topic

Spitzer/MIPS 24 micron Analysis Routines

Next topic

Difference Image Analysis

This Page