Get the minimum residual and the minimum distance in terms of the x axis using solver functions?

3 visualizzazioni (ultimi 30 giorni)
I have a set of linear data and I used regression to best fit the data. I m trying to identify the data point that has the smallest distance in terms of the x axis and the smallest residual. So it appears that I need a solver function for finding the optimal value of two variables. So, looking at some of the solver functions, they require the fun of the polynomial you are using. So if I define this function based on the polynomials of the best fit line, how do I get the optimal residual at one data point. I was trying to use fminsearch but it seems that this is for multivariables of a single function. So maybe there is a way i can define a function that describes both the best fit line as well as the residuals. Like a 3D plot? Alternatively the lagrange multiplier seems to use 2 functions, so maybe I can do something like that. Any suggestions, 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');

Risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by