The most likely point closest to best fit line?
Mostra commenti meno recenti
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 Commento
Ronan
il 30 Nov 2015
Risposte (1)
the cyclist
il 30 Nov 2015
0 voti
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.
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 Commento
Ronan
il 1 Dic 2015
Categorie
Scopri di più su Linear and Nonlinear Regression in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!