Normal distribution Test
Normaltest: Normal distribution Test
ZF: Normal distribution cumulative function
Vark (dlist,k): K-Order Sample moment
int Normaltest (double* dlist,int ndatacount,double alpha,bool* pbres)
{
Double sig1,sig2,mu2,a1,a2,a3,a4,b2,b3,b4,g1,g2,u1,u2;
if ((NULL = = dlist) | | (NULL = = pnres)) return-1;
if (ndatacount<100) return-2;
if ((Alpha < 0) | | (Alpha >= 1.0)) return-3;
Sig1=sqrt (6.0* (n-2)/(n+1)/(n+3));
Sig2=sqrt (24.0*n* (n-2) * (n-3)/(n+1)/(n+1)/(n+3)/(n+5));
mu2=3.0-6.0/(n+1);
A1=vark (dlist,1);
A2=vark (dlist,2);
A3=vark (dlist,3);
A4=vark (dlist,4);
B2=A2-A1*A1;
B3=A3-3.0*A2*A1+2.0*A1*A1*A1;
B4=A4-4.0*A3*A1+6.0*A2*A1*A1-3.0*A1*A1*A1*A1;
if (Fabs (B2) <1e-9)
return-4;
G1=B3/B2/SQRT (B2);
G2=B4/B2/B2;
U1=G1/SIG1;
U2= (G2-MU2)/sig2;
if ((Fabs (U1) >= ZF (alpha/4.0)) | | (Fabs (U2) >= ZF (alpha/4.0)))
{
*pbres = false;
}
Else
{
*pbres = true;
}
return 1;
}
Normal distribution Test Normaltest