Bivariate Distribution

Shipping
bivariate_distribution

Full joint X–Y analysis: correlation, covariance, KDE contours, ellipses, marginals, OLS + PCA axes

Signature

Inputs

  • xSignal|VectorrequiredX-axis samples (Signal values, or a 1-D array).
  • ySignal|VectorrequiredY-axis samples, paired element-wise with x.

Outputs

  • statsDataFrameOne-row table: n, means, σ, variances, covariance, Pearson r, Spearman ρ, R², slope, intercept, eigenvalues, axis angle, eccentricity.
  • pearson_rScalarPearson linear correlation (dimensionless); NaN if degenerate.
  • spearman_rhoScalarSpearman rank correlation (dimensionless); NaN when $n<3$.
  • covarianceScalarSample covariance $\operatorname{cov}(x,y)$, unit $u_x\cdot u_y$.
  • ellipseSignalNested concentration/confidence ellipse ring(s) as a plottable (x, y) polyline (NaN-separated).
  • kde_contoursSignalKDE iso-density contour segments as an (x, y) polyline.
  • densityMatrix2-D histogram heatmap (rows = y bins, cols = x bins).
  • marginal_xSignalX-axis marginal histogram (bin centers vs counts).
  • marginal_ySignalY-axis marginal histogram.
  • regression_lineSignalOLS y-on-x line drawn across the x-range.
  • principal_axisSignalMajor-eigenvector (PCA) axis through the centroid, $\pm 2\sqrt{\lambda_{\text{major}}}$.

Parameters

KeyTypeDefaultNotes
estimatorenumclassicalone of: classical, robust
robust_fractionfloat0.75MCD subset coverage $h/n$ (0.5 = max breakdown). Active only when estimator = robust.
ellipse_levelstext1,2,3Comma-separated nested contour levels — σ multiples in σ mode, probabilities (0.5,0.95,0.99) in confidence mode.
scale_modeenumsigmaone of: sigma, confidence
distributionenumnormalone of: normal, student
purposeenumconcentrationone of: concentration, mean_confidence, prediction
ellipse_segmentsint96Number of vertices per ellipse ring.
kde_binsint64Resolution of the KDE evaluation grid (per axis).
kde_bandwidthenumscottone of: scott, silverman, manual
kde_bw_scalefloat1.0Smoothing multiplier on the selected bandwidth rule.
kde_levelsint6Number of iso-density KDE contour levels.
kde_padfloat0.12Fraction of the data range to pad the KDE grid by on each side.
heatmap_binsint402-D histogram resolution for the density Matrix output.
marginal_binsint30Bin count for the marginal_x / marginal_y histograms.
max_pointsint200000Cap on points used for the estimate; larger clouds are decimated by a fixed deterministic stride.

Description

Bivariate Distribution takes two paired sample streams (x, y) and produces a complete statistical and geometric breakdown of their joint distribution in one node. Alongside the classic scalar summaries — Pearson (linear), Spearman (rank/monotone), and the sample covariance — it emits a one-row stats DataFrame with everything from the means and variances to , the OLS slope/intercept, and the covariance-ellipse eigen-decomposition (major/minor eigenvalues, axis angle, eccentricity).

The visual outputs are emitted as plottable Signals whose timestamps carry the polyline X and values the Y, with NaN breaks separating disjoint rings/segments — so wiring ellipse, kde_contours, regression_line, or principal_axis straight into a plot draws closed curves with zero plot-side special-casing. The density output is a 2-D histogram heatmap Matrix (rows = y, cols = x), and marginal_x / marginal_y are per-axis histograms.

Two estimators are offered: classical sample covariance, or robust MCD (Minimum Covariance Determinant), which fits only the densest robust_fraction of the cloud and ignores outliers and heavy tails. Confidence ellipses can be scaled by σ-multiples or by probability (Normal χ² or Student-F for small ), and can represent data spread, the confidence region of the mean, or a prediction region for a new point.

Uncertainty is not propagated (-class drops) because these summary statistics are non-linear functions of the inputs. The node is stateless.

Mathematics

Examples

Correlation of a noisy line

Feed x = 1..5 and y ≈ 2x with small noise. pearson_r reads near , the stats DataFrame reports slope , intercept , , and regression_line draws the OLS fit. Wire ellipse and kde_contours into the same plot to see the cloud, its 1σ/2σ/3σ rings, and the KDE density overlaid.

Robust estimate with outliers

Set estimator = robust and robust_fraction = 0.5 so the covariance ellipse and correlation follow the dense core of the data, ignoring a scatter of outliers that would otherwise inflate the classical variance and rotate the principal axis.

Applications

  • Correlation / dependency analysis between two measured channels (linear via Pearson, monotone via Spearman).
  • Publication-ready scatter overlays: confidence ellipses, KDE density contours, marginal histograms, and regression + PCA axes from a single node.
  • Outlier-robust covariance estimation (MCD) for noisy experimental clouds.
  • Feeding the density heatmap Matrix into an image/heatmap sink for 2-D density visualization.

Neat

Every geometry output is a Signal whose timestamps ARE the X coordinates and values the Y, with NaN gaps breaking disjoint rings — so a plot renders nested ellipses and marching-squares KDE contours as closed curves with no special casing.

The confidence ellipse uses a proper Mahalanobis radius that adapts to the chosen distribution (Normal χ² or Student-F for small n) and purpose (data spread vs mean-confidence vs prediction), not a fixed 2σ approximation.

The robust MCD estimator finds the densest data subset and computes covariance from it alone, giving a high-breakdown-point fit that classical covariance cannot.

The principal axis is the major eigenvector of the covariance matrix drawn ±2√λ through the centroid — a live PCA direction indicator over the scatter.

Known issues

Uncertainty is dropped (not propagated) because the summary statistics are non-linear in the inputs.

Spearman ρ is NaN for fewer than 3 points and Pearson r / ellipse geometry are undefined for a degenerate (rank-deficient) cloud.

Clouds larger than max_points are decimated by a fixed stride before estimation; KDE contours further cap at 20,000 points.

See also

bivariatecorrelationcovariancekdeellipsepcarobustmcdstateless