Skip to contents

Transform a between bound and unbounded scales.

Usage

logit(x, lower_bound = 0, upper_bound = 1, base = exp(1))

expit(x, lower_bound = 0, upper_bound = 1, base = exp(1))

Arguments

x

Value to be rescaled.

lower_bound

Lower bound of x; defaults to 0.

upper_bound

Upper bound of x; defaults to 1.

base

Base used for log-transform, defaults to exp(1) = e

Details

logit() will transform a value on a bound scale to an unbound scale, while expit() performs the reverse transformation. Values at the lower/upper bounds correspond to -Inf/Inf on the unbounded scale. Uses the natural base, e, by default, but other bases can be passed to the parameter base.

Examples

# unbound vector of values bound between [0, 1]
myvec <- seq(0, 10, 1)/10
logit(myvec)
#>  [1]       -Inf -2.1972246 -1.3862944 -0.8472979 -0.4054651  0.0000000
#>  [7]  0.4054651  0.8472979  1.3862944  2.1972246        Inf

# unbound vector of values between [100, 200]
myvec <- seq(100, 200, 10)
logit(myvec, lower_bound = 100, upper_bound = 200)
#>  [1]       -Inf -2.1972246 -1.3862944 -0.8472979 -0.4054651  0.0000000
#>  [7]  0.4054651  0.8472979  1.3862944  2.1972246        Inf

# bound vector of unbounded values to [0, 1]
myvec <- rnorm(10)
expit(myvec)
#>  [1] 0.4665508 0.1289710 0.4306408 0.4222738 0.7440846 0.5175016 0.3454447
#>  [8] 0.4875114 0.4374584 0.6094015

# bound vector of unbounded values to [100, 200]
expit(myvec, lower_bound = 100, upper_bound = 200)
#>  [1] 146.6551 112.8971 143.0641 142.2274 174.4085 151.7502 134.5445 148.7511
#>  [9] 143.7458 160.9401