Improving the fitting of data

5 ビュー (過去 30 日間)
Gina Carts
Gina Carts 2019 年 3 月 13 日
コメント済み: Image Analyst 2019 年 3 月 14 日
I have a small group of people (n=15). For each person I have the age and a blood measurement. The relationship between the age and the blood measurement is linear (please look at the attached figure).
I make the assumption that my data can be described by the equation y= -ax+b (I want to keep it simple for now). I've been told that I can use Matlab to improve the fitting of these data (i.e. to bring the dots that look like outliers closer to the straight line). I have no idea how to do that though.
Any suggestion/help would be greatly appreciated.
example.png

回答 (2 件)

Kevin Phung
Kevin Phung 2019 年 3 月 13 日
編集済み: Kevin Phung 2019 年 3 月 13 日
the polyfit and polyval functions will help you here:
also, just for the sake of principles, you should never try to fit your data to your model (bringing the dots closer to the line), but rather find a model that fits your data.
here's a quick example:
x = 1:10; %x data
y = [6 10 12 12 14 15 17 20 24 25]; %ydata
p = polyfit(x,y,1) % p returns the slope and y intercept (your a and your b)
y2 = polyval(p,x) %create a set of y values based on x, a, b.
figure
plot(x,b,'ro',x,y2,'b')
if a linear model doesnt work, you can change the degree of the polynomial with the 3rd argument of polyfit.
  3 件のコメント
Kevin Phung
Kevin Phung 2019 年 3 月 13 日
oops, i meant to put
plot(x,y,'ro',x,y2,'b')
Image Analyst
Image Analyst 2019 年 3 月 14 日
Gina, so now Kevin and I are saying the same thing:
  1. your data is your data and can't "move", and
  2. the linear fit that MATLAB gives you, and we showed you how to use, is already the best fit you can get for a line, and
  3. if you need a better fit you need to try a higher order polynomial.
So, what are you going to do? What I'd do is what I suggested in my answer, and that is to collect very many more data points before deciding on a model.

サインインしてコメントする。


Image Analyst
Image Analyst 2019 年 3 月 13 日
I don't think the fit can be improved unless you assume a different model (like higher order polynomial or whatever). That looks like a linear fit like what you'd get from
coefficients = polyfit(x, y, 1)
a = -coefficients(1);
b = coefficients(2);
and the fit is what it is. You can't make the line get any closer to the points since the line it gives you is already the closest overall to the points that is possible.
Now if you want to go to a higher order, you could do
coefficients = polyfit(x, y, 3)
fittedY = polyval(coefficients, x)
You can see that it's no more complicated than the linear fit you wanted to "keep it simple". So just pick the best one. But you can't pick the best model on only 15 sample points. I'd get data from a few hundred patients/subjects and then look at the scatterplot and see what you think the best model would be.

カテゴリ

Help Center および File ExchangeGet Started with Curve Fitting Toolbox についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by