How to fit data to a Gaussian distribution
이전 댓글 표시
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
답변 (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
Lorenzo
2013년 1월 9일
Matt J
2013년 1월 9일
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
2013년 1월 10일
Tom Lane
2013년 1월 11일
0 개 추천
Similar question in the newsgroup: http://www.mathworks.com/matlabcentral/newsreader/view_thread/325685
카테고리
도움말 센터 및 File Exchange에서 Get Started with Curve Fitting Toolbox에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!