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)).

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.

Value

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

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.

Examples

# Standard logit(0.1)
#> [1] -2.197225
invlogit(-2)
#> [1] 0.1192029
# 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)