Skip to content

Commit feb557c

Browse files
committed
v3.2.5
1 parent 771e750 commit feb557c

File tree

4 files changed

+47
-141
lines changed

4 files changed

+47
-141
lines changed

src/LO Basic/VBAExpressionsLib/TestVBAExpr.xba

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,11 @@ Sub RunAllTests
337337
"ROUND(IBETA((2-1)/(3-1);8;10);4)", _
338338
"0.6855" _
339339
)
340+
Run( _
341+
"Excel T.INV function test", _
342+
"ROUND(TINV(0.75;2;1);8)", _
343+
"0.81649658" _
344+
)
340345
SF_Exception.debugprint("Passed tests:",sAcum)
341346
SF_Exception.debugprint("Failed tests:",tTotal - sAcum)
342347
SF_Exception.debugprint("Passed tests Ratio:",Round(100*sAcum/tTotal,2) &"%")

src/LO Basic/VBAExpressionsLib/VBAexpressions.xba

Lines changed: 41 additions & 139 deletions
Original file line numberDiff line numberDiff line change
@@ -3995,9 +3995,11 @@ Private Function GetFunctionName(ByRef expression As String) As String
39953995
For EFjCounter = LBound(FunctionsId) To UBound(FunctionsId)
39963996
tmpPos = strVBA.InStrB(1, ExpCopy, FunctionsId(EFjCounter))
39973997
If tmpPos Then
3998-
GFNbool = ValidFuntionName(ExpCopy, FunctionsId(EFjCounter), tmpPos)
3999-
If GFNbool Then
4000-
Exit For
3998+
If ExpCopy = FunctionsId(EFjCounter) Then
3999+
GFNbool = ValidFuntionName(ExpCopy, FunctionsId(EFjCounter), tmpPos)
4000+
If GFNbool Then
4001+
Exit For
4002+
End If
40014003
End If
40024004
End If
40034005
Next EFjCounter
@@ -4009,9 +4011,11 @@ Private Function GetFunctionName(ByRef expression As String) As String
40094011
For i = 0 To UserDefFunctions.aindex
40104012
tmpPos = strVBA.InStrB(1, ExpCopy, UserDefFunctions.Storage(i).aName)
40114013
If tmpPos Then
4012-
GFNbool = ValidFuntionName(ExpCopy, UserDefFunctions.Storage(i).aName, tmpPos)
4013-
If GFNbool Then
4014-
Exit For
4014+
If ExpCopy = UserDefFunctions.Storage(I).name Then
4015+
GFNbool = ValidFuntionName(ExpCopy, UserDefFunctions.Storage(I).name, tmpPos)
4016+
If GFNbool Then
4017+
Exit For
4018+
End If
40154019
End If
40164020
End If
40174021
Next i
@@ -4951,7 +4955,7 @@ Private Function iBETAINV(p As Double, A As Double, B As Double) As Double
49514955
err = iBETA_(x, A, B) - p
49524956
t = Exp(a1 * Log(x) + b1 * Log(1 - x) + afac)
49534957
u = err / t
4954-
t = u / (1 - 0.5 * Min(1, u * (a1 / x - b1 / (1 - x))))
4958+
t = u / (1 - 0.5 * MIN_(1, u * (a1 / x - b1 / (1 - x))))
49554959
x = x - t
49564960
If x <= 0 Then x = 0.5 * (x + t)
49574961
If x >= 1 Then x = 0.5 * (x + t + 1)
@@ -8452,97 +8456,6 @@ Private Function STUDT_(ByVal t As Double, n As Double) As Double
84528456
End If
84538457
End Function
84548458

8455-
Private Function subTINV_(x1 As Double, x2 As Double) As Variant
8456-
If ((0 >= x1 Or Abs(x1) - Abs(Fix(x1)) <> 0) Or (0 >= x2 Or x2 >= 1)) Then
8457-
subTINV_ = False
8458-
Else
8459-
subTINV_ = GetPrecisionResult(subt_(x1, x2))
8460-
End If
8461-
End Function
8462-
8463-
Private Function subtprob_(y1 As Double, y2 As Double) As Double
8464-
Dim e As Double, rt1 As Double
8465-
Dim L As Double, n As Double
8466-
Dim s As Double, rt2 As Double
8467-
8468-
L = Atn((y2 / Sqr(y1)) / 1)
8469-
n = Cos(L) ^ 2: s = 1
8470-
For rt2 = y1 - 2 To 2 Step -2
8471-
s = 1 + (rt2 - 1) / rt2 * n * s
8472-
Next rt2
8473-
If REM_(y1, 2) = 0 Then
8474-
e = 0.5
8475-
rt1 = Sin(L) / 2
8476-
subtprob_ = rt1
8477-
Else
8478-
e = 0.5 + L / pi
8479-
If 1 = y1 Then
8480-
rt1 = 0
8481-
Else
8482-
rt1 = Cos(L) * Sin(L) / pi
8483-
End If
8484-
subtprob_ = MAX_(0, 1 - e - rt1 * s)
8485-
End If
8486-
End Function
8487-
8488-
Private Function subt_(t As Double, r As Double) As Double
8489-
Dim e As Double, h As Double
8490-
Dim f As Double, i As Double
8491-
Dim inp1 As Double, inp2 As Double
8492-
Dim inp3 As Double, inp4 As Double
8493-
Dim inp5 As Double, inp6 As Double
8494-
Dim inp7 As Double, inp9 As Double
8495-
8496-
If (0 >= r Or r >= 1) Then
8497-
subt_ = 0: Exit Function
8498-
End If
8499-
If (0.5 > r) Then
8500-
subt_ = -subt_(t, 1 - r): Exit Function
8501-
End If
8502-
e = subu_(r)
8503-
inp1 = e ^ 2
8504-
inp2 = (27 * inp1 + 339) * inp1 + 930
8505-
inp2 = inp2 * inp1 - 1782
8506-
inp2 = ((inp2 * inp1 - 765) * inp1 + 17955) / 368640
8507-
inp3 = (79 * inp1 + 776) * inp1 + 1482
8508-
inp3 = inp3 * inp1 - 1920
8509-
inp3 = (inp3 * inp1 - 945) / 92160
8510-
inp4 = (((3 * inp1 + 19) * inp1 + 17) * inp1 - 15) / 384
8511-
inp6 = ((5 * inp1 + 16) * inp1 + 3) / 96
8512-
inp5 = (inp1 + 1) / 4
8513-
inp7 = inp3 + inp2 / t
8514-
inp7 = (inp6 + (inp4 + inp7 / t) / t)
8515-
inp7 = e * (1 + (inp5 + inp7 / t) / t)
8516-
If (t <= (Log10(r) ^ 2) + 3) Then
8517-
Do
8518-
f = subtprob_(t, inp7)
8519-
inp9 = t + 1
8520-
i = Log(inp9 / (t + inp7 * inp7))
8521-
i = i + Log(t / inp9 / 2 / pi) - 1 + (1 / inp9 - 1 / t)
8522-
i = (f - r) / Exp((inp9 * i / 6) / 2)
8523-
inp7 = inp7 + i
8524-
h = RoundToPrecision(i, Abs(Fix(Log10(Abs(inp7)) - 6)))
8525-
Loop While (inp7 And 0 <> h)
8526-
End If
8527-
subt_ = inp7
8528-
End Function
8529-
8530-
Private Function subu_(p3 As Double) As Double
8531-
Dim p4 As Double
8532-
Dim e As Double
8533-
8534-
p4 = -Log(4 * p3 * (1 - p3))
8535-
e = -3.231081277E-09 + p4 * (3.657763036E-11 + 6.936233982E-13 * p4)
8536-
e = -0.00000104527497 + p4 * (8.360937017E-08 + p4 * e)
8537-
e = 0.000006841218299 + p4 * (0.000005824238515 + p4 * e)
8538-
e = -0.0008364353589 + p4 * (-0.0002250947176 + p4 * e)
8539-
e = Sqr(p4 * (1.570796288 + p4 * (0.03706987906 + p4 * e)))
8540-
If p3 > 0.5 Then
8541-
e = -e
8542-
End If
8543-
subu_ = e
8544-
End Function
8545-
85468459
Private Function SUM(ByRef expression As String, ByRef fName As String) As String
85478460
Dim g As Long
85488461
Dim tmpData() As String
@@ -8713,15 +8626,17 @@ err_Handler:
87138626
End Function
87148627

87158628
''' <summary>
8716-
''' Receives the degrees of freedom and the confidence level to
8717-
''' compute the one-tailed or two-tailed t-value (Student t-value)
8718-
''' with up to 6 significant digits accuracy. Use the tOption
8719-
''' parameter to select from two and right one-tailed computation.
8720-
''' [(c) iCalculator™](https://www.icalculator.com/)
8629+
''' receives the degrees of freedom and the confidence level to
8630+
''' compute the one-tailed or two-tailed t-value (student t-value)
8631+
''' with full accuracy. use the toption parameter to select from
8632+
''' two and right one-tailed computation.
8633+
'''
8634+
''' (c) david m. lane
8635+
''' https://onlinestatbook.com/2/calculators/inverse_t_dist.html
87218636
''' </summary>
8722-
''' <param name="confidence">Confidence level.</param>
8723-
''' <param name="dof">Shape parameter alpha.</param>
8724-
''' <param name="tOption">Select from two and right one-tailed computation.</param>
8637+
''' <param name="confidence">confidence level.</param>
8638+
''' <param name="dof">shape parameter alpha.</param>
8639+
''' <param name="toption">select from two and right one-tailed computation.</param>
87258640
Private Function TINV(ByRef expression As String, ByRef fName As String) As String
87268641
Dim argsCount As Long
87278642
Dim tmpData() As String
@@ -8752,28 +8667,37 @@ err_Handler:
87528667
d_lParenthesis & err.Description & d_rParenthesis
87538668
End Function
87548669

8755-
Private Function TINV_(confidence As Double, dof As Double, _
8670+
Private Function TINV_(ByRef confidence As Double, dof As Double, _
87568671
Optional tOption As Single = 2) As Double
8672+
Dim x As Double
87578673
Dim p As Double 'Probability
87588674

87598675
If confidence > 1 And confidence < 100 Then 'Percentage entry
87608676
confidence = confidence / 100
87618677
End If
8762-
p = (1 - confidence)
8678+
p = 1 - confidence
87638679
If tOption = 1 Then
8764-
TINV_ = subTINV_(dof, p)
8680+
x = iBETAINV(2 * p, 0.5 * dof, 0.5)
87658681
Else
87668682
If tOption = 2 Then
8767-
TINV_ = subTINV_(dof, p / 2)
8683+
x = iBETAINV(p, 0.5 * dof, 0.5)
87688684
End If
87698685
End If
8686+
x = Round(Sqr(dof * (1 - x) / x), 8)
8687+
If confidence > 0 Then
8688+
TINV_ = x
8689+
Else
8690+
TINV_ = -x
8691+
End If
87708692
End Function
87718693

87728694
''' <summary>
87738695
''' Receives the degrees of freedom and the Probability to
8774-
''' compute the one-tailed t-value (Student t-value) with up
8775-
''' to 6 significant digits accuracy. Parameter p can be passed
8776-
''' as 0 < p < 1, or 1 < p < 100
8696+
''' compute the one-tailed t-value (Student t-value) with full
8697+
''' accuracy. Parameter p can be passed as 0 < p < 1, or 1 < p < 100
8698+
'''
8699+
''' (c) David M. Lane
8700+
''' https://onlinestatbook.com/2/calculators/inverse_t_dist.html
87778701
''' </summary>
87788702
''' <param name="p">Probability.</param>
87798703
''' <param name="dof">Degrees of freedom.</param>
@@ -8807,21 +8731,14 @@ err_Handler:
88078731
d_lParenthesis & err.Description & d_rParenthesis
88088732
End Function
88098733

8810-
Private Function TINV_1T_(p As Double, dof As Double) As Double
8811-
Dim confidence As Double
8812-
8813-
If p > 1 Then 'Percentage entry
8814-
p = p / 100
8815-
End If
8816-
confidence = 1 - p
8817-
TINV_1T_ = TINV_(confidence, dof, 1)
8818-
End Function
8819-
88208734
''' <summary>
88218735
''' Receives the degrees of freedom and the Probability to
88228736
''' compute the two-tailed t-value (Student t-value) with full
88238737
''' significant digits accuracy. Parameter p can be passed
88248738
''' as 0 < p < 1, or 1 < p < 100
8739+
'''
8740+
''' (c) David M. Lane
8741+
''' https://onlinestatbook.com/2/calculators/inverse_t_dist.html
88258742
''' </summary>
88268743
''' <param name="p">Probability.</param>
88278744
''' <param name="dof">Degrees of freedom.</param>
@@ -8838,7 +8755,7 @@ Private Function TINV_2T(ByRef expression As String, ByRef fName As String) As S
88388755
argsCount = UB - LB + 1
88398756
Select Case argsCount
88408757
Case 2
8841-
tmpEval = TINV_2T_( _
8758+
tmpEval = TINV_( _
88428759
CDbl(tmpData(LB)), _
88438760
CDbl(tmpData(UB)) _
88448761
)
@@ -8854,21 +8771,6 @@ err_Handler:
88548771
d_lParenthesis & err.Description & d_rParenthesis
88558772
End Function
88568773

8857-
Private Function TINV_2T_(ByVal p As Double, dof As Long) As Double
8858-
Dim x As Double
8859-
8860-
If p > 1 Then 'Percentage entry
8861-
p = p / 100
8862-
End If
8863-
x = iBETAINV(p, 0.5 * dof, 0.5)
8864-
x = Sqr(dof * (1 - x) / x)
8865-
If p > 0 Then
8866-
TINV_2T_ = x
8867-
Else
8868-
TINV_2T_ = -x
8869-
End If
8870-
End Function
8871-
88728774
Public Function ToDblArray(ByRef aArray As Variant) As Variant
88738775
Dim i As Long, LB As Long, UB As Long
88748776
Dim j As Long, LB2 As Long, UB2 As Long

src/LO Basic/VBAExpressionsLib/script.xlb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,4 @@
77
<library:element library:name="VBAexpressions"/>
88
<library:element library:name="VBAcallBack"/>
99
<library:element library:name="UDFunctions"/>
10-
<library:element library:name="clsSimpleMath"/>
1110
</library:library>

src/VBAexpressions.cls

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8549,7 +8549,7 @@ Private Function TINV_(ByRef confidence As Double, dof As Double, _
85498549
x = iBETAINV(p, 0.5 * dof, 0.5)
85508550
End If
85518551
End If
8552-
x = Sqr(dof * (1 - x) / x)
8552+
x = Round(Sqr(dof * (1 - x) / x), 8)
85538553
If confidence > 0 Then
85548554
TINV_ = x
85558555
Else

0 commit comments

Comments
 (0)