perc_dist: Calculate a distribution of percentiles from an ordered...

Description Usage Arguments Details Value Examples

View source: R/perc_dist.R

Description

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

Usage

1
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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
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)

cimentadaj/perccalc documentation built on May 28, 2020, 1:06 p.m.