Pages

Kamis, 29 Maret 2012

Menghitung P-Value dengan uji-t


function g1(v1:integer):real;
var fak:real;
begin
fak:=1;
for i:=1 to (v1-1) do
fak:=fak*i;
g1:=fak;
end;

function g2(v2:integer):real;
var fak,k:real;
begin       
if v2=0 then g2:=sqrt(3.14)
else
k:=-0.5;
fak:=1;
for i:=1 to v2 do
fak:=fak*(k+i);
g2:=fak*sqrt(3.14);
end;

function pangkat(x,p:real):real;
begin      
pangkat:=exp(p*ln(x));
end;

function fx1(v:integer):real;
var h,hi,p,x,xo,xn,fungsi,fungsi1,fungsi2,fsigma:real;
begin
v1:=(v+1) div 2;
v2:=v div 2;
h:=(t)/1000;
xo:=(1);
xn:=(1+(t*t/v));
p:=(v+1)/2;
fungsi:=g1(v1)/(g2(v2)*sqrt(v*3.14));
fungsi1:=fungsi/(pangkat(xo,p));
fungsi2:=fungsi/(pangkat(xn,p));
fsigma:=0;
for i:=1 to 999 do
begin
hi:=i*h;
x:=(1+(sqr(hi)/v));
fsigma:=fsigma+(fungsi/(pangkat(x,p)));
end;
fx1:=1-(0.5+(h/2)*(fungsi1+(2*fsigma)+fungsi2));
end;

function fx2(v:integer):real;
var h,hi,p,x,xo,xn,fungsi,fungsi1,fungsi2,fsigma:real;
begin         
v1:=v div 2;
v2:=(v+1) div 2;
h:=(t)/1000;
xo:=(1);
xn:=(1+(t*t/v));
p:=(v+1)/2;
fungsi:=g2(v1)/(g1(v2)*sqrt(v*3.14));
fungsi1:=fungsi/(pangkat(xo,p));
fungsi2:=fungsi/(pangkat(xn,p));
fsigma:=0;
for i:=1 to 999 do
begin
hi:=i*h;
x:=(1+(sqr(hi)/v));
fsigma:=fsigma+(fungsi/(pangkat(x,p)));
end;
fx2:=1-(0.5+(h/2)*(fungsi1+(2*fsigma)+fungsi2));
end;

{$R *.dfm}

procedure TForm1.Button2Click(Sender: TObject);
begin
n:=StrToInt(Edit1.Text);
x:=StrToFloat(Edit2.Text);
s:=StrToFloat(Edit3.Text);
x0:=StrToFloat(Edit4.Text);
alpha:=StrToFloat(Edit5.Text);

t:=(x-x0)/(s/sqrt(n));
v:=n-1;

d:=ComboBox1.Text;

sisa:=v mod 2;
if sisa=1 then
pvalue:=fx1(v)
else
pvalue:=fx2(v);


if (d='greater than') then
pvalue:=pvalue
else if (d='less than') then
pvalue:=1-pvalue
else
begin
if t<0 then t:=-t;
  sisa:=v mod 2;
  if sisa=1 then
  pvalue:=fx1(v)
  else
  pvalue:=fx2(v);
pvalue:=2*pvalue;
end;

label7.caption:=FloatToStrf(pvalue,ffnumber,4,3);
if pvalue<alpha then
label8.caption:='tolak H0. mu not equals '+FloatToStr(x0)
else
label8.caption:='gagal tolak H0. mu equals '+FloatToStr(x0);

end;

Tidak ada komentar:

Posting Komentar