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
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
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.
Originally Posted by shg
@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
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.
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
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:
Does that help you see how to use these functions in the UDF?![]()
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
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks