Package {roundr}


Title: Incorporate Rounding for Discrete Data Modeling
Version: 1.0.0
Description: Provides density, distribution and random number generator functions to account for discretization in data where recorded values mask the underlying measurement process. Details on methodology are described in Glazer et al. (2026) <doi:10.1080/00031305.2025.2604812>.
License: MIT + file LICENSE
Depends: R (≥ 4.1.0)
Encoding: UTF-8
RoxygenNote: 7.3.3
Imports: rlang, statmod
Suggests: testthat (≥ 3.0.0)
Config/testthat/edition: 3
NeedsCompilation: no
Packaged: 2026-05-13 05:41:53 UTC; berkeleyho
Author: Berkeley Ho [aut, cre]
Maintainer: Berkeley Ho <berknho@gmail.com>
Repository: CRAN
Date/Publication: 2026-05-18 18:30:07 UTC

Returns the probability mass function for the rounded asymmetric Laplace distribution

Description

Returns the probability mass function for the rounded asymmetric Laplace distribution

Usage

drdald(
  x,
  mu = 0,
  sigma = 1,
  tau = 0.5,
  n.quad = 7,
  thresh = 1e-20,
  log = FALSE
)

Arguments

x

Vector of quantiles.

mu

Vector of location parameters.

sigma

Vector of scale parameters.

tau

Vector of skewness parameters.

n.quad

Numeric. The degree of a Legendre polynomial used for approximation.

thresh

Numeric. Threshold used to truncate small probability values before taking logarithms when log.p = TRUE.

log

Logical. If TRUE, probabilities p are given as log(p).

Value

A vector of densities.

Examples

drdald(-1)

drdald(x = 0, mu = 2, sigma = 2, tau = .3)

x = -3:3
mu = 1
sigma = 1
tau = 0.5
drdald(x = x, mu = mu, sigma = sigma, tau = tau, log = TRUE)

Returns the probability mass function for the rounded normal distribution

Description

Returns the probability mass function for the rounded normal distribution

Usage

drdnorm(x, mu = 0, sigma = 1, n.quad = 7, thresh = 1e-20, log = FALSE)

Arguments

x

Vector of quantiles.

mu

Vector of means.

sigma

Vector of standard deviations.

n.quad

Numeric. The degree of a Legendre polynomial used for approximation.

thresh

Numeric. Threshold used to truncate small probability values before taking logarithms when log.p = TRUE.

log

Logical. If TRUE, probabilities p are given as log(p).

Value

A vector of densities.

Examples

drdnorm(x = 1)

drdnorm(x = -1, mu = 1, sigma = 4)

y <- c(-1, 0, 1, 2, 3)
mu <- 1.5
sigma <- 2
drdnorm(x = y, mu = mu, sigma = sigma, log = TRUE)

Returns the Cumulative Distribution Function for the rounded asymmetric Laplace distribution

Description

Returns the Cumulative Distribution Function for the rounded asymmetric Laplace distribution

Usage

drpald(
  q,
  mu = 0,
  sigma = 1,
  tau = 0.5,
  lower.tail = TRUE,
  log.p = FALSE,
  n.quad = 7,
  thresh = 1e-20,
  tails = 35
)

Arguments

q

Vector of quantiles.

mu

Vector of location parameters.

sigma

Vector of scale parameters.

tau

Vector of skewness parameters.

lower.tail

Logical. If TRUE, probabilities are P\{X \le x\} otherwise, P\{X > x\}.

log.p

Logical. If TRUE, probabilities p are given as log(p).

n.quad

Numeric. The degree of a Legendre polynomial used for approximation.

thresh

Numeric. Threshold used to truncate small probability values before taking logarithms when log.p = TRUE.

tails

Numeric. Threshold used to generate probabilities for sampling.

Value

A vector of cumulative probability densities

Examples

drpald(0)

drpald(q = 0.5, mu = 0, sigma = 1, tau = 0.75, log.p = TRUE)

q = -1:3
mu = 1
sigma = 2
tau = 0.5
drpald(q = q, mu = mu, sigma = sigma, tau = tau, lower.tail = FALSE)

Returns the Cumulative Distribution Function for the rounded normal distribution

Description

Returns the Cumulative Distribution Function for the rounded normal distribution

Usage

drpnorm(
  q,
  mu = 0,
  sigma = 1,
  lower.tail = TRUE,
  log.p = FALSE,
  n.quad = 7,
  thresh = 1e-20,
  tails = 10
)

Arguments

q

Vector of quantiles.

mu

Vector of means.

sigma

Vector of standard deviations.

lower.tail

Logical. If TRUE, probabilities are P\{X \le x\} otherwise, P\{X > x\}.

log.p

Logical. If TRUE, probabilities p are given as log(p).

n.quad

Numeric. The degree of a Legendre polynomial used for approximation.

thresh

Numeric. Threshold used to truncate small probability values before taking logarithms when log.p = TRUE.

tails

Numeric. Threshold used to generate probabilities for sampling.

Value

Vector of cumulative probability densities for the given quantiles.

Examples

drpnorm(2)

drpnorm(q = 0, mu = 1, sigma = 1)

q <- c(1, 2, 3)
mu <- 3
sigma <- 2

drpnorm(q = q, mu = mu, sigma = sigma, lower.tail = FALSE)

Returns randomly generated values from the rounded asymmetric Laplace distribution

Description

Returns randomly generated values from the rounded asymmetric Laplace distribution

Usage

drrald(
  n,
  type = c("floor", "ceil", "nearest"),
  mu = 0,
  sigma = 1,
  tau = 0.5,
  tails = 35
)

Arguments

n

Number of observations. When length(n) > 1, the number of observations is taken as the length of n.

type

Character. Type of rounding applied to the latent variable. One of "floor", "ceil", or "nearest".

mu

Vector of values for the location parameter.

sigma

Vector of values for the scale parameter.

tau

Vector of values to for the skewness parameter.

tails

Numeric. Threshold used to generate probabilities for sampling.

Value

A vector of numbers randomly generated from a rounded asymmetric Laplace distribution.

Examples

drrald(1, "floor")

drrald(n = 5, type = "ceil", mu = 5, sigma = 4, tau = 0.5)

mu = c(1, 4)
sigma = c(1, 2)
tau = c(0.3, 0.5)
drrald(n = 7, type = "nearest", mu = mu, sigma = sigma, tau = tau)

Returns randomly generated values from the rounded normal distribution

Description

Returns randomly generated values from the rounded normal distribution

Usage

drrnorm(n, type = c("floor", "ceil", "nearest"), mu = 0, sigma = 1, tails = 10)

Arguments

n

Number of observations. When length(n) > 1, the number of observations is taken as the length of n.

type

Character. Type of rounding applied to the latent variable. One of "floor", "ceil", or "nearest".

mu

Vector of means.

sigma

Vector of standard deviations.

tails

Numeric. Threshold used to generate probabilities for sampling.

Value

A vector of numbers randomly generated from a rounded normal distribution.

Examples

drrnorm(1, "floor")

drrnorm(n = 10, type = "nearest", mu = 4, sigma = 2)

mu <- c(0, 5)
sigma <- c(1, 4)
drrnorm(n = 20, "ceil", mu = mu, sigma = sigma)