我有一个代码来计算标准偏差:
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)
有人看到我的错误吗?