Another Standard Deviation Extension for LINQ

Just wanted to post my SDev extension for linq

HopeFully someone will find it helpfull

Happy coding all

DK

Module Module1

<Runtime.CompilerServices.Extension()> _

Function StDev(Of T)(ByVal Values As System.Collections.Generic.IEnumerable(Of T), ByVal selector As Func(Of T, Double))

Return Statistics.StDev(Values.Select(selector).ToList())

End Function

End Module

Public Class Statistics

Public Shared Function StDev(ByVal Values As System.Collections.Generic.List(Of Double))

Dim n = Values.Count()

Dim SigXSquare = (From i In Values Select i * i).Sum()

Dim SigX = Values.Sum()

Dim SigSquareX = SigX * SigX

Dim MySTDev As Double = ((n * SigXSquare) - SigSquareX) / (n * (n - 1))

Dim root = Math.Sqrt(MySTDev)

Return root End Function

End Class

 

 

1 Comment

Comments have been disabled for this content.