perc_dist {perccalc}R Documentation

Calculate a distribution of percentiles from an ordered categorical variable and a continuous variable.

Description

Calculate a distribution of percentiles from an ordered categorical variable and a continuous variable.

Usage

perc_dist(data_model, categorical_var, continuous_var, weights = NULL)

Arguments

data_model

A data frame with at least the categorical and continuous variables from which to estimate the percentiles

categorical_var

The bare unquoted name of the categorical variable. This variable should be an ordered factor. If not, will raise an error.

continuous_var

The bare unquoted name of the continuous variable from which to estimate the percentiles

weights

The bare unquoted name of the optional weight variable. If not specified, then equal weights are assumed.

Details

perc_dist drops missing observations silently for calculating the linear combination of coefficients.

Value

A data frame with the scores and standard errors for each percentile

Examples


set.seed(23131)
N <- 1000
K <- 20

toy_data <- data.frame(id = 1:N,
                       score = rnorm(N, sd = 2),
                       type = rep(paste0("inc", 1:20), each = N/K),
                       wt = 1)


# perc_diff(toy_data, type, score)
# type is not an ordered factor!

toy_data$type <- factor(toy_data$type, levels = unique(toy_data$type), ordered = TRUE)

perc_dist(toy_data, type, score)

[Package perccalc version 1.0.5 Index]