Using R to fit a Sigmoidal Curve

后端 未结 3 1449
悲哀的现实
悲哀的现实 2020-12-29 12:14

I have read a post ( Sigmoidal Curve Fit in R ). It was labeled duplicated, but I can\'t see anything related with the posts. And the answer given for the posts was not enou

3条回答
  •  太阳男子
    2020-12-29 12:50

    I see two issues.

    1. the default algorithm of nls is very sensitive to the starting parameter. In your example data I found it useful to use algorithm='port'. Alternatively switching to a "robust" implementation might also help.

    2. It helps understanding the role of the parameter in your model.

    The simple interpretation for your model is: The sigmoid goes in y from 0 to a. It reaches the "half way" point at x=c. b has the role of a slope, and if negative the model would go from a to 0 instead.

    Specifically to the test data posted by you I would estimate the start values as following:

    • First thing I notice - your data is not exactly 'close' to zero so maybe it might be useful to add an offset d which is around 1000.
    • a is then 5000 or greater
    • c is somewhere greater 2 - maybe 3
    • b one needs to guess - from x 2 to 3.5 your signal jumps from 1000 to 6000 gives 5000 difference - divided by a - a slope of 1/1.5 = 0.66 or greater... lets round to one.

    So ultimately using the formula

    fitmodel <- nls(y ~a/(1 + exp(-b * (x-c)) ) + d, start=list(a=5000,b=1,c=3, d=1000))
    

    gives a fit (also works without the d). Trying around I found setting algorithm='port' made the command even less sensitive to the start values.

提交回复
热议问题