Learn R Programming

SynthesizerPlus (version 0.4.0)

margin_categorical: Marginal quantile functions for r_mvdist()

Description

margin_categorical() builds a quantile function for a categorical variable; margin_empirical() builds the (interpolated) empirical quantile function of observed data, preserving its class.

Usage

margin_categorical(levels, probs = NULL, ordered = FALSE)

margin_empirical(x, interpolation = c("linear", "spline"))

Value

A function of p returning values.

Arguments

levels

Category labels.

probs

Category probabilities (normalised internally).

ordered

Return an ordered factor?

x

Observed data (numeric, integer, Date, POSIXct, factor, character, logical).

interpolation

"linear" or "spline".

Examples

Run this code
q <- margin_categorical(c("low", "mid", "high"), c(0.2, 0.5, 0.3), ordered = TRUE)
table(q(runif(1000)))
qe <- margin_empirical(faithful$eruptions)
summary(qe(runif(1000)))

Run the code above in your browser using DataLab