Skip to content

detrend builtin

detrend(
    coords,
    values,
    *,
    degree=1,
    bandwidth=None,
    rotation=Ellipsis,
    ratios=Ellipsis,
    weights=None,
    categorical=False,
    scheme=None,
)

Fits a trend and returns it with the residuals, data minus trend.

Without bandwidth, the trend is a polynomial of degree in the coordinates, fitted by least squares. With it, the trend is smooth: at each location, the weighted average of the samples under an anisotropic Gaussian kernel whose standard deviation is bandwidth along the major axis and ratios times it along the semi-major and minor axes. Given several bandwidths, the one with the least leave-one-out error is kept: the weighted mean squared difference between each sample and the trend of the others, a sample with no other within four bandwidths counting against the global mean. Noisier data thus get a smoother trend.

Parameters:

Name Type Description Default
coords (array_like, PointSet or BlockModel)

Sample locations, shape (n, 2) or (n, 3), or a container.

required
values array_like or str

Sample values, or the column of coords holding them. With categorical, category labels.

required
degree int

Polynomial degree, 0 to 2, without bandwidth.

1
bandwidth float or sequence of float

Kernel standard deviation along the major axis, or candidates to choose from.

None
rotation tuple of float

Azimuth, dip and rake of the kernel's major axis, in degrees.

(0, 0, 0)
ratios tuple of float

Semi-major and minor over major bandwidth.

(1, 1)
weights array_like or str

Declustering weights, or the column of coords holding them.

None
categorical bool

Smooth the indicator of each category instead: the trend is the local proportions, which lie in [0, 1] and sum to 1, one per category in the order of Categories.from_values.

False
scheme Categories

With categorical, the categories' order and names, which encode the labels.

None

Returns:

Type Description
Trend

The fitted trend; predict evaluates it anywhere, e.g. at the cells of a BlockModel, as trend= of SGS or TurningBands.

ndarray or Table

Residuals at the samples; per category, indicator minus proportion.

used in