How to fit data to a Gaussian distribution
Show older comments
Hi there, I'm quite new of MatLab and thus I hope you'll be patient with me.
I need to fit a given distribution (an actual one I generated from subjects) to its theorical Gaussian and get the R square value.
The Model (Gaussian distribution) I use is: Y=Amplitude*exp(-0.5*((X-Mean)/SD)^2) Amplitude is the height of the centre of the distribution in Y units. Mean is the X value at the centre of the distribution. SD is a measure of the width of the distribution, in the same units as X.
Rules for initial values Parameter Initial value Rule Amplitude 1.0 *YMAX No constraint MEAN 1.0 *(Value of X at YMAX) No constraint SD 0.1 *(XMAX-XMIN) Must be > 0.0
I use to do that with GraphPad and SPSS but I'd like to be able to do that in MatLab too. I need some good soul to tel me, step by step, how to do that in MatLab.... Please
Answers (2)
Study the documentaion for FMINSEARCH and consider the following
fminsearch(@(p) norm( p(1).*exp(-0.5.*((X(:)-p(2))./p(3)).^2) -Y(:)), p0)
3 Comments
Lorenzo
on 9 Jan 2013
Matt J
on 9 Jan 2013
Here's a simpler example where I fit the slope p(1) and intercept p(2) of a line:
>>x=0:.01:1;
y=2*x+1;
initialguess=[0,0];
>> [pfit,residual]=fminsearch(@(p) norm(p(1)*x+p(2)-y) , initialguess)
pfit =
2.0000 1.0000
residual =
2.1512e-04
In reality, you would use POLYFIT to fit a line or any other polynomial, of course. This was just an example.
Lorenzo
on 10 Jan 2013
Tom Lane
on 11 Jan 2013
0 votes
Similar question in the newsgroup: http://www.mathworks.com/matlabcentral/newsreader/view_thread/325685
Categories
Find more on Get Started with Curve Fitting Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!