MATLAB Answers

0

Improving the fitting of data

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

  0 件のコメント

サインイン to comment.

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 件のコメント

Gina Carts 2019 年 3 月 13 日
I tried to plot the figure plot(a,b,'ro',a, y2,'b') but I only got a single dot. Is that what am I suppose to plot?
Kevin Phung
2019 年 3 月 13 日
oops, i meant to put
plot(x,y,'ro',x,y2,'b')
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.

サインイン to comment.


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.

  0 件のコメント

サインイン to comment.



Translated by