get_cdfs: Compute Cumulative Distribution Functions (CDFs) based on...

View source: R/get_cdfs.R

get_cdfsR Documentation

Compute Cumulative Distribution Functions (CDFs) based on sample data.

Description

Given a data frame with at least one continuous variable and one categorical variable, we can use this function to find the empirical CDFs of any continuous variable on the data frame, optionally grouped by a categorical variable. These CDFs can then be called to return probabilities for any given x value.

Usage

get_cdfs(df)

Arguments

df

A data frame.

Value

function(xvar, groupby = "1")

  • xvar. String, name of a continuous variable over which the empirical CDF to be calculated.

  • groupby. String, name of a categorical variable for subsetting the data frame. Default = "1", indicating no such variable is supplied.

Examples

library(ezplot)

df = data.frame(x = c(rnorm(100, 0, 3), rnorm(100, 0, 10)), gp = gl(2, 100))
CDF = get_cdfs(df)

CDF_x = CDF('x') # returns a single CDF that can be called on a number
CDF_x(0.23)

CDFs_x_by_gp = CDF('x', 'gp') # returns a list of CDFs, one for each group
sapply(CDFs_x_by_gp, function(f) f(0.23))

gmlang/ezplot documentation built on Sept. 18, 2022, 6:33 a.m.