function r = tchresvar(X,Y)
%
% tchresvar - Compute residual variance of Y values about regression line
% On input:
%     X: independent variable vector of length n
%     Y: dependent variable vector of length n
% On output:
%     r: residual variance
% Call:
%     r = tchresvar(X,Y);
%

n = length(X);
Xmean = tchmean(X);
Ymean = tchmean(Y);
x = X-Xmean;
y = Y-Ymean;
r = (sum(y.^2) - ((sum(x.*y)^2)/(sum(x.^2))))/(n-2);
