histwidth: Histogram Widths

histwidthR Documentation

Histogram Widths

Description

Generates a set of class breaks and absolute frequencies for the range from from to to. Class widths are randomly sampled from the vector widths. The total number of classes (nb) must be an integer multiple of min(widths); otherwise, the function stops with an error. If the initial frequencies (n) are too small, they can be scaled by an integer factor. The routine also checks whether the resulting class densities are terminating decimals.

Usage

histwidth(from, to, widths, dmax = 2000, maxit = 1000)

width_breaks(from, to, widths, dmax = 2000, maxit = 1000)

dhistwidth(from, to, widths, dmax = 2000, maxit = 1000)

Arguments

from

numeric: start value of the range.

to

numeric: end value of the range.

widths

numeric: vector of possible class widths to sample from.

dmax

numeric: maximum denominator allowed when checking fractional densities, see fractions().

maxit

integer: maximum number of iterations when attempting to find a suitable break pattern.

Value

A list containing:

breaks

Numeric vector of class boundaries.

n

Integer vector of absolute frequencies for each class.

decimal

Logical, TRUE if all densities are terminating decimals.

density

Numeric vector of class densities.

Examples

l <- histwidth(1.6, 2.1, widths = c(0.05, 0.1, 0.15, 0.2))
x <- histx(l$breaks, l$n)
histdata(x, l$breaks)
# Fallback: use constant min(widths) if no valid break pattern 
# is found within max iterations
l <- histwidth(1.6, 2.1, widths=0.05, dmax=10)
str(l)

exams.forge documentation built on Aug. 21, 2025, 5:41 p.m.