Fitting Cumulative Gaussian Function to data

14 vues (au cours des 30 derniers jours)
Sarah T
Sarah T le 19 Mar 2021
Commenté : Sarah T le 22 Mar 2021
Hello ,
I am trying to fit the cumulative Gaussian Function to my data points, to find out the PSE. So far I used this function:
f = @(b,x) normcdf(x, b(1), b(2)); % Objective Function
NRCF = @(b) norm(y - f(b,x)); % Norm Residual Cost Function
B1 = fminsearch(NRCF, [-1; 5]); % Estimate Parameters
x = 0:5
y = [0.7 0.4 0.2 0.4 0.6 0.9]
I am getting: 1.91293286
However, the correct value should be: 1.81051. Does anyone have ideas? Is there a better way to fit the cumulative function to my data in Matlab?
Thank you for your help :)
  1 commentaire
the cyclist
the cyclist le 19 Mar 2021
After I posted my answer, I happened to notice that you already had a post about this question here. @Matt J also pointed out that the model is a very poor one for your data.
Also, what is "PSE"? I don't recognize that in this context.

Connectez-vous pour commenter.

Réponse acceptée

the cyclist
the cyclist le 19 Mar 2021
I get the same coefficient that you did, using the fitnlm function instead.
This seems to be a terrible model for your data, which is obvious when you plot them. (Always plot the data!) Why did you choose it?
f = @(b,x) normcdf(x, b(1), b(2));
x = 0:5;
y = [0.7 0.4 0.2 0.4 0.6 0.9];
mdl = fitnlm(x,y,f,[1 1])
mdl =
Nonlinear regression model: y ~ normcdf(x,b1,b2) Estimated Coefficients: Estimate SE tStat pValue ________ ______ _______ _______ b1 1.9129 2.238 0.85476 0.44086 b2 7.8396 9.9659 0.78664 0.47548 Number of observations: 6, Error degrees of freedom: 4 Root Mean Squared Error: 0.259 R-Squared: 0.143, Adjusted R-Squared -0.0709 F-statistic vs. zero model: 13, p-value = 0.0177
xq = (-2 : 0.1 : 8)';
yq = predict(mdl,xq);
figure
hold on
hd = plot(x,y,'.');
set(hd,'MarkerSize',24)
hf = plot(xq,yq);
set(hf,'LineWidth',2)
ylim([0 1])
legend([hd,hf],{'data','fit'},'Location','SouthWest')
  4 commentaires
the cyclist
the cyclist le 22 Mar 2021
I'm a little confused by your remark, "That is an interesting model you propose here."
The model is exactly the same as in your original question. I just used a different MATLAB function to find the best fit. There is no "extra" fitting parameter. Your code reports the two coefficients, just the same:
x = 0:5
x = 1×6
0 1 2 3 4 5
y = [0.7 0.4 0.2 0.4 0.6 0.9];
f = @(b,x) normcdf(x, b(1), b(2)); % Objective Function
NRCF = @(b) norm(y - f(b,x)); % Norm Residual Cost Function
B1 = fminsearch(NRCF, [-1; 5]) % Estimate Parameters
B1 = 2×1
1.9129 7.8395
And then, since this is a model that fits a model of the form f(x) = y, all I do in the last part is create a sequence of uniformly space x values, and find the "predicted" y values given by the fitted equation. You could have done that same with your output. Here is a tiny example:
xq = [-1 0 1];
yq = f(B1,xq)
yq = 1×3
0.3551 0.4036 0.4536
I still don't understand why you are trying to fit this function to the data points, which are shaped nothing like a CDF.
Sarah T
Sarah T le 22 Mar 2021
Ah, its true. Basically you also get the same value with 1.91 and not 1.81.
I have a data set for whom I would like calculate psychometric functions. With 80% of my data this works fine, but for some data points I get different values compared to fitiing with CDF in other programs. This counts especially for data that also do not really look like CDF (like the example I posted). That is why I thought I am not using a good model right now in Matlab and there would be possibilities to change the fit.

Connectez-vous pour commenter.

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by