norm2d: Bivariate normal density with independent components

View source: R/norm2d.R

norm2dR Documentation

Bivariate normal density with independent components

Description

Evaluates the density of a bivariate normal distribution with mean vector \mu = (\mu_x,\mu_y) and diagonal covariance matrix (independent components). The density is the product of the two univariate normal densities:

f(x,y) = \phi(x;\mu_x,\sigma_x)\,\phi(y;\mu_y,\sigma_y).

Usage

norm2d(x, y, mu = c(0, 0), sd = c(1, 1), log = FALSE)

Arguments

x

Numeric vector of x-coordinate(s).

y

Numeric vector of y-coordinate(s).

mu

Numeric vector of length 2 giving c(mu_x, mu_y).

sd

Numeric vector of length 2 giving positive standard deviations c(sd_x, sd_y).

log

Logical; if TRUE, return the log-density.

Value

Numeric vector of densities (or log-densities) with length determined by standard recycling rules for x and y.

Author(s)

Mohammad Ghorbani mohammad.ghorbani@slu.se
Nafiseh Vafaei nafiseh.vafaei@slu.se

Examples


# Evaluate the density at the peak
norm2d(0.5, 0.5, mu = c(0.5, 0.5), sd = c(0.2, 0.2))

# Evaluate at multiple x values
norm2d(c(0.3, 0.7), 0.5, mu = c(0.5, 0.5), sd = c(0.2, 0.2))

# Visualize on a grid
x <- y <- seq(0, 1, length.out = 100)
f <- Vectorize(function(x, y) norm2d(x, y, mu = c(0.5, 0.5), sd = c(0.2, 0.2)))
z <- outer(x, y, f)
image(x, y, z, col = terrain.colors(50), main = "Bivariate Normal Intensity")
contour(x, y, z, add = TRUE)


SepTest documentation built on Feb. 3, 2026, 5:07 p.m.

Related to norm2d in SepTest...