Transform a between bound and unbounded scales.
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.3788464 0.3648040 0.4510225 0.7326628 0.6156200 0.8123456 0.4121611
#> [8] 0.1660213 0.9048911 0.1331326
# bound vector of unbounded values to [100, 200]
expit(myvec, lower_bound = 100, upper_bound = 200)
#> [1] 137.8846 136.4804 145.1023 173.2663 161.5620 181.2346 141.2161 116.6021
#> [9] 190.4891 113.3133