estimate_mode: Estimate the mode of a distribution

View source: R/analyze_data.R

estimate_modeR Documentation

Estimate the mode of a distribution

Description

Estimate the mode of a numeric distribution using kernel density estimation.

Usage

estimate_mode(x, na_rm = TRUE, ...)

Arguments

x

Numeric vector.

na_rm

Logical value. If TRUE, missing values are removed before estimation.

...

Further arguments passed to stats::density().

Details

The function computes a kernel density estimate with stats::density() and returns the value of x at which the estimated density is largest.

Missing values are removed by default. Additional arguments are passed to stats::density(), for example bw, kernel, or n.

Value

A numeric value giving the estimated mode of the distribution.

See Also

Other data analysis: acf_vec(), estimate_acf(), estimate_kurtosis(), estimate_pacf(), estimate_skewness(), pacf_vec(), summarise_data(), summarise_split(), summarise_stats()

Examples

x <- c(1, 1, 2, 2, 2, 3, 4, NA)

estimate_mode(x)
estimate_mode(x, na_rm = TRUE)
estimate_mode(x, bw = "nrd0")

set.seed(123)
y <- rnorm(100, mean = 5)
estimate_mode(y)

tscv documentation built on May 13, 2026, 9:07 a.m.