logit_utils: Logit and inverse logit functions

logit_utilsR Documentation

Logit and inverse logit functions

Description

Logit and inverse logit functions, with option to perform a transformation such that the domain in non-logit space is as specified (standard is (0, 1)).

Usage

logit(x, domain_lower = 0, domain_upper = 1)

invlogit(x, domain_lower = 0, domain_upper = 1)

check_logit_inputs(x, domain_lower, domain_upper)

Arguments

x

[numeric()]
Value to take the logit or inverse logit of.

domain_lower

[numeric()]
Lower bound of domain in non-logit space, inclusive. Default 0. Logit at lower bound is -Inf.

domain_upper

[numeric()]
Upper bound of domain in non-logit space, inclusive. Default 1. Logit at upper bound is Inf.

Details

Standard:

  • logit (x) = log (x / (1-x))

  • inverse logit (x) = exp (x) / (1 + exp (x))

Optional logit with transformed domain:

  • logit (x, l, u) = log (x' / (1 - x')) where x' = (x - l) / (u - l)

  • inverse logit (x, l, u) = ( exp (x) / (1 + exp (x)) ) * (u - l) + l

Other notes: Values of x outside of (domain_lower, domain_upper) will return NaN and result in a warning from logit function.

Value

[numeric()]
The calculated logit or inverse logit value.

Examples

# Standard
logit(0.1)
invlogit(-2)

# Domain shift
x <- stats::runif(n = 100, min = 10, max = 20)
logit_x <- logit(x, domain_lower = 10, domain_upper = 20)
x_again <- invlogit(logit_x, domain_lower = 10, domain_upper = 20)


ihmeuw-demographics/demUtils documentation built on Feb. 27, 2024, 1:25 p.m.