Statistical functions with E-Basic?
Ignacio Valdes
ivaldes at hal-pc.org
Thu Mar 17 17:00:45 UTC 2005
Here you go. This will calculate z and ordinate in e-prime given a
particular p. -- IV
'The following tests the P2Z and Ordinal functions
' Author: Ignacio Valdes, MD, MS
' 3/17/05
'
' The two functions: P2Z and Ordinal calculates the
' z-statistic given a p value and Ordinal calculates
' the Ordinate when given a z statistic value.
'
Dim P,Z,R,crlf,i,j As Variant
crlf = Chr(13) + Chr(10)
j = 0
For i = 0 to 10
R = R & "p: " & j & " z: " & P2Z(j) & " O: " & Ordinal(P2Z(j)) &
crlf
j = j + 0.1
Next i
MsgBox "R: " & R
' Calculate the ordinal value given a z value.
' Equation is 0(x)=[1/sqrt(2*pi)]*e^-(x^2)/2
Function Ordinal(x)
Dim n As Variant
n = exp(-(x*x)/2)
' MsgBox "x: " & x & " n: " & n
Ordinal = 0.39894228 * n
End Function
Function P2Z(P)
' THIS SUBROUTINE COMPUTES THE Z-VALUE ASSOCIATED WITH A
' P-VALUE
' P MUST BE IN THE RANGE 0.0 < P < 1.00
' Y IS THE Z-SCORE RETURNED FROM THE SUBROUTINE
'
' THE ALGORITHM IS APPROXIMATE AT P= .99975 TO 4 DECIMAL PLACES
' IN Z.
'---------------------------------------------------------------------------
'
Dim RA1, RA2, RA3, RB0, RB1, RB2, RB3, RC0, RC1, RC2, RC3, RD0,
RD1, RD2, _
RD3, RE0, RE1, RE2, RE3, RF0, RF1, RF2, RF3, RG0, RG1, RG2, RG3,
RH0, _
RH1, RH2, RH3, X, Y, Z, Z2, SIGMA, RA, RF, RB, W, SD, WI, SN, SQRT2
As Variant
RA1=-.5751703 :RA2=-1.896513 :RA3=-.05496261
RB0=-.1137730 :RB1=-3.293474 :RB2=-2.374996
RB3=-1.187515
RC0=-.1146666 :RC1=-.1314774 :RC2=-.2368201
RC3=.05073975
RD0=-44.27977 :RD1=21.98546 :RD2=-7.586103
RE0=-.05668422 :RE1=.3937021 :RE2=-.3166501
RE3=.06208963
RF0=-6.266786 :RF1=4.666263 :RF2=-2.962883
RG0=.0001851159 :RG1=-.002028152
RG2=-.1498384 :RG3=.01078639
RH0=.09952975 :RH1=.5211733
RH2=-.06888301
SQRT2=1.414214
X=1.0-P-P
SIGMA=1.0
IF (X < 0) Then
SIGMA=-SIGMA
End If
Z=ABS(X)
IF (Z > .85) Then
Z2=Z*Z
RF=Z+Z*(RB0+RA1*Z2/(RB1+Z2+RA2/(RB2+Z2+RA3/(RB3+Z2))))
Else
RA=1.0-Z
RB=Z
' ------------ P IS BETWEEN .85 AND 1.0
W=SQR(-LOG(RA+RA*RB))
If W >= 4.0 Then
' ------------ W > 4.0 APPROX. BY FUNC. IN 1/W.
WI=1.0/W
SN=((RG3*WI+RG2)*WI+RG1)*WI
SD=((WI+RH2)*WI+RH1)*WI+RH0
RF=W+W*(RG0+SN/SD)
Else If W >= 2.5 Then
SN=((RE3*W+RE2)*W+RE1)*W
SD=((W+RF2)*W+RF1)*W+RF0
RF=W+W*(RE0+SN/SD)
Else
' ----------- 1.13222 < W < 2.5 APPROX. BY FUNC. IN W.
SN=((RC3*W+RC2)*W+RC1)*W
SD=((W+RD2)*W+RD1)*W+RD0
RF=W+W*(RC0+SN/SD)
End If
End If
End If
Y=SIGMA*RF
Y=-SQRT2*Y
P2Z = Y
End Function
More information about the Eprime
mailing list