Good morning
I found a ready-made p-value calculator from the z value in the network (it's kinda hard for Delphi;). Unfortunately, it only gives the value for left-tailed, and I need it to give a value for two-tailed. Can anyone tell me how to calculate or what to change in the code?
function NormalZ (const X: Extended): Extended;
{ Returns Z(X) for the Standard Normal Distribution as defined by
Abramowitz & Stegun. This is the function that defines the Standard
Normal Distribution Curve.
Full Accuracy of FPU }
begin
Result := Exp (- Sqr (X) / 2.0)/Sqrt (2 * Pi);
end;
function NormalP (const A: Extended): Single;
{Returns P(A) for the Standard Normal Distribution as defined by
Abramowitz & Stegun. This is the Probability that a value is less
than A, i.e. Area under the curve defined by NormalZ to the left
of A.
Only handles values A >= 0 otherwise exception raised.
Accuracy: Absolute Error < 7.5e-8 }
const
B1: Extended = 0.319381530;
B2: Extended = -0.356563782;
B3: Extended = 1.781477937;
B4: Extended = -1.821255978;
B5: Extended = 1.330274429;
var
T: Extended;
T2: Extended;
T4: Extended;
begin
if (A < 0) then
raise EMathError.Create ('Value must be Non-Negative')
else
begin
T := 1 / (1 + 0.2316419 * A);
T2 := Sqr (T);
T4 := Sqr (T2);
Result := 1.0 - NormalZ (A) * (B1 * T + B2 * T2
+ B3 * T * T2 + B4 * T4 + B5 * T * T4);
end;
end;
According to the online calculator, for example here: https://www.easycalculation.com/statistics/p-value-for-z-score.php for given z score: 0.70710678 this code gives me 0,76025003 as result, what is the correct result, but for one-tailed hypothesis. Can anyone tell me how to get the correct result for a two-tailed hypothesis, i.e. 0.47950012? My guess is that the case can be very simple, but I'm not good at z-distibution. :(
Thank You for any help.