Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

- JMP User Community
- :
- Discussions
- :
- How to get the median of an array

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

Highlighted
##

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

How to get the median of an array

Jan 4, 2019 10:45 AM
(5601 views)

Hi,

I am looking for a simple thing: the median of an array.

I found complex things with tabulate, summary tables,...But I need simpler:

Suppose I have an array (Matrix) A:

`A = 1::10;`

How to get the media of A ??

Thank you.

5 REPLIES 5

Highlighted
##

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Re: How to get the median of an array

Created:
Jan 4, 2019 11:23 AM
| Last Modified: Jan 4, 2019 11:27 AM
(5592 views)
| Posted in reply to message from samir 01-04-2019

Hi @samir,

You can use the quantile function without and with a by variable as shown in the example below.

```
Names Default To Here( 1 );
Open( "$SAMPLE_DATA/Big Class.jmp" );
Row() = 1;
median_ht = Col Quantile( :height, 0.5 );
Row() = 1;
median_htbyage = Col Quantile( :height, 0.5, :age );
Show( median_ht ); //Show median height
Show( median_htbyage ); //Show median height by age
```

cheers,

Stan

Highlighted
##

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Re: How to get the median of an array

@stan_koprowski,

While I thought of this, I think @samir was asking, how the same can be calculated for a matrix not from a data table ? I looked at the scripting index, there does not seem a direct way to compute the quantiles or median for a matrix (unless I missed it)

Best

Uday

Uday

Highlighted
##

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Re: How to get the median of an array

Hi @uday_guntupalli,

You could do the same with a matrix as follows--

```
Names Default To Here( 1 );
Open( "$SAMPLE_DATA/Big Class.jmp" );
htmat = :height<<Get As Matrix;
htmat1 = 1 :: 10;
Eval List(
{
Quantile( 0.5, 0, 100, 200, 300, 400, 500, 600, 700, 800, 900, 1000 ),
Quantile(0.5,htmat),
Quantile(0.5,htmat1)
}
);
```

//output

{500, 63, 5.5}

cheers,

Stan

Highlighted
##

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Re: How to get the median of an array

Thanks !

I guess @uday_guntupalli got my point :) and @stan_koprowski got a solution.

Indeed I was looking for a median of a matrix because I was not able to extract it immediatly from the table, but may be you can lead me to a way:

I hava a table (like below). I would like to calculate the median of each row in a simple way. Of course I need to exclude the 1st column from the calculation. In excel it is straight forward, but in JSL-JMP, I do not know how to do it simply (avoiding to stack the table,...).

Example of a table:

Consumption Monday Tuesday Wednesday Thursday Friday Saturday Sunday Median

Electricity 11.2 10.4 13.0 7.1 12.4 11.9 9.7 ?

Gas 100.4 86.9 94.8 103.0 112.3 95.3 97.8 ?

Highlighted
##

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Re: How to get the median of an array

Using Stan's quantile method, add the formula to the *median* column:

```
New Table( "Utility Data",
New Column( "Consumption", Character, "Nominal", Set Values( {"Electricity", "Gas"} ) ),
New Column( "Monday", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [11.2, 100.4] ) ),
New Column( "Tuesday", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [10.4, 86.9] ) ),
New Column( "Wednesday", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [13, 94.8] ) ),
New Column( "Thursday", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [7.1, 103] ) ),
New Column( "Friday", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [12.4, 112.3] ) ),
New Column( "Saturday", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [11.9, 95.3] ) ),
New Column( "Sunday", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [9.7, 97.8] ) ),
New Column( "Median", Numeric, "Continuous", Format( "Best", 12 ),
// the 2nd argument to the quantile function is a matrix made from the days of the row...
formula( Quantile( 0.5, monday || tuesday || wednesday || thursday || friday || saturday || sunday ) )
)
)
```

Craige

Article Labels

There are no labels assigned to this post.