標準偏差を計算するためのコードがあります。
Public Function StandardDeviation(ByRef arr() As Double) As Double
'standard deviation
Dim sum As Double
Dim sumSquare As Double
Dim value As Double
Dim count As Long
Dim index As Long
sum = 0
sumSquare = 0
value = 0
count = 0
index = 0
' evaluate sum of values
For index = LBound(arr) To UBound(arr)
value = arr(index)
count = count + 1
sum = sum + value
sumSquare = sumSquare + value * value
Next
StandardDeviation = Sqr((sumSquare - (sum * sum / count)) / count)
End Function
うまくいくようです。
たまたま、値がすべて同じになる場合があります。次に例を示します。
0.419208025523645
0.419208025523645
0.419208025523645
0.419208025523645
0.419208025523645
0.419208025523645
0.419208025523645
0.419208025523645
0.419208025523645
0.419208025523645
0.419208025523645
0.419208025523645
0.419208025523645
0.419208025523645
0.419208025523645
0.419208025523645
0.419208025523645
0.419208025523645
0.419208025523645
0.419208025523645
0.419208025523645
0.419208025523645
0.419208025523645
0.419208025523645
0.419208025523645
0.419208025523645
0.419208025523645
0.419208025523645
0.419208025523645
0.419208025523645
0.419208025523645
0.419208025523645
0.419208025523645
0.419208025523645
0.419208025523645
0.419208025523645
0.419208025523645
0.419208025523645
0.419208025523645
0.419208025523645
0.419208025523645
0.419208025523645
0.419208025523645
0.419208025523645
0.419208025523645
0.419208025523645
0.419208025523645
0.419208025523645
0.419208025523645
0.419208025523645
このような場合、次の行に「無効な引数」というエラーが表示されます。
StandardDeviation = Sqr((sumSquare - (sum * sum / count)) / count)
誰かが私の間違いを見ますか?