From: Matt J on
"Nathan " <ndn3(a)georgetown.edu.remove.this> wrote in message <hsa4fg$7fv$1(a)fred.mathworks.com>...
> I should have been more specific. While m and b are important, I'd also like to get the MSE, p, and r values for the fit. Ideally, I was looking for a model option for regstats that let me add constraints to the coefficients. Something like regstats(X,Y,[>0]).
=================

Well, once you have m and b, you can certainly calculate residuals, their norm, and any other function based on the residuals that you like. If you have simulated ground truth values, then you can also compute MSE and the like by numerical simulation.

The reason that you're not going to find a turn-the-crank method/code for doing error analysis is that, with the slope constrained positive, the parameter estimator is no longer linear/unbiased. The statistical distribution of the estimate is therefore much harder to calculate analytically.
From: Nathan on
Is there a way to use orthogonal offsets instead of vertical offsets when doing the least squares fitting? I think that may be more of what I am envisioning.

And before it comes up, I am not interested in passing the line through the origin.
From: Bruno Luong on
"Nathan " <ndn3(a)georgetown.edu.remove.this> wrote in message <hsbs46$q21$1(a)fred.mathworks.com>...
> Is there a way to use orthogonal offsets instead of vertical offsets when doing the least squares fitting? I think that may be more of what I am envisioning.

Such regression called TLS (total least square). Numerical method for linear fitting uses SVD. You could google.

Bruno
From: Matt J on
"Matt J " <mattjacREMOVE(a)THISieee.spam> wrote in message <hsbq2g$be5$1(a)fred.mathworks.com>...
> "Roger Stafford" <ellieandrogerxyzzy(a)mindspring.com.invalid> wrote in message <hsa4uj$6mv$1(a)fred.mathworks.com>...
> If you wish to constrain the slope to non-negative values, then the best slope in that least squares sense would be a slope of zero. That is the value you would get if you were to minimize the objective function Matt described while restricting slope m to real values.
> ====================
>
> That is indeed the result I got when I performed the function minimization for the given data. It would not be the case for all data, however.
=============

Scratch that. I just convinced myself that it will happen for all data...
From: Roger Stafford on
"Nathan " <ndn3(a)georgetown.edu.remove.this> wrote in message <hsbs46$q21$1(a)fred.mathworks.com>...
> Is there a way to use orthogonal offsets instead of vertical offsets when doing the least squares fitting? I think that may be more of what I am envisioning.
> .........

To Nathan:

There is nothing difficult about finding orthogonal fits. For your data x and y you would do this:

xm = mean(x); ym = mean(y);
A = [x-xm;y=ym].';
[U,S,V] = svd(A,0);

Then V(:,1) is a unit vector parallel to the desired line, so its slope is

m = V(2,1)/V(1,1)

and the line runs through the point (xm,ym).

The assumption behind ordinary regression is that all the errors are in the y-ccordinates, while these orthogonal fits assume that both x and y coordinates are equally in error. You can revise the above to weight the respective coordinates so as to obtain an optimum line in the sense of correspondingly weighted least square errors.

I seem to recall that the orthogonal-fit slope wil always lie between that of the ordinary regression line on the one hand and the regression line with x and y interchanged on the other, and that the three slopes can only be equal when the original data is colinear. (I would have to brush off some mental cobwebs to prove this right now.)

To Matt J:

When you write y(x) = m^2*x + b and remove all constraints, the optimization procedure will move toward a solution in which the partial derivatives of the objective function with respect to m and b are zero, since there is no longer a constraint barrier to stop it. If the data is such that it cannot find such a solution with m^2 > 0 - in other words, the natural regression slope would be negative - then it will presumably gravitate (if its search is successful) toward the m = 0 value which will then be the only way it can achieve a zero partial derivative with respect to m. That was the basis of my statement earlier.

Roger Stafford