I'm trying to fit data. I assume that the association between dependent and indepdent variable is of the form


I also know that my data are ressemble either an asymptotic function so that


or a sigmoid function so that

$$ R(x) = \frac{\mathrm{1} }{\mathrm{1} + e^{(\frac{{c-x}} {\mathrm{d}})}} $$

How can I find $a$, $b$, $c$ and $d$ in each of those situations?

  • $\begingroup$ The $a$ and $b$ in $R$ are really the same as the ones in $aR(x)+b$? $\endgroup$
    – paf
    Jul 17, 2018 at 7:15
  • $\begingroup$ Thanks for your comment @paf. No indeed there are not the same. I changed the question accordingly $\endgroup$
    – ecjb
    Jul 17, 2018 at 7:20

1 Answer 1


In your previous problem, you had the advantage that your models were simple enough to admit a linearization. If you are willing to accept, for example, that $$T(y)=R(x,a,b)$$ instead of $$T(y)=aR(x,a,b)+b,$$ then as a practical matter you can do the following in each scenario:

  • Estimate $\tan\left(T(y)\right)$ given $x$ using linear regression. The slope is $m=\frac{1}{b}$, and the intercept is $k=-\frac{a}{b}$ so that $b=\frac{1}{m}$ and $a=-\frac{k}{m}$.
  • Estimate $\log\left(\frac{T(y)}{1-T(y)}\right)$ given $x$ using linear regression. The slope and intercept are the same as before so that $b=\frac{1}{m}$ and $a=-\frac{k}{m}$.

Without some sort of similar simplification, the linear regression you have been using no longer suffices, and you need to perform a more complicated regression. The best way to do this varies a bit based on your data and your desired goals, but a reasonably common way to start is to use the Mean Squared Error.

To apply MSE, you define an auxiliary error function $$E(a,b,c,d)=\sum_{i}(T(y_i)-aR(x_i,c,d)+b)^2,$$ where the $x_i$ and $y_i$ represent the observed data you have. There are a variety of black-box solvers to take care of this for you (recall scipy.optimize.curve_fit from before), or you can attempt to solve it analytically.

To solve it analytically, you would want to take the partial derivatives of $E$ with respect to each of $a,b,c,d$ and set those partial derivatives equal to $0$. This gives a system of auxiliary equations to solve. The nonlinearity makes those equations unpleasant at the least, and I'm not certain they have nice closed forms. Even if they did, the quadratic convergence of newton-based function minimizers is likely to make black-box solvers competitive in computer runtime for tiny problems like these.

  • $\begingroup$ Thank you very much again @Hans Musgrave for your insightful and quick answer. Just one more point : will the black box solver scipy.optimize.curve_fit give an explaining model, that is will it give me a sigmoid or asymptotic model or will it use combination of polynomial which will not have anything to do with sigmoid / asymptotic model anymore $\endgroup$
    – ecjb
    Jul 17, 2018 at 7:35
  • $\begingroup$ The solver scipy.optimize.curve_fit minimizes the Mean Squared Error defined above. You hand it any functional you want (including sigmoids) alongside all of your data, and it determines the parameters for you. In this case, it would be a way of finding optimal $a,b,c,d$. Mean Squared Error isn't necessarily always the right choice, but it's rarely a bad choice. $\endgroup$ Jul 17, 2018 at 16:03

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .