德尔福的Z得分为P值 - 单尾到双尾

问题描述 投票:-3回答:2

早上好

我从网络中的z值找到了一个现成的p值计算器(这对Delphi来说有点困难;)。不幸的是,它只给出了左尾的值,我需要它给双尾值。任何人都可以告诉我如何计算或在代码中改变什么?

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;

根据在线计算器,例如:https://www.easycalculation.com/statistics/p-value-for-z-score.php给定z得分:0.70710678这个代码给我0,76025003作为结果,正确的结果是什么,但对于单尾假设。谁能告诉我如何获得双尾假设的正确结果,即0.47950012?我猜这个案子可以很简单,但我不擅长z-distibution。 :(

感谢您的任何帮助。

delphi distribution p-value
2个回答
1
投票

您正在寻找的公式可以在您链接的网页的源代码中找到。

如果X是P函数的结果,则计算2 *(1-X)。

我也从源代码中翻译了Z函数。它会从您提供的功能中生成不同的结果。我不能说哪个更准确。

function pzscore(z:extended):extended;
const
  Z_MAX = 6;
var
  x, y, w : extended;
begin
  if z = 0.0 then
    x := 0.0
  else
    begin
      y := 0.5 * abs(z);
      if y > Z_MAX * 0.5 then
        x := 1.0
      else
        if y < 1.0 then
          begin
            w := y * y;
            x := ((((((((0.000124818987 * w
                 - 0.001075204047) * w + 0.005198775019) * w
                 - 0.019198292004) * w + 0.059054035642) * w
                 - 0.151968751364) * w + 0.319152932694) * w
                 - 0.531923007300) * w + 0.797884560593) * y * 2.0;
          end
        else
          begin
            Y := Y - 2.0;
            x := (((((((((((((-0.000045255659 * y
                 + 0.000152529290) * y - 0.000019538132) * y
                 - 0.000676904986) * y + 0.001390604284) * y
                 - 0.000794620820) * y - 0.002034254874) * y
                 + 0.006549791214) * y - 0.010557625006) * y
                 + 0.011630447319) * y - 0.009279453341) * y
                 + 0.005353579108) * y - 0.002141268741) * y
                 + 0.000535310849) * y + 0.999936657524;
          end;
    end;
  if x > 0.0 then
    Result :=  (x + 1.0) * 0.5
  else
    Result :=  (1.0 - x) * 0.5;
end;

0
投票

对不起,我认为这是一个愚蠢的问题 - 从我收到的誓言来判断。好。 ;)

实际上,我并不认为模式可能在页面代码中,所以对我很羞耻。谢谢大卫杜波依斯。挖掘部分代码:

var lp = pzscore(z);
document.getElementById('lp').value = lp.toFixed(4);
var rp = 1 - lp;
document.getElementById('rp').value = rp.toFixed(4);
 var tp = 2 * rp;
document.getElementById('tp').value = tp.toFixed(4);
 var cl = 1 - tp;
document.getElementById('cl').value = cl.toFixed(4);

我只需要计算简单的方程式。函数NormalP(x)将给出mi左尾P值。然后1-NormalP(x)将给出右尾P值。然后2 *(1-NormalP(x))会给我一个答案。

不需要新功能,上面使用的是与SPSS和R兼容的有效功能(我检查过)。

© www.soinside.com 2019 - 2024. All rights reserved.