-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathZScore.cls
72 lines (71 loc) · 2.57 KB
/
ZScore.cls
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
VERSION 1.0 CLASS
BEGIN
MultiUse = -1 'True
Persistable = 0 'NotPersistable
DataBindingBehavior = 0 'vbNone
DataSourceBehavior = 0 'vbNone
MTSTransactionMode = 0 'NotAnMTSObject
END
Attribute VB_Name = "ZScore"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Private StatisticArray() As Single
Public Average!, Mode!, Quartile1!, Quartile2!, Quartile3!, IQR!, SIQR!, NIQR!
Public SD!, RSD!
Public Sub Sort()
Dim I As Integer, J As Integer
For I = LBound(StatisticArray) To UBound(StatisticArray) - 1
For J = I + 1 To UBound(StatisticArray)
If StatisticArray(I) > StatisticArray(J) Then Swap StatisticArray(I), StatisticArray(J)
Next J
Next I
End Sub
Public Sub FillArray(StatArray() As Single)
ReDim StatisticArray(LBound(StatArray) To UBound(StatArray)), Zc(LBound(StatArray) To UBound(StatArray)), Zr(LBound(StatArray) To UBound(StatArray))
Dim I As Integer, AvgSum As Single
For I = LBound(StatArray) To UBound(StatArray)
StatisticArray(I) = StatArray(I)
AvgSum = AvgSum + StatisticArray(I)
Next I
Average = AvgSum / (UBound(StatisticArray) - LBound(StatisticArray) + 1)
For I = LBound(StatisticArray) To UBound(StatisticArray)
SD = SD + (StatisticArray(I) - Average) ^ 2
Next I
SD = Sqr(SD / (UBound(StatisticArray) - 1)): RSD = SD / Average * 100
Dim TempArr() As Single
ReDim TempArr(LBound(StatisticArray) To UBound(StatisticArray))
Dim LMiddle As Integer, UMiddle As Integer
TempArr = StatisticArray
Statistics.Sort TempArr
Mode = 0 'Find mode
If UBound(TempArr) / 2 = Int(UBound(TempArr) / 2) Then 'Even
Quartile2 = (TempArr(UBound(TempArr) / 2) + TempArr(UBound(TempArr) / 2 + 1)) / 2
LMiddle = UBound(TempArr) / 2: UMiddle = LMiddle + 1
Else 'Odd
Quartile2 = TempArr(UBound(TempArr) / 2 + 0.5)
LMiddle = Int(UBound(TempArr) / 2): UMiddle = LMiddle + 2
End If
If LMiddle / 2 = Int(LMiddle / 2) Then 'Even
Quartile1 = (TempArr(LMiddle / 2) + TempArr(LMiddle / 2 + 1)) / 2
Else 'odd
Quartile1 = TempArr(LMiddle / 2 + 0.5)
End If
Dim Inx As Integer
Inx = UBound(TempArr) - UMiddle + 1
If Inx / 2 = Int(Inx / 2) Then 'Even
Quartile3 = (TempArr(UMiddle + Inx / 2 - 1) + TempArr(UMiddle + Inx / 2)) / 2
Else 'odd
Quartile3 = TempArr(UMiddle + Inx / 2 - 0.5)
End If
IQR = Quartile3 - Quartile1
SIQR = IQR / 2
NIQR = IQR / 1.3489
End Sub
Public Function Robust(StNum As Single) As Single
Robust = (StNum - Quartile2) / NIQR
End Function
Public Function Classical(StNum As Single) As Single
Classical = (StNum - Average) / SD
End Function