MATLAB Answers


Goodness of Fit from Gaussian Fit

Asked by Benjamin Zaugg on 24 Apr 2013
Hi there, I have to analyze data (specificly area under curve) from an table with 2 coloumns and abou 1700 rows. I have used a a fit on the data:
fit_1 = fit(table([x0:x1],[1]),table([x0:x1],[2]),'gauss4');
this gives me the CFIT file named 'fit_1'
However, I would like to find out the Goodness of the fit (R squared) of my fit_1 compared to my table data, without using the cftool but integrate it into my existing function which I wrote.
Can somebody tell me if there is the possibility to do so outside of cftool and where I could find Information of how to do so?
Thanks a lot! Sorry for any typos & lack of knowledge (first post)

  1 Comment

Sign in to comment.

1 Answer

Answer by Eric
on 24 Apr 2013
Edited by Eric
on 24 Apr 2013

I use the following:
ybar = mean(y); %Mean of the data
sst = sum( (y - ybar).^2 ); %Total sum of squares
gof.sse = sum( (y - fit_vec).^2 ); %Residual sum of squares
gof.rsquare = 1 - gof.sse/sst;
See as a reference for the equation for gof.rsquare.
In this code y is the data and fit_vec is the fitted data.


Sign in to comment.