stat-ellipse

Covariance-ellipse statistic: one ellipse per group from the sample covariance of (x, y).

Each output row carries the parameters that geom-ellipse expects: (x0, y0, a, b, angle) with x0, y0 the group centroid, a, b the semi-major and semi-minor radii in data units, and angle the rotation in radians. Pair with geom-ellipse(stat: stat-ellipse()) or equivalently geom-ellipse(stat: "ellipse").

Usage

stat-ellipse(
  level: 0.95,
)

Parameters

Parameter Default Description
level 0.95 Coverage probability for the confidence ellipse, in (0, 1).

Returns

Statistic object with name: "ellipse", consumed by geom-ellipse.

Outputs

  • x0.
  • y0.
  • a.
  • b.
  • angle.

Examples

Three Gaussian-like clusters, each enclosed by a 95% confidence ellipse.

#let pts = ()
#for (cx, cy, k) in ((0, 0, "a"), (4, 1, "b"), (2, 4, "c")) {
  for i in range(0, 30) {
    let r = (calc.sin(i * 0.7) + calc.cos(i * 1.1)) * 0.4
    pts.push((
      x: cx + calc.cos(i * 0.5) + r,
      y: cy + calc.sin(i * 0.5) + r,
      k: k,
    ))
  }
}
#plot(
  data: pts,
  mapping: aes(x: "x", y: "y", fill: "k"),
  layers: (
    geom-point(size: 2pt),
    geom-ellipse(stat: stat-ellipse(), alpha: 0.2),
  ),
  width: 10cm,
  height: 6cm,
)

Scatter chart with x and y axes showing three coloured point clusters a, b, c, each enclosed by a translucent 95 percent confidence ellipse summarising its spread.

Scatter chart with x and y axes showing three coloured point clusters a, b, c, each enclosed by a translucent 95 percent confidence ellipse summarising its spread.

See also

geom-ellipse, stat-summary.

Back to top