jsd_discrete: Estimate JSD for discrete variables

View source: R/jsd_discrete.R

jsd_discreteR Documentation

Estimate JSD for discrete variables

Description

Computes Jensen-Shannon divergence (JSD) between two discrete variables using empirical probability mass functions.

Usage

jsd_discrete(
  x,
  y,
  support = NULL,
  base = 2,
  eps = 1e-12,
  add_smoothing = FALSE,
  na_rm = TRUE
)

Arguments

x

Vector for group 1. Can be numeric, factor, character, or logical.

y

Vector for group 2. Can be numeric, factor, character, or logical.

support

Optional support values. If 'NULL', the union of observed values in 'x' and 'y' is used.

base

Logarithm base. Defaults to 2. Use 'exp(1)' for nats.

eps

Small constant for numerical stability.

add_smoothing

Logical; add 1 to each cell count?

na_rm

Logical; remove missing values?

Value

An object of class '"jsd_estimate"'.


jsdtools documentation built on March 31, 2026, 1:06 a.m.