Results 1 to 6 of 6

Thread: Anybody out there have a statistics background?

  1. #1

    Thread Starter
    PowerPoster BruceG's Avatar
    Join Date
    May 2000
    Location
    New Jersey (USA)
    Posts
    2,657
    Technically, this is not a VB question, but in my latest project I need to apply some statistics calculations. Does anyone know the formula for calculating "weighted percentiles" for a group of values? (I know how to get "regular" percentiles.)
    "It's cold gin time again ..."

    Check out my website here.

  2. #2
    Frenzied Member
    Join Date
    Mar 2000
    Posts
    1,089
    I've done quite a bit of statistics, what exactly do you mean by Weighted percentiles? I can never remember the exact definitions for different terms (statistics si full of different names for similar formulae and I can never remember them all)

  3. #3

    Thread Starter
    PowerPoster BruceG's Avatar
    Join Date
    May 2000
    Location
    New Jersey (USA)
    Posts
    2,657
    Part of the problem is that I'm creating some of the functionality of an old (gulp)COBOL program into this VB project, and folks here are having trouble recollecting exactly what these values are supposed to represent.

    Anyway, "regular" percentiles deal with a sorted array of values. To get the value at the 25th perecentile in an array containing 11 elements, you calculate the position in the array (1-based) as follows:
    (11 * 25)/100 = 2.75 (if the result has a remainder, add 1 to the result, so you get 3). Therefore the item at index (3) in the array represents the value at the 25th percentile.

    With "weighted percentiles", the array of values has an associated list of values, or weights, that somehow affect the calculation above. This is what I'm trying to find.

    [Edited by BruceG on 08-07-2000 at 11:07 AM]
    "It's cold gin time again ..."

    Check out my website here.

  4. #4
    Frenzied Member
    Join Date
    Mar 2000
    Posts
    1,089
    Ok, I think I've got you (something is stirring in the obscure part of my brain that listened in Statistics lectures)

    so you should have a UDT like this
    Code:
    Private Type ArrayMember
        Value As Double
        Weight As Double
    End Type
    So, if you have an Array
    Code:
    Dim Data() As ArrayMember
    You Can Get the Weighted Percentile Something like this

    Code:
    Private Type ArrayMember
        Value As Double
        Weight As Double
    End Type
    
    Dim uData() As ArrayMember
    
    Private Function WeightedPercentile(Percentile as Single) As Double 
    'NB, Percentile is a single because it is still valid to get the 10.5th percentile etc
    
    Dim dblTotal As Double
    Dim dblRequredValue As Double
    Dim i As Integer
    
    'Check we have a valid Percentile
    If (Percentile < 0) OR (Percentile > 100) Then _
        Exit Sub
    
    'Get the Total Value of the Array
    dblTotal = GetArrayTotal
    
    'Get the Value we Need
    dblRequiredValue = dblTotal * dblPercentile / 100
    
    'Now we no longer need the Total Value of the Array, so dblTotal will be a running Total
    
    dblTotal = 0
    
    For i = LBound(uData) To UBound(uData)
    
        'Add The Weight of the member to our total
        dblTotal = dblTotal + uData(i).Weight
        
        If dblTotal > dblRequiredValue Then _
            Exit For
    
    Next i
    
    WeightedPercentile = uData(i).Value
    
    Exit Function
    
    
    Private Function GetArrayTotal() As Double
    
    Dim i As Integer
    Dim dblRunningTotal As Integer
    
    
    For i = LBound(uData) To UBound(uData)
    
        'Add The Weight of the member to our total
        dblTotal = dblTotal + uData(i).Weight
    
    Next i
    
    GetArrayTotal = dblRunningTotal
    
    Exit Function

    That'lll work

  5. #5

    Thread Starter
    PowerPoster BruceG's Avatar
    Join Date
    May 2000
    Location
    New Jersey (USA)
    Posts
    2,657
    You got it, Sam! I desk-checked your logic, applying it to the results on this old green-bar report here and it worked perfectly. Thank you very much!

    BTW (not to bite the hand that feeds me) but you had two typos in your code: In GetArrayTotal, where you have "dblTotal", it should be "dblRunningTotal"; and in the WeightedPercentile function, "dblPercentile" should just be "Percentile". But no problem, I saw exactly what you were doing.

    Again, much thanks - I had been searching on the net and in old Statistics books all weekend to no avail.

    "It's cold gin time again ..."

    Check out my website here.

  6. #6
    Frenzied Member
    Join Date
    Mar 2000
    Posts
    1,089
    Sorry about the typos, I typed the code straigt in without checking, I didn't have VB open at the time, and checking it properly would have meant making up a whole **** load of data, which I didn't want to do. So I didn't check it at all, I'm usually fairly good at typing it in right, but not today. Fortunatly they were all invalid names, rather than the name of the wrong variable, which would have confused you.

Posting Permissions

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



Click Here to Expand Forum to Full Width