At this point these notes on R and statistics are mostly to myself. Hopefully over time they will evolve into something that can be more generally useful.
Tuesday, March 17, 2015
Wednesday, November 12, 2014
Sigmoids
Link to the Rmd file on GitHub
Sigmoid Function
\(\frac{p_1}{(1+e^{-p_2 \times (x - p_3)})}\)
p1 is the full scale from 0 to p1. For logistic regression it is 1. In the later examples it will be hardcoded as 1.
p2 is the sharpness of change.
p3 x position of the 50% height.
sigmoid = function(x, p1, p2, p3) {p1 / (1 + exp(-p2 * (x - p3)))}
curve(sigmoid(x, p1=1, p2=2, p3=-3), from=-10, to=+10)
abline(v=-3, lty=2)
Sigmoid that starts at zero.
Sometimes we want to convert a parameter that varies only as \((0,+\infty)\) instead of \((-\infty,+\infty)\). First, to convert x form \((0,+\infty)\) to \((-\infty,+\infty)\) we’ll take the log. The formular for the sigmoid/logistic curve will be transformed as…
\(\frac{1}{(1+e^{-p_2 \times (log(\frac{x}{p_3}))})}\)
sigmoid2 = function(x, p2, p3) {1 / (1 + exp(-p2 * (log(x/p3))))}
curve(sigmoid2(x, p2=20, p3=3), from=0.01, to=+10)
abline(v=3, lty=2)
Transformed Positive Sigmoid
If we move p2 inside the log followed by logarithm exponentiation we’ll get
\(\frac{1}{1+(\frac{p_3}{x})^{p_2}}\)
sigmoid3 = function(x, p2, p3) {1 / (1 + (p3/x)^p2)}
curve(sigmoid3(x, p2=20, p3=3), from=0.01, to=+10)
abline(v=3, lty=2)
# smoother
curve(sigmoid3(x, p2=4, p3=3), from=0.01, to=+10, add=T, col='navyblue')
In case we need to model an opposite dependency the trend has to be reversed. For example we want to formalize a probablity of chemical compound being missed in analysis as a function of intensity.
\(\frac{1}{1+(\frac{x}{p_3})^{p_2}}\)
sigmoid3 = function(x, p2, p3) {1 / (1 + (x/p3)^p2)}
curve(sigmoid3(x, p2=20, p3=3), from=0.01, to=+10)
abline(v=3, lty=2)
# smoother
curve(sigmoid3(x, p2=4, p3=3), from=0.01, to=+10, add=T, col='navyblue')
Arctangent
Another way of modeling sigmoid dependency.
\(\frac{2}{\pi} \times arctan((x-p3) \times p2)\)
The notation of parameters as above:
p2 - shaprness
p3 - position of 50% change
sigmoid2 = function(x, sharpness, threshold) (2/pi)*atan((x-threshold)*sharpness)
curve(sigmoid2(x, sharpness=1, threshold=2), from=-10, to=+10)
curve(sigmoid2(x, sharpness=3, threshold=2), from=-10, to=+10, add=TRUE, col='blue')
abline(v=2)
Checking font availability on Mac fc-list : family | grep "Fira Code" or system_profiler -json SPFontsDataType | grep \...
-
http://www.liacs.nl/~hoogeboo/mcb/nature_primer.html
-
E.g. we have a list of dictionaries x = [{'a':1,'b':3}, {'a':3,'b':2}, {'a':2,'b':1}] x....