I have a routine that tests a mechanical timer a number of times. I would like to display the Mean, Modal, Median, Maximum and Minimum times.
I sort the ArrayList before using the subs. I'm struggling with the code to calculate the modal value. I appreciate in my dataset there may be (rarely) more than one modal value.
I sort the ArrayList before using the subs. I'm struggling with the code to calculate the modal value. I appreciate in my dataset there may be (rarely) more than one modal value.
B4X:
#Region StatsCalculators
Sub CalcMean
For i=0 To ArrayList1.Count-1
x=x+ArrayList1.Item(i)
Next
Return Format(x/ArrayList1.Count,"F2")
End Sub
Sub CalcMode
Return "Uniform Dist." 'Unless there is a genuine Modal value.
End Sub
Sub CalcMed
If ArrayList1.Count Mod 2=1 Then
Return ArrayList1.Item(((ArrayList1.Count+1)/2)-1)
Else
Return Format((ArrayList1.Item((ArrayList1.Count/2)-1)+ArrayList1.Item(ArrayList1.Count/2))/2,"F2")
End If
End Sub
Sub CalcMax
Return ArrayList1.Item(ArrayList1.Count-1)
End Sub
Sub CalcMin
Return ArrayList1.Item(0)
End Sub
#End Region