function [Cook,DFFITS,H,ss]=regress(X,vrt)
    [na,np]=size(X);
    vel=pinv(X'*X)*X'*vrt;
    resid=(vrt-X*vel);
    ss=sqrt(var(resid));
    H=X*pinv(X'*X)*X';
    for j=1:na
        resid(j)=resid(j)/ss/sqrt(1-H(j,j));
    end
    Cook=zeros(1,na);
    DFFITS=zeros(1,na);
    for n=1:na
        Cook(n)=(resid(n).^2/np)*(H(n,n)/(1-H(n,n)));
        sn=((nn-pp)*ss - resid(n)^2/(1-H(n,n)))/(nn-pp-1);
        DFFITS(n)=sqrt(H(n,n)/(1-H(n,n)))*(resid(n)/sn/sqrt(1-H(n,n)));
    end

return
