Good afternoon, I'm quite a newbie in MatLab, and I'm trying to use the fminsearch function to fit both a normal and a sigmoidal/logistic models to my data. At the moment, I'm using the following formula for the logistic: [par fit]=fminsearch(@(p) norm(1./(1+exp(-p(1).*(X-p(2)))) -Y), [1,1]);
X corrisponds to 10 different location of a stimulus, while Y is the answer (0/1) given to the stimulus. However, the outcomes I obtain in this way seem totally untrustworthy, even if the formula is the correct logistic formula. There is something I'm missing?
Thank you in advance, Alessandro

 採用された回答

Star Strider
Star Strider 2018 年 4 月 19 日

0 投票

When in doubt, simulate:

p = [2 5];
X = 0:20;
Yfcn = @(p,X) 1./(1+exp(-p(1).*(X-p(2))));
Y = Yfcn(p,X) + 0.1*randn(size(X));
[par fit]=fminsearch(@(p) norm(1./(1+exp(-p(1).*(X-p(2)))) -Y), [1,1])
figure(1)
plot(X, Y, 'p')
hold on
plot(X, Yfcn(par,X), '-r')
hold off
grid

It looks good to me, and the parameter estimates are appropriate. If you are not getting reasonable results, experiment with different initial parameter estimates.

その他の回答 (3 件)

Alessandro Zanini
Alessandro Zanini 2018 年 4 月 19 日

0 投票

Thank you so much! The simulation runs perfectly, so I think I have problems with the X: probably only 10 positions are insufficient for the sigmoid

1 件のコメント

Star Strider
Star Strider 2018 年 4 月 19 日
As always, my pleasure!
You have only 2 parameters, so 10 data points should be enough to provide good parameter estimates. The fminsearch algorithm is derivative-free, although it still requires initial parameter estimates that are reasonably close to the optimal estimates. I would continue to vary the initial estimates across a wide range of values to see if you can get a good fit. The initial estimate for ‘p(1)’ can be any positive value. An appropriate initial estimate for ‘p(2)’ would be mean(X).

サインインしてコメントする。

Alessandro Zanini
Alessandro Zanini 2018 年 4 月 19 日

0 投票

Correct. Modifying the parameters the curve fits without problems, even in 10 positions. Thanks!

1 件のコメント

Star Strider
Star Strider 2018 年 4 月 19 日
As always, my pleasure!

サインインしてコメントする。

Jeff Miller
Jeff Miller 2018 年 4 月 20 日
編集済み: Jeff Miller 2018 年 4 月 20 日

0 投票

Alessandro, it sounds like you are fitting probit models and/or psychometric functions. If so, you might find some very useful routines here: Cupid . DemoProbit.m shows some examples of how you could fit such models with various underlying distributions (normal, logistic, etc).

3 件のコメント

Alessandro Zanini
Alessandro Zanini 2018 年 4 月 20 日
Thanks! But the link leads to a "not existing" page
Jeff Miller
Jeff Miller 2018 年 4 月 20 日
Sorry, here is the link in plain text: https://github.com/milleratotago/Cupid
Alessandro Zanini
Alessandro Zanini 2018 年 4 月 20 日
Thanks again!

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeGet Started with Curve Fitting Toolbox についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by