Skip to contents

Computes Shannon entropy H = -sum(p * log(p, base)) for a vector of clonotype counts. Natural log (nats) by default; set base = 2 for bits.

Usage

tcr_shannon_entropy(counts, base = exp(1))

Arguments

counts

Integer vector. Clonotype counts (positive integers).

base

Numeric. Logarithm base. Default exp(1) (natural log). Use 2 for bits.

Value

A numeric scalar >= 0.

Examples

# Uniform: H = log(S)
tcr_shannon_entropy(rep(10, 5))
#> [1] 1.609438

# Single species: H = 0
tcr_shannon_entropy(c(100))
#> [1] 0