g_wcdf: Weighted cumulative distribution function (CDF)-based...

View source: R/helper_functions.R

g_wcdfR Documentation

Weighted cumulative distribution function (CDF)-based transformation

Description

Compute a CDF-based transformation using the observed count data. The CDF can be estimated nonparametrically or parametrically based on the Poisson or Negative-Binomial distributions. In the parametric case, the parameters are determined based on the moments of y. Note that this is a fixed quantity and does not come with uncertainty quantification. This function incorporates positive weights to determine the CDFs.

Usage

g_wcdf(y, distribution = "np", weights = NULL)

Arguments

y

n x 1 vector of observed counts

distribution

the distribution used for the CDF; must be one of

  • "np" (empirical CDF)

  • "pois" (moment-matched marginal Poisson CDF)

  • "neg-bin" (moment-matched marginal Negative Binomial CDF)

weights

an optional vector of weights

Value

A smooth monotone function which can be used for evaluations of the transformation.

Examples

# Sample some data:
y = rpois(n = 500, lambda = 5)
# And some weights:
w = runif(n = 500, min = 0, max = 10)

# Empirical CDF version:
g_np = g_wcdf(y, distribution = 'np', weights = w)

# Poisson version:
g_pois = g_wcdf(y, distribution = 'pois', weights = w)

# Negative binomial version:
g_negbin = g_wcdf(y, distribution = 'neg-bin', weights = w)

# Plot together:
t = 1:max(y) # grid
plot(t, g_np(t), type='l')
lines(t, g_pois(t), lty = 2)
lines(t, g_negbin(t), lty = 3)


drkowal/rSTAR documentation built on July 5, 2023, 2:18 p.m.