# Curve fitting using an asymmetrical sigmoid function

This is probably going to sound trivial, as I am new to Mathematica and still busy reading the Getting Started materials.

I have a series of observations:

[(duration, speed sustained for duration), ...]

Due to the nature of the context in which these observations are made, I am confident these observations can be well fitted to a curve of this kind:

It looks like a logistic function or some kind of sigmoid curve.

But, it's not symmetrical. The first plateau could potentially be longer or shorter. The middle "descent" could more or less sharp and extend over a wider or narrower range of durations. Finally, the low plateau to the right could also be shorter or longer.

How can I use Mathematica to find the sigmoid curve that best fit my data?

My first attempts were in Mathematical Online, but it gives me quite a few errors when I try to use FindFit, NonlinearModelFit, etc.

Sometimes, I'll have very few points, sometimes I'll have more points to work with. Here is an example with only 4 points: (58.41, 325), (174.17, 311), (377.06, 294), (691.51, 281)

Any hints appreciated...

• Are you asking for a formula which may fit well? That isn't really on topic here, as it's unrelated to Mathematica. But if you can come up with an S-shape function $f(x)$, you can always translate and scale it to make it not symmetric around the origin: $f_0 + \alpha f( (x - x_0) \beta )$. There are many different S-shape functions, such as $1/(1+e^x)$, $\arctan x$, etc. – Szabolcs Nov 6 '16 at 20:00
• It is more likely that you will get a useful answer if you show sample data to fit. – Szabolcs Nov 6 '16 at 20:01
• To sound like a broken record to some here: While I understand that's the data you have, you have no business fitting a curve with just 4 points ESPECIALLY when you don't even know the form of the curve. – JimB Nov 6 '16 at 21:24
• @JimBaldwin Sorry for forcing you into the role of a broken record. I have much to learn. I agree it would be insane to anticipate a complex form or any particular form with only 4 points. But, I derive the anticipated form (some kind of asymmetrical sigmoid curve) from a great number of other experiments that include many more points and some "perfect cases" such as the one given in the picture. In other words, the 4-point example is only an instance of the general case, if more observations had been taken, the overall shape would have been the same. – L_R_T Nov 6 '16 at 21:33
• It appears to be an asymmetrical sygmoidal function which follows: f(x)= d+ (a-d)/(1+(x/c)^b). A is the minimal assymptote B is Hill's slope C is the inflection point D is the maximum asymptote – swjk Aug 19 '17 at 3:20

To follow up on @Szabolcs comment you might consider a scaled logistic function:

$$lower+(upper-lower)/(1+\exp(a+b x))$$

But with 5 parameters (lower, upper, a, b, and error variance) to estimate you'll need at least 5 data points. Here's an example with 6 data points.

data = {{Log10[1], 7.5}, {Log10[100], 6.9}, {Log10[500], 4.95}, {Log10[1000], 2.6},
{Log10[10000], 0.95}};
nlm = NonlinearModelFit[data,
lower + (upper - lower)/(1 + Exp[a + b x]),
{{lower, 0.8}, {upper, 7.8}, a, b}, x];
nlm["BestFitParameters"]
(* {lower -> 0.9118092650911604, upper -> 7.2768093930069275,
a -> -13.762511622296703, b -> 4.911994387570109} *)


with the following fit:

mpb = nlm["MeanPredictionBands"];
Show[ListPlot[data, PlotRange -> {{-0.1, 4.1}, {-4, 12}}],
Plot[{nlm[x], mpb}, {x, 0, 4}]]


The wide 95% confidence bands are wide for a reason: not much data. Always produce and listen to the confidence bands. (And even this is optimistic in that this assumes one really knows the form of the underlying function and the variance structure.)

• Thanks, Jim. I have since adopted as a principle that at least 6 data points are required. "And even this is optimistic in that this assumes one really knows the form of the underlying function" -- this point is well understood and accepted. – L_R_T Jan 8 '17 at 21:03

In there are few points available, the best thing is to pre-determine what to be expecting. Linear relationship or any specific quadratic polynomial. Maybe a sinsoidal or any other trigonometric function. There is no guest work that will do you any good here. If you do not have guest work surrounding your specific problem.

My answer her has nothing to do with Mathematica, but it is a good start to get you going to where to get started using Mathematic to help you.

• Jose, your suggestions may be more appropriate for a comment than for a full answer. – MarcoB Nov 6 '16 at 22:08
• Trust me .. I had previously put a lot of thinking on exactly on your addressing. But , there are times where this answer is all that really make truly sense to contribute. – Jose Enrique Calderon Nov 6 '16 at 22:11
• Let's say during an experiment, you can make 4 or 1000 observations. Each observation has a cost. If you make 1000 observations, you obtain a plot that is well approximated by a sigmoid-like curve. I added a second image to the original question. It contains 4 key points on the curve. Can Mathematica help me figure out what the curve would look like if I had taken 1000 observations? My guess is that it should be able to if I come with a good pair of expr, pars for: FindFit[{{58.41, 325}, {174.17, 311}, {377.06, 294}, {691.51, 281}}, expr, pars, x] – L_R_T Nov 6 '16 at 23:49