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 で Univariate Discrete Distributions についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!