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 FunctionEnd Module
Public Class StatisticsPublic 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 FunctionEnd Class