4

I have a lot of data, and I think it is possible to fit it to a sigmoid (this thought based on my eye-sight, not a mathematical formula).

How can I find the parametric form with statistically significant explanatory power of the best sigmoid for my data?

Thanks!

user3094996
  • 53
  • 1
  • 1
  • 7
  • Ratios of polynomials (of equal degree) can give very good fits to sigmoids if set up correctly and you can ensure the denominator has no zeros on your approximation range. This might be overkill though but hard to say based on your question. – mathematician1975 Nov 02 '15 at 10:38
  • 1
    you could try with lsqnonlin http://au.mathworks.com/help/optim/ug/lsqnonlin.html – gregswiss Nov 02 '15 at 10:54
  • 1
    Possible duplicate of [MATLAB fitting of data to a user given function](http://stackoverflow.com/questions/12970043/matlab-fitting-of-data-to-a-user-given-function) – tashuhka Nov 02 '15 at 11:31
  • Check out Matlab's fit() function and post some data and what you've tried. Matlab also has a built in sigmoidal membership function see [here](http://uk.mathworks.com/help/fuzzy/sigmf.html?refresh=true) to use as a fit function. You could also try an error function (erf()). – lhcgeneva Nov 02 '15 at 12:42

1 Answers1

4

One great thing that you can do is to use the "Curve fitting" App in Matlab. you can find it in APPS, in "Math, statistics and optimization" section.

over there you can choose your x and y data and the function that you want to fit over them (you can enter custom equations such as sigmoid).

Then you can see the fitting results on a plot, also, fitting parameters are shown.

If you were satisfied with the results and you want to use them inside a code, simply hit the generate code under the File tab. See Here you can see the details in this screenshot i took. after pressing the generate code button, matlab will create a fuction that will give the same result. what i like to do is just copy the parts i need in this case:

 enter code here
 [xData, yData] = prepareCurveData( x, y );

 % Set up fittype and options.
ft = fittype( 'a/(1+exp(-b*x))', 'independent', 'x', 'dependent', 'y' );
opts = fitoptions( 'Method', 'NonlinearLeastSquares' );
opts.Display = 'Off';
opts.StartPoint = [0.957166948242946 0.485375648722841];

% Fit model to data.
[fitresult, gof] = fit( xData, yData, ft, opts );

as you can see matlab adds the necessary details and now you can access fitting parameters using fitresult. for example-> fitresult.a

HoomanShan
  • 164
  • 7
  • 1
    Just be careful, the fittype in the code and the image do not correspond. – lhcgeneva Nov 04 '15 at 10:16
  • Because your fittype in the image is a sigmoid (`a/(1+exp(-bx)`) whereas your code is an exponential (`a +(b-a)*exp(-c*x)`) – lhcgeneva Nov 04 '15 at 11:01
  • 1
    @lhcgeneva Sorry my bad. – HoomanShan Nov 04 '15 at 11:04
  • @lhcgeneva I'm new to stack overflow, I have some editing suggestions for this post and i think one was from you. what can i do with them? should i like click on something to approve them? – HoomanShan Nov 04 '15 at 11:11
  • 1
    My edit was supposed to correct the above mistake, but was rejected as an edit, because apparently it was too much of a change to be edited without your approval ;). So I suggest you just leave it the way it is. Except, there is one more mistake, because your sigmoid only has two parameters (a and b) but you are giving it three start points, you should delete one of them. – lhcgeneva Nov 04 '15 at 11:18
  • @HoomanShan if you have less than 2k reputation edits you make to a post not your own are "suggested", which means 3 people with more than 2k reputation will have to judge whether it is a useful and correct edit and approve or reject accordingly. The owner of the post however, is able to single handedly reject and approve edits to their own posts, thus if you feel an edit made to your post is (not) useful approve (reject) it. Users with more than 2k rep will not have this restriction and their edits are instantly applied, though you can roll them back within the edit menu. – Adriaan Nov 04 '15 at 11:27
  • 1
    @Adriaan Thanks you very much for your explanation! I hope to become a useful member of this community oneday – HoomanShan Nov 04 '15 at 11:35