function s=ntest3(data)

% NTEST3      Test of tri-variate normality.
%
%             Example: data=randn(100,3);
%                      s=ntest3(data);
%
%             NTEST3(DATA)
%
%             5% critical values: See Bowman and Foster(1993), pg 536
%
%             Christian C. Beardah 1996

inc=48;
[n,d]=size(data);
ndata=inv(sqrtm(cov(data)))*(data-ones(n,1)*mean(data))';
ndata=ndata';
h=(4/(5*n))^(1/7);
[X,Y,Z,f]=kdplot3(ndata,'knorm',inc,h,0);
f1=npdf3(X,Y,Z,[0 0 0]',(1+h^2)*eye(3));
deltax=X(inc+1,1)-X(1,1);
deltay=Y(2,1)-Y(1,1);
deltaz=Z(1,2)-Z(1,1);
s=deltax*deltay*deltaz*sum(sum((f-f1).^2));