| Title: | Recursive Mode Detection for Distributions of Ordinal Data |
|---|---|
| Description: | Provides the function remode() for recursive modality detection in ordinal data. 'remode' is an algorithm specifically designed to estimate the number and location of modes in ordinal data while being robust to large sample sizes. |
| Authors: | Han van der Maas [aut], Madlen Hoffstadt [aut, cre], Javier Garcia-Bernardo [aut] |
| Maintainer: | Madlen Hoffstadt <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.1.0 |
| Built: | 2026-05-16 07:57:06 UTC |
| Source: | https://github.com/cran/remode |
The 'plot.remode_result' function provides a way to visualize the output of the 'remode' function using a bar plot, highlighting the identified modes by adjusting the bar density.
## S3 method for class 'remode_result' plot( x, main = paste("Number of modes =", x$nr_of_modes), density = replace(rep(20, length(x$frequency_input_data)), x$mode_indeces, 50), ... )## S3 method for class 'remode_result' plot( x, main = paste("Number of modes =", x$nr_of_modes), density = replace(rep(20, length(x$frequency_input_data)), x$mode_indeces, 50), ... )
x |
A list of class 'remode_result' containing the output of the 'remode' function. |
main |
A character string specifying the main title of the plot. Default is "Modes = (number of modes)". |
density |
A numeric vector specifying the density of shading lines, in lines per inch, for the bars. Default is 20 for non-mode bars and 50 for mode bars. |
... |
Additional arguments passed to the 'barplot' function. |
None. This function is called for its side effects.
data <- c(80, 90, 110, 70, 90) result <- remode(data) plot(result, xlab="This is my x-axis label", col="red", names=-2:2)data <- c(80, 90, 110, 70, 90) result <- remode(data) plot(result, xlab="This is my x-axis label", col="red", names=-2:2)
Prints a 'remode_result' object in easily readable format.
## S3 method for class 'remode_result' print(x, ...)## S3 method for class 'remode_result' print(x, ...)
x |
A list of class 'remode_result' returned by the 'remode' function. |
... |
Additional arguments. |
No return value, called for its side effects.
Implementation of the recursive modality detection method ('remode') which detects modes in univariate distributions through recursive significance testing. 'remode' recursively tests whether the frequency of a local maximum significantly exceeds the frequencies of neighboring local minima on its left and right side.
remode( xt, alpha = 0.05, f_sign_test = c("bootstrap", "binomial", "fisher"), definition = c("shape_based", "peak_based"), check = FALSE, format_raw = FALSE, levels = seq(min(xt), max(xt)), n_boot = 10000, ... )remode( xt, alpha = 0.05, f_sign_test = c("bootstrap", "binomial", "fisher"), definition = c("shape_based", "peak_based"), check = FALSE, format_raw = FALSE, levels = seq(min(xt), max(xt)), n_boot = 10000, ... )
xt |
A numeric vector of ordinal data. |
alpha |
The significance level for the chi-squared test. Default is 0.05. At each recursive step, |
f_sign_test |
A character string or function specifying the statistical test to use for significance testing. Options are "bootstrap" (default), "binomial" (more efficient when N is large), "fisher" (exact fisher test) or a user-defined function. User-defined functions must include the following arguments: candidate, left_minimum, right_minimum, xt, alpha |
definition |
Underlying modality definition. If "shape_based", the unifom distribution is classified as unimodal. If "peak_based", a uniform distribution is classified as having zero modes. |
check |
A logical variable indicating whether to return input, test, and outcome of each recursive step of the algorithm. Default is FALSE. |
format_raw |
A logical value indicating whether the input data ('xt') is raw data. If TRUE, data will be converted to a frequency table inside the function. Default is FALSE. |
levels |
A numeric vector specifying the categories of the (ordinal) distribution. Used for the factor conversion if 'format_raw' is TRUE. Default is 'seq(min(xt), max(xt))'. |
n_boot |
Number of bootstrap samples. Only used if f_dign_test = "bootstrap". |
... |
Additional arguments |
The function recursively detects a mode candidate (highest frequency), tests whether its frequency significantly deviates from the lowest frequencies on both its left and right side. If significant, the candidate is classified as a mode. The function recursively processes the segments of the vector to the left and right of the mode candidate, applying the same procedure to identify additional modes.
A list of class remode_result containing:
The number of modes identified in the data.
The indices of the identified modes.
Max. p-value of each detected mode.
Approximated Bayes Factors, following Selke et al., 2001
Input data (as frequency table).
The original significance level.
Chosen definition: shape based of peak based.
# Input data as frequencies data <- c(80, 90, 110, 70, 90) result <- remode(data) print(result) plot(result, xlab="This is my x-axis label", col="red", names=-2:2) # Raw data input x <- c(rep(1, 80), rep(2, 90), rep(3, 110), rep(4, 70), rep(5, 90)) result <- remode(x, format_raw = TRUE) print(result) plot(result, xlab="This is my x-axis label", col="red", names=-2:2)# Input data as frequencies data <- c(80, 90, 110, 70, 90) result <- remode(data) print(result) plot(result, xlab="This is my x-axis label", col="red", names=-2:2) # Raw data input x <- c(rep(1, 80), rep(2, 90), rep(3, 110), rep(4, 70), rep(5, 90)) result <- remode(x, format_raw = TRUE) print(result) plot(result, xlab="This is my x-axis label", col="red", names=-2:2)
remode_stability evaluates the stability of the mode estimation of the remode() function by performing jacknife resampling. It generates a series of jackknife resamples, calculates the mean and most frequent number of modes for each sample, and determines the stability of the original modality estimate. Stability is determined by te maximum percentage of data removal for which the majority of iterations still find the original number of modes.
remode_stability( remode_result, iterations = 100, percentage_steps = 10, plot = TRUE )remode_stability( remode_result, iterations = 100, percentage_steps = 10, plot = TRUE )
remode_result |
A list of class 'remode_result', output of remode() function |
iterations |
Numeric value specifying the number of random sub-samples to generate for each percentage step. Default is 100. |
percentage_steps |
An integer specifying the number of percentage steps for data removal. Default is 20 (i.e. steps of 5). |
plot |
Logical value indicating wether to plot the results. Default is TRUE. |
A list containing the stability analysis results.