Last active
November 26, 2019 08:13
-
-
Save kyrcha/74ec4894994e6a8a6d89 to your computer and use it in GitHub Desktop.
Fitting a sigmoind curve in R
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# function needed for visualization purposes | |
sigmoid = function(params, x) { | |
params[1] / (1 + exp(-params[2] * (x - params[3]))) | |
} | |
x = 1:53 | |
y = c(0,0,0,0,0,0,0,0,0,0,0,0,0,0.1,0.18,0.18,0.18,0.33,0.33,0.33,0.33,0.41, | |
0.41,0.41,0.41,0.41,0.41,0.5,0.5,0.5,0.5,0.68,0.58,0.58,0.68,0.83,0.83,0.83, | |
0.74,0.74,0.74,0.83,0.83,0.9,0.9,0.9,1,1,1,1,1,1,1) | |
# fitting code | |
fitmodel <- nls(y~a/(1 + exp(-b * (x-c))), start=list(a=1,b=.5,c=25)) | |
# visualization code | |
# get the coefficients using the coef function | |
params=coef(fitmodel) | |
y2 <- sigmoid(params,x) | |
plot(y2,type="l") | |
points(y) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment