Julia, Software Development, Statistics

Find Interquartile Range In Julia

This post shows how to find the Interquartile Range (IQR) in Julia. We will use custom codes and move them into a function for reusability.

Interquartile Range With Custom Codes

Before moving on, please install Julia plugin for IntelliJ IDEA. Using IntelliJ IDEA may be optional for those who already have other IDEs. In this section, we’ll create simple Julia codes to find the Interquartile Range of a given array of integers.

First, we bring in the Statistics package to compute for the median values later.

We have these sample values stored in an array.

Then, we sort the values.

We find the length of the array to split it into two using the built-in Julia function length.

Next, we find the start and end indexes for Q1 and Q3.

Then, we find the median values from each half of the array. This function requires the Julia Statistics package.

Lastly, we get the difference between the two median values, which is our Interquartile Result.

Find Interquartile Range With a Function

Okay, from the code fragments we have, we can create our function in Julia to find the Interquartile Range. We will name our function my_iqr. Its definition is shown as follows.

We still need to use the Statistics package, though. Also, the function definition goes first before in the file before any codes use it.

The codes produce a value of 29.5 for those integer values.

Loading

Got comments or suggestions? We disabled the comments on this site to fight off spammers, but you can still contact us via our Facebook page!.


You Might Also Like