| Type: | Package |
| Title: | Recursive Mode Detection for Distributions of Ordinal Data |
| Version: | 0.1.0 |
| 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. |
| License: | MIT + file LICENSE |
| Encoding: | UTF-8 |
| RoxygenNote: | 7.3.2 |
| Imports: | graphics |
| Suggests: | testthat (≥ 3.0.0) |
| Config/testthat/edition: | 3 |
| NeedsCompilation: | no |
| Packaged: | 2026-01-11 12:01:57 UTC; Michael |
| Author: | Han van der Maas [aut], Madlen Hoffstadt [aut, cre], Javier Garcia-Bernardo [aut] |
| Maintainer: | Madlen Hoffstadt <madlenfeehoffstadt@gmail.com> |
| Repository: | CRAN |
| Date/Publication: | 2026-01-16 11:00:02 UTC |
Plot for remode_result
Description
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.
Usage
## 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),
...
)
Arguments
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. |
Value
None. This function is called for its side effects.
Examples
data <- c(80, 90, 110, 70, 90)
result <- remode(data)
plot(result, xlab="This is my x-axis label", col="red", names=-2:2)
Printing remode_result
Description
Prints a 'remode_result' object in easily readable format.
Usage
## S3 method for class 'remode_result'
print(x, ...)
Arguments
x |
A list of class 'remode_result' returned by the 'remode' function. |
... |
Additional arguments. |
Value
No return value, called for its side effects.
Recursive Mode Detection for Distributions of Ordinal Data
Description
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.
Usage
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,
...
)
Arguments
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 |
Details
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.
Value
A list of class remode_result containing:
- nr_of_modes
The number of modes identified in the data.
- mode_indeces
The indices of the identified modes.
- p_values
Max. p-value of each detected mode.
- approx_bayes_factors
Approximated Bayes Factors, following Selke et al., 2001
- frequency_input_data
Input data (as frequency table).
- alpha
The original significance level.
- definition
Chosen definition: shape based of peak based.
Examples
# 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)
Barplot for 'remode' result
Description
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.
Usage
remode_stability(
remode_result,
iterations = 100,
percentage_steps = 10,
plot = TRUE
)
Arguments
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. |
Value
A list containing the stability analysis results.