The most likely point closest to best fit line?

조회 수: 5 (최근 30일)
Ronan
Ronan 2015년 11월 30일
댓글: Ronan 2015년 12월 1일
So I m using regression to best fit a plot of data. Each data point is represented by distance and value. If the residuals are defined as the error of the points away from the best fit line, I can plot a normal probability density function plot of the likelihood of the residuals. So I have 2 plots. The first plot shows distance(of points, not residual distance) vs value and the second plot shows residuals vs density(normal probability density function). I m trying to find the minimum distance of the points in terms of the first plots x values and at the same time chose the point that has the smallest residual (closest to best fit line) based on the normal probability density function. So I cant just pick the minimum value of the residuals because the data may be different each time. My knowledge of statistics is very limited so i m not sure if this is the best way to find the most likely point that is closest to best fit line. Attached is the code,
yVals = zeros(1,10);
yVals(1,1) = 2;
yVals(1,2) = 5;
yVals(1,3) = 6;
yVals(1,4) = 9;
yVals(1,5) = 14;
yVals(1,6) = 18;
yVals(1,7) = 25;
yVals(1,8) = 21;
yVals(1,9) = 23;
yVals(1,10) = 27;
xVals = 1:10;
xVals = xVals';
yVals = yVals/max(yVals);
yVals = yVals'
scatter(xVals, yVals);
hold on;
[logitCoef,dev, stats] = glmfit(xVals,yVals,'binomial','logit');
logitFit = glmval(logitCoef,xVals,'logit');
figure(1);
plot(xVals,logitFit,'g-','MarkerSize', 2 );xlabel('Distance'); ylabel('Value');
legend('logit');
A = stats.resid;
M = mean(A);
S = std(A);
MAX = max(A);
MIN = min(A);
[residuals residualIndex] = sort(stats.resid);
figure(2);
PDF = normpdf(residuals, M, S);
plot(residuals, PDF);xlabel('Residuals'); ylabel('Density');
  댓글 수: 1
Ronan
Ronan 2015년 11월 30일
So if you look at the peak of the normal probability density function it contains the points that are on the best fit line so they are likely. However I want to find the most likely at the smallest distance. eg the very first point has a very small distance but has a larger residual then the most likely residuals. So perhaps I need to get the weighted sum of smallest distance/smallest residual to identify the optimal one? Any suggestions?

댓글을 달려면 로그인하십시오.

답변 (1개)

the cyclist
the cyclist 2015년 11월 30일
It sounds like you are effectively doing an optimization problem. If you have the Optimization Toolbox -- I don't, so I can't help you specifically -- there will be lots of tools available to you.
In core MATLAB, you might just be able to use fminsearch.
Regardless, you are going to have to decide on the function you want to optimize. MATLAB won't be able to do that for you.
  댓글 수: 1
Ronan
Ronan 2015년 12월 1일
thank you for your suggestion. I will try out fminsearch once i get to grips with applying the function parameter fun in regards to my application.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Linear and Nonlinear Regression에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by