Has anyone ever programmed this as a function for Matlab?
Thanks for tips.
Urs Utzinger, utzi...@mail.utexas.edu
I haven't done exactly this in MATLAB, but the calculations are
relatively trivial, see for example, section 15.1 of Jackson, J. E.
(1991), "A User's Guide to Principal Components", John Wiley and Sons,
New York.
--
+---------------------------------+------------------------------------+
| Paige Miller | "It's nothing until I call it" |
| Eastman Kodak Company | Bill Klem |
| Pai...@kodak.com | NL Umpire |
+---------------------------------+------------------------------------+
| The opinions expressed herein do not necessarily reflect the |
| views of the author nor the views of the Eastman Kodak Company. |
+----------------------------------------------------------------------+
>Urs Utzinger wrote:
>>
>> It is a quite common tool in scatter plots to draw confidence
>> ellipses.
>> They represent a normal distribution fit on bivariate data.
>>
>> Has anyone ever programmed this as a function for Matlab?
>>
>> Thanks for tips.
>
>I haven't done exactly this in MATLAB, but the calculations are
>relatively trivial, see for example, section 15.1 of Jackson, J. E.
>(1991), "A User's Guide to Principal Components", John Wiley and Sons,
>New York.
Gee, thanks a lot Paige! I thought I was pretty clever when I figured it
out. :-)
Anyway, here's one that uses the Statistics Toolbox. If you don't have
that then you can just as easily use functions from Peter Shaw's ftest
toolbox available from
<ftp://ftp.mathworks.com/pub/contrib/v4/stats/ftest>
The changes are explained in the comments.
------------------------- convellipse2.m ----------------------------
function hh = confellipse2(xy,conf)
%CONFELLIPSE2 Draws a confidence ellipse.
% CONFELLIPSE2(XY,CONF) draws a confidence ellipse on the current axes
% which is calculated from the n-by-2 matrix XY and encloses the
% fraction CONF (e.g., 0.95 for a 95% confidence ellipse).
% H = CONFELLIPSE2(...) returns a handle to the line.
% written by Douglas M. Schwarz
% sch...@kodak.com
% last modified: 12 June 1998
n = size(xy,1);
mxy = mean(xy);
numPts = 181; % The number of points in the ellipse.
th = linspace(0,2*pi,numPts)';
p = 2; % Dimensionality of the data, 2-D in this case.
k = finv(conf,p,n-p)*p*(n-1)/(n-p);
% Comment out line above and uncomment line below to use ftest toolbox.
% k = fdistinv(p,n-p,1-conf)*p*(n-1)/(n-p);
[pc,score,lat] = princomp(xy);
% Comment out line above and uncomment 3 lines below to use ftest toolbox.
% xyp = (xy - repmat(mxy,n,1))/sqrt(n - 1);
% [u,lat,pc] = svd(xyp,0);
% lat = diag(lat).^2;
ab = diag(sqrt(k*lat));
exy = [cos(th),sin(th)]*ab*pc' + repmat(mxy,numPts,1);
% Add ellipse to current plot
h = line(exy(:,1),exy(:,2),'Clipping','off');
if nargout > 0
hh = h;
end
-----------------------------------------------------------------------
--
Doug Schwarz
Eastman Kodak Company
sch...@kodak.com