Results 1 to 12 of 12

Thread: Standard deviation of a subset in VBA

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #4
    VBAX Expert Dave's Avatar
    Joined
    Mar 2005
    Posts
    863
    Location
    Not sure what's up with your code. Here's some code borrowed from Tushar Meta for 1D array..
    Function StdDev(Arr)
         Dim i As Integer
         Dim avg As Single, SumSq As Single
         Dim k1 As Long, k2 As Long    
         Dim n As Long    
         k1 = LBound(Arr)
         k2 = UBound(Arr)
         n = 0
         avg = Mean(Arr)
         For i = k1 To k2
            n = n + 1
              SumSq = SumSq + (Arr(i) - avg) ^ 2
         Next i 
         StdDev = Sqr(SumSq / (n - 1))
    End Function
    You could trial it like this...
    For i = 1 To 5
        subsetStDev(i) = StdDev(subsets(i))
        ' Output standard deviation to Immediate Window for debugging
        Debug.Print "Subset " & i & " Standard Deviation: " & subsetStDev(i)
    Next i
    Good luck. Dave
    Last edited by Aussiebear; 04-10-2025 at 06:43 PM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •