Path: news.mathworks.com!newsfeed-00.mathworks.com!newsfeed2.dallas1.level3.net!news.level3.com!postnews.google.com!i29g2000prf.googlegroups.com!not-for-mail
From: Steve <srjm72499@frontiernet.net>
Newsgroups: comp.soft-sys.matlab
Subject: Help with orthogonal least squares line fit with slope constraint...
Date: Thu, 13 Dec 2007 12:21:13 -0800 (PST)
Organization: http://groups.google.com
Lines: 29
Message-ID: <8a0a561b-f3b1-4dcd-8c61-20d0fd4f7cf7@i29g2000prf.googlegroups.com>
NNTP-Posting-Host: 129.21.57.192
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
X-Trace: posting.google.com 1197577274 28835 127.0.0.1 (13 Dec 2007 20:21:14 GMT)
X-Complaints-To: groups-abuse@google.com
NNTP-Posting-Date: Thu, 13 Dec 2007 20:21:14 +0000 (UTC)
Complaints-To: groups-abuse@google.com
Injection-Info: i29g2000prf.googlegroups.com; posting-host=129.21.57.192; 
User-Agent: G2/1.0
X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET 
Xref: news.mathworks.com comp.soft-sys.matlab:442394


If I have a group of points, I know I can do a least-squares line fit
in the orthogonal sense by doing an eigenvector-type approach.  The
code I've been using for this is:

    Xm = mean(X);
    A = cov(X);
    [V,D] = eig(A);
    [ignore,imx] = max(diag(D)); % Choose eigenvector with max.
eigenvalue
    t=4;
    x = Xm + V(:,imx)'*t;
    t=-t;
    x2 = Xm + V(:,imx)'*t;
    slope=(x2(2)-x(2))/(x2(1)-x(1));
    b=((x2(2)+x(2))-(slope.*(x(1)+x2(1))))./2;

Now, I am looking to do a best fit line through the data, again in an
(orthogonal) least-squares sense, but this time where the slope of the
fitting line is a pre-determined (fixed) value.  Is there a simple
solution to this problem?  I am currently getting an approximate
solution by rotating the first line about Xm until it's slope is as
desired, but of course this doesn't always work well.  I have
considered doing a coordinate transform to make the predetermined
slope the x-axis, then doing a standard (non-orthogonal) regression
where the only uncertainty is in the vertical direction, but I'm
guessing there's probably a better way...

Any thoughts?  Thanks.
-SL