//=============================================================
//     Numerical Analysis Packages in Java
//     Matrix calculations class Matrix
//     Author : Dr. Turhan Coban
//=============================================================
//Turhan Coban
import java.io.*;
import java.text.*;
import java.util.Locale;

class fnormal extends f_x
{
  double func(double x)
  {
  return Math.exp(-x*x/2);
  }
}

public class stat
{

public static double t95(double N)
{
double x2=Math.log(N);
double a[]=new double[11];
double y;	
a[0] = 2.542076419105797;
a[1] = -2.3696744069457054;
a[2] = 1.515182912349701;
a[3] = -0.593106746673584;
a[4] = 0.13502562046051025;
a[5] = -0.009722605347633362;
a[6] = -0.0038675889372825623;
a[7] = 0.0013531427830457687;
a[8] = -1.972669269889593E-4;
a[9] = 1.447178510716185E-5;
a[10] = -4.3549766814976465E-7;
y=Numeric.f_least_square(a,x2);
return Math.exp(y);
}

public static double normal(double x)
{
//bu fonksiyon normal dağılım güven aralığını -x*sigma dan +x*sigma aralığında
//hesaplar
fnormal b1;
b1=new fnormal();
double x1=-1.0*x;
return   1.0/Math.sqrt(2.0*Math.PI)*Numeric.integral(b1,x1,x);
}

public static double ortalama(double x[])
{
//ortalama değerleri hesaplar
int N=x.length;
double tot=0;
for(int i=0;i<N;i++)
  tot+=x[i];
return tot/N;  
}

public static double s(double x[])
{
//standart sapma değerlerini hesaplar
double xort=ortalama(x);
int N=x.length;
double tot=0;
double xi=0;
for(int i=0;i<N;i++)
{
  xi=x[i]-xort;
  tot+=xi*xi;
}
return Math.sqrt(tot/(N-1));  
}

public static double sx(double x[])
{
// s/sqrt(N) kesinlik indeksi değerini hesaplar
return s(x)/Math.sqrt(x.length);
}

public static double t95sx(double x[])
{
double N=x.length-1;	
return t95(N)*sx(x);
}

}











