Computes the logistic (i.e., sigmoid) function with configurable slope, midpoint, and upper asymptote.
Usage
logistic(x, slope = 1, midpoint = 0, upper = 1)
sigmoid(x, slope = 1, midpoint = 0, upper = 1)Details
The logistic function is a smooth S-shaped curve bounded between 0 and upper.
It transitions from near 0 to near upper around the midpoint, with the steepness
of this transition controlled by slope.
Examples
logistic(0)
#> [1] 0.5
# equivalent:
sigmoid(0)
#> [1] 0.5
logistic(1, slope = 5, midpoint = 0.5, upper = 10)
#> [1] 9.241418
# Visualize different slopes
x <- seq(-5, 5, length.out = 1000)
plot(x, logistic(x, slope = 1), type = "l", ylab = "f(x)", ylim = c(0, 1))
lines(x, logistic(x, slope = 5), col = "blue")
lines(x, logistic(x, slope = 50), col = "red")
legend("topleft", legend = c("slope = 1", "slope = 5", "slope = 50"),
col = c("black", "blue", "red"), lty = 1)