ForumNorway.com Forum Index ForumNorway.com

 
Log in to check your private messagesLog in to check your private messages

Log inLog in  RegisterRegister


Profile  Search  Memberlist  FAQ  Usergroups
Statistical observators used to test for normality.

 
Post new topic   Reply to topic    ForumNorway.com Forum Index -> C++
View previous topic :: View next topic  
Author Message
KBleivik
Site Admin


Joined: 31 Jan 2006
Posts: 78
Location: Moss Norway

PostPosted: Fri Sep 22, 2006 5:04 pm    Post subject: Statistical observators used to test for normality. Reply with quote

#include <math.h>
#include <iostream.h>
long double mean (const long double *x, const int n)
{
int i; long double m;
m = x[0];
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[0] - 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[0]-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[0]-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[0]-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[10] = {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 |
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    ForumNorway.com Forum Index -> C++ All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum