+ Reply to Thread
Results 1 to 3 of 3

How to automate the calculation of the median from a frq distribut

  1. #1
    Alaska Hydro
    Guest

    How to automate the calculation of the median from a frq distribut

    Instructions for calculating the median froma frequency distribution tend to
    rely on a visual interpretation of the frequency distribution. I have
    hundreds of frequency distributions that I want to calculate the median for.

    Can I automate the calculation of the median directly using code or do I
    need to transform the distribution temporarily into its original array then
    calc?

    I can provide examples if necessary.
    thanks.

  2. #2
    N10
    Guest

    Re: How to automate the calculation of the median from a frq distribut

    Hi Alaska

    I think this would work if you placed your array in column A. It uses the
    formula (n+1) /2 as the estimator for the median

    Dim datarange As Range


    Range("A1").Select
    Range(Selection, Selection.End(xlDown)).Select
    Selection.Sort Key1:=Range("A1"), Order1:=xlAscending, Header:=xlGuess,
    _
    OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
    DataOption1:=xlSortNormal

    Dim datarange As Range

    Set datarange = Selection

    k = datarange.Rows.Count + 1
    k = k / 2

    Range("a1").Select
    For x = 1 To k
    ActiveCell.Offset(1, 0).Select
    Next

    MsgBox (" THE MEDIAN IS ") & ActiveCell.Value


    Hope this helps

    Best N10



    "Alaska Hydro" <[email protected]> wrote in message
    news:[email protected]...
    > Instructions for calculating the median froma frequency distribution tend
    > to
    > rely on a visual interpretation of the frequency distribution. I have
    > hundreds of frequency distributions that I want to calculate the median
    > for.
    >
    > Can I automate the calculation of the median directly using code or do I
    > need to transform the distribution temporarily into its original array
    > then
    > calc?
    >
    > I can provide examples if necessary.
    > thanks.




  3. #3
    Alaska Hydro
    Guest

    Re: How to automate the calculation of the median from a frq distr

    Thanks N10 - your formula would work for an array - alas I have frequency
    distributions that look like this:
    class (mm) count
    1 11
    2 6
    4 2
    8 6
    16 1
    32 21
    64 35
    128 11
    256 0
    512 7
    1024 0
    2048 0
    4096 0
    8192 0

    The count category represents the number of hits in a particular class.
    Were this an array it would look like:
    1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,4,4,... ...,512 with an n of 100. The
    median value falls in the 64 category.
    One thought I had would be to write the distribution back into an array
    temporarily - calculate the median as you so helpfully wrote below, then
    delete the temporary array and continue to the next set. It might be nicer
    to have it work on the distribution itself though.
    thanks.

    "N10" wrote:

    > Hi Alaska
    >
    > I think this would work if you placed your array in column A. It uses the
    > formula (n+1) /2 as the estimator for the median
    >
    > Dim datarange As Range
    >
    >
    > Range("A1").Select
    > Range(Selection, Selection.End(xlDown)).Select
    > Selection.Sort Key1:=Range("A1"), Order1:=xlAscending, Header:=xlGuess,
    > _
    > OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
    > DataOption1:=xlSortNormal
    >
    > Dim datarange As Range
    >
    > Set datarange = Selection
    >
    > k = datarange.Rows.Count + 1
    > k = k / 2
    >
    > Range("a1").Select
    > For x = 1 To k
    > ActiveCell.Offset(1, 0).Select
    > Next
    >
    > MsgBox (" THE MEDIAN IS ") & ActiveCell.Value
    >
    >
    > Hope this helps
    >
    > Best N10
    >
    >
    >
    > "Alaska Hydro" <[email protected]> wrote in message
    > news:[email protected]...
    > > Instructions for calculating the median froma frequency distribution tend
    > > to
    > > rely on a visual interpretation of the frequency distribution. I have
    > > hundreds of frequency distributions that I want to calculate the median
    > > for.
    > >
    > > Can I automate the calculation of the median directly using code or do I
    > > need to transform the distribution temporarily into its original array
    > > then
    > > calc?
    > >
    > > I can provide examples if necessary.
    > > thanks.

    >
    >
    >


+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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