+ Reply to Thread
Results 1 to 6 of 6

Weighted interquartile range

Hybrid View

asenso Weighted interquartile range 05-13-2017, 12:02 PM
MrShorty Re: Weighted interquartile... 05-13-2017, 12:34 PM
asenso Re: Weighted interquartile... 05-13-2017, 07:18 PM
MrShorty Re: Weighted interquartile... 05-13-2017, 09:50 PM
asenso Re: Weighted interquartile... 05-14-2017, 12:47 AM
MrShorty Re: Weighted interquartile... 05-14-2017, 01:18 AM
  1. #1
    Registered User
    Join Date
    05-10-2017
    Location
    Australia
    MS-Off Ver
    2016
    Posts
    3

    Weighted interquartile range

    Pls anyone to provide advice on how to compute weighted interquartile range in Excel. I managed to compute weighted median but not sure how to do for weighted IQR

    Thanks

  2. #2
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP, 2007, 2024
    Posts
    16,431

    Re: Weighted interquartile range

    How did you compute the weighted median? According to this Wikipedia page (https://en.wikipedia.org/wiki/Weight...centile_method ), the weighted median is just a special case of the more general weighted percentile formula. I expect that you should be able to substitute something other than 50 or 0.5 (depending on the formula you used for weighted median) and get the desired weighted percentile (if I understand correct, the 25th and 75th percentile). Then compute your interquartile range.
    Quote Originally Posted by shg
    Mathematics is the native language of the natural world. Just trying to become literate.

  3. #3
    Registered User
    Join Date
    05-10-2017
    Location
    Australia
    MS-Off Ver
    2016
    Posts
    3

    Re: Weighted interquartile range

    @Shortly,
    Thanks for the feedback.. I used a previous excel sheet that was shared on this platform. Pls see attached. It allows straight forward calculation of weighted median. In that the values are in one column and weight in another column. but cant figure out how to get the QI and Q3
    The excel file in question was shared by gjlindn here https://www.excelforum.com/excel-pro...ed-median.html

    Thanks

  4. #4
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP, 2007, 2024
    Posts
    16,431

    Re: Weighted interquartile range

    Do you understand how gjlindn's code? It looks like, rather than use the formula described by Wikipedia, his/her UDF simply makes a new array of "weight" copies of each "value". Then uses the built in WorksheetFunction.Median() function to derive the median. By simply changing WorksheetFunction.Median to WorksheetFunction.Percentile() or .Quartile(), you could return any quartile or percentile you wanted from the UDF.

  5. #5
    Registered User
    Join Date
    05-10-2017
    Location
    Australia
    MS-Off Ver
    2016
    Posts
    3

    Re: Weighted interquartile range

    shorty

    Thanks much!... i am not able to do as described. Can you please populate this in the excel file and share? That will be very much appreaicted

    Thanks

  6. #6
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP, 2007, 2024
    Posts
    16,431

    Re: Weighted interquartile range

    I am hesitant to "just do it for you" because this edit should be very simple. What have you tried, and what has happened with each attempt?

    Here's a quick edit allowing you to see how to replace the .Median() function with either the .Quartile() function or the .Percentile() function:

    unction WTMEDIAN(ValueRange As Range, WeightRange As Range) As Double
        Dim aArray()   As Variant
        Dim rCell       As Range
        Dim lRowCnt     As Long
        Dim lColCnt     As Long
        Dim lCount      As Long
        Dim lAry        As Long
        
        If ValueRange.Cells.Count = WeightRange.Cells.Count And _
        (ValueRange.Rows.Count = WeightRange.Rows.Count Or _
        ValueRange.Columns.Count = WeightRange.Columns.Count) And _
        ValueRange.Rows.Count * ValueRange.Columns.Count = ValueRange.Cells.Count Then
            ReDim aArray(WorksheetFunction.Sum(WeightRange) - 1)
            lRowCnt = 1
            lColCnt = 1
    
    'This block "unwinds" the weighted array into a single array with weight copies of each value
    'The outer rcell loop loops through each weight in weight range
            For Each rCell In WeightRange
    'The inner lCount loop makes weight (the value in rCell) copies of the corresponding value in ValueRange
                For lCount = 1 To Int(rCell)
                    Debug.Print ValueRange.Item(lRowCnt, lColCnt)
                    aArray(lAry) = ValueRange.Item(lRowCnt, lColCnt)
                    lAry = lAry + 1
                Next
                If ValueRange.Rows.Count = 1 Then lColCnt = lColCnt + 1
                If ValueRange.Columns.Count = 1 Then lRowCnt = lRowCnt + 1
            Next
    'stop function pauses execution and enters debug mode, so you can step through subsequent
    'statements and see what happens
    stop
    
    
    'With the weighted values unwound into a simple array of values, use the MEDIAN() worksheet function to get the median
            WTMEDIAN = WorksheetFunction.Median(aArray)
    
    'The same value could be obtained from the QUARTILE() function
             WTMEDIAN=WorksheetFunction.Quartile(aArray,2)
    'Of course, the QUARTILE() function can return more than just the median/2nd quartile. You can also return the 1st and/or 3rd quartiles s as well
    
    'or from the PERCENTILE() function
              WTMEDIAN=WorksheetFunction.Percentile(aArray,0.5)
    'Of course, the PERCENTILE() function is not limited to the median/50th percentile. It can return any percentile including the 25th and 75th percentiles.
    
        End If
    End Function
    Does that help you see how to use these functions in the UDF?

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Calculate Weighted Average within a date range
    By danallamas in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 05-27-2016, 10:59 AM
  2. Cumulative weighted average of different range
    By dastgir in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 07-31-2015, 09:35 AM
  3. [SOLVED] Weighted Average, Dynamic Range, Conditional Dashboard
    By MIACG in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 03-27-2014, 05:32 PM
  4. [SOLVED] Weighted Sum of Positives in a Range
    By odyman in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 05-03-2013, 05:55 PM
  5. [SOLVED] Macro to find the range a value falls in and apply a weighted formula
    By aarho in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 11-01-2012, 01:11 AM
  6. How to find range, coefficient of variation, interquartile range?
    By stathead in forum Excel - New Users/Basics
    Replies: 1
    Last Post: 12-16-2007, 07:29 PM
  7. Scatter plot with median and interquartile lines
    By ninja-lewis in forum Excel Charting & Pivots
    Replies: 0
    Last Post: 05-01-2006, 01:26 PM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1