## Statistical observators used to test for normality.

KBleivik
Posts: 88
Joined: Tue Jan 31, 2006 3:10 pm
Location: Moss Norway
Contact:

### Statistical observators used to test for normality.

#include <math.h>
#include <iostream.h>
long double mean (const long double *x, const int n)
{
int i; long double m;
m = x;
for (i=1; i<n; i++) m += x[i];
return (m/(long double )n);
}

long double var (const long double *x, const int n)
{
long double sum,m;
int i;
m = mean(x,n);
sum = x - m;
sum *= sum;
for (i=1; i<n; i++) sum += (x[i]-m)*(x[i]-m);
return (sum/(long double )(n-1));
}

long double meandev (const long double *x, const int n)
{
long double sum,m;
int i;
m = mean(x,n);
sum = fabs(x-m);
for (i=1; i<n; i++) sum += fabs(x[i]-m);
return (sum/(long double )n);
}

long double sd (const long double *x, const int n)
{
long double v;
v = var(x,n);
return (sqrt(v));
}

long double skew (const long double *x, const int n)
{
long double s,m,sum; int i;
s = sd(x,n);
m = mean(x,n);
s = s*s*s;
sum = pow((x-m),3.0);
for (i=1; i<n; i++) sum += pow((x[i]-m),3.0);
return (sum/(s*(long double )n));
}

long double kurt (const long double *x, const int n)
{
long double s,m,sum; int i;
s = sd(x,n);
m = mean(x,n);
s = s*s*s*s;
sum = pow((x-m),4.0);
for (i=1; i<n; i++) sum += pow((x[i]-m),4.0);
return (sum/(s*(long double )n)-3.0);
}

void main()
{
long double a = {1.0, 7.8, 10.5, 5.0, 13.0, 20.0, 22.3, 17.5, 12.3,7.0};
cout << "\n The mean: " << mean(a,10) << endl;
cout << "\n The variance: " << var(a,10) << endl;
cout << "\n Absolute deviation: " << meandev(a,10) << endl;
cout << "\n The standarddeviation: " << sd(a,10) << endl;
cout << "\n Skewness: " << skew(a,10) << endl;
cout << "\n Excess kurtosis: " << kurt(a,10) << endl;
}
Kjell Gunnar Bleivik
Make it simple, as simple as possible but no simpler: | DigitalPunkt.no |