function [ A, sA, Q2, NGL, VA, F ] = mmqLINCOV( X, Y, V )
% [ A, sA, Q2, NGL, VA, F ] = mmqLINCOV( X, Y, V );

if min(size(V))==1
    V = diag( V.^2 );
end

[ Alscov, sAlscov, MSE, VAlscov ] = lscov( X, Y, V );

A = Alscov;
sA = sAlscov*sqrt(1/MSE);
VA = VAlscov*(1/MSE);

F = X * A;
Q2 = (Y-F)' * inv(V) * (Y-F);
NGL = length(Y) - length( A );
