fitting 1D data to y=x polynomial (cftool)
显示 更早的评论
In an experiment vector y is a measurement of vector x. I want to fit polynomial y=x to this data and find R^2. When I use polyfit(x,y,1), MATLAB gives me y=ax+b but I am interested in knowing the R^2 when the data is fitted to y=x. Could someone please help me on that?
I found cftool which can solve my problem. Could someone tell me how I can retrieve R^2 from the analysis of cftool when the data is fitted to a polynomial?
Thanks.
1 个评论
Jesús Lucio
2011-9-5
Hello. I think you only have to evaluate the fitted polynomial at the same abscissas and compare with the original ordinates:
poly = polyfit(x, y, 1);
yfit = polyval(poly, x);
cc = corrcoef(y, yfit);
R2 = cc(1, 2).^2;
回答(1 个)
Sean de Wolski
2011-7-7
0 个投票
5 个评论
AP
2011-7-7
Sean de Wolski
2011-7-7
No reason for cftool. Did you look at Matt's answer?
AP
2011-7-7
Sean de Wolski
2011-7-7
All you need to do is change the vandermonde matrix, in his example 'F'
Sean de Wolski
2011-7-7
For zeroth order fit; i.e. what you want, it will just be x.^0, aka ones(size(x)) aka the mean.
类别
在 帮助中心 和 File Exchange 中查找有关 Linear and Nonlinear Regression 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!