Skip to contents

Gaussian-kernel 2-D density on a regular grid, matching MASS::kde2d (same normal-reference bandwidth and the h/4 scaling MASS applies).

Usage

morie_kde2d(x, y, h, n = 25, lims = c(range(x), range(y)))

Arguments

x, y

Numeric coordinate vectors of equal length.

h

Bandwidth vector (default normal-reference per coordinate).

n

Grid size (scalar or length-2).

lims

Grid limits c(xlo, xhi, ylo, yhi).

Value

A list list(x, y, z) (grid axes and the n1 x n2 density matrix).

Examples

set.seed(2)
x <- rnorm(80); y <- rnorm(80)
k <- morie_kde2d(x, y, n = 20)
dim(k$z)
#> [1] 20 20