Tyler Marrs (Posts about median)http://tylermarrs.com/enContents © 2020; Tyler MarrsFri, 27 Mar 2020 00:45:00 GMTNikola (getnikola.com)http://blogs.law.harvard.edu/tech/rss- Quick Stats - Descriptive Statistics Part 2 - Medianhttp://tylermarrs.com/posts/quick-stats-descriptive-statistics-part-2-median/Tyler Marrs<div><p></p><h3>
Introduction
</h3>
<p>
In this next post on descriptive statistics, the median will be discussed. In <a href="http://tylermarrs.com/quick-stats-descriptive-statistics-part-1-mean/" target="_blank">part 1 of this blog series we learned about the mean (average)</a> and found out that it can easily be skewed by large or small values. Both the median and mean are "measures of central tendency". Central tendency is essentially the center position of a distribution for a data set. Now that you are refreshed, we can discuss the median.
</p>
<h3>
Median
</h3>
<p>
The median is simple to calculate. First, we must arrange the values from least to greatest. Next, we pick the center value - this is our median when there is an odd number of values. When there are an even number of values we simply add the two center values together and divide by 2.
</p>
<p>
Here are examples of both odd and even cases:
</p>
<p>
<strong>Odd number of values</strong>
</p>
<pre>
<code>1, 2, 3, 4, 5
Median = 3</code></pre>
<p>
<strong>Even number of values</strong>
</p>
<pre>
<code>1, 2, 3, 4
Median = (2 + 3) / 2 = 2.5</code></pre>
<h3>
Median vs. Mean
</h3>
<p>
As you can see the median is not influenced by outliers. It provides the central value that most of us tend to think of as the average (mean). You might ask when you would use one over the other. This question is difficult to answer without context. In some situations it may make more sense to use one or both. Let's look at some grades for 10 random students to see how the mean and median look.
</p>
<p>
The raw values are as follows:
</p>
<pre>
<code>20, 20, 25, 27, 29, 37, 45, 55, 90, 100</code></pre>
<p style="text-align: center;">
<img alt="" class="size-full wp-image-114 aligncenter" height="299" src="http://tylermarrs.com/wp-content/uploads/2017/01/exam_grades_median_mean.png" style="" title="" width="598">
</p>
<p>
In the plot, shown above, the blue line represents the mean - 44.8%. The green line represents the median - 33%. Clearly there is a difference between these two measures of central point.
</p>
<h3>
R
</h3>
<p>
To calculate the median in R - simply use the built in function.
</p>
<pre class="code literal-block"><span></span><code><span class="n">grades</span> <span class="o">&</span><span class="n">lt</span><span class="p">;</span><span class="o">-</span> <span class="nf">c</span><span class="p">(</span><span class="m">20</span><span class="p">,</span> <span class="m">20</span><span class="p">,</span> <span class="m">25</span><span class="p">,</span> <span class="m">27</span><span class="p">,</span> <span class="m">29</span><span class="p">,</span> <span class="m">37</span><span class="p">,</span> <span class="m">45</span><span class="p">,</span> <span class="m">55</span><span class="p">,</span> <span class="m">90</span><span class="p">,</span> <span class="m">100</span><span class="p">)</span>
<span class="n">median_grade</span> <span class="o">&</span><span class="n">lt</span><span class="p">;</span><span class="o">-</span> <span class="nf">median</span><span class="p">(</span><span class="n">grades</span><span class="p">)</span>
</code></pre>
<h3>
Python
</h3>
<p>
To calculate the median in Python we use Numpy. Import Numpy and use the median function.
</p>
<pre class="code literal-block"><span></span><code><span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span>
<span class="n">grades</span> <span class="o">=</span> <span class="p">[</span><span class="mi">20</span><span class="p">,</span> <span class="mi">20</span><span class="p">,</span> <span class="mi">25</span><span class="p">,</span> <span class="mi">27</span><span class="p">,</span> <span class="mi">29</span><span class="p">,</span> <span class="mi">37</span><span class="p">,</span> <span class="mi">45</span><span class="p">,</span> <span class="mi">55</span><span class="p">,</span> <span class="mi">90</span><span class="p">,</span> <span class="mi">100</span><span class="p">]</span>
<span class="n">median_grade</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">median</span><span class="p">(</span><span class="n">grades</span><span class="p">)</span>
</code></pre>
<h3>
Conclusion
</h3>
<p>
In this post we discussed the median and how it differentiates from the mean. We also established that context is important when deciding to use one versus the other. The mean and median are important values used in statistics and our every day lives.
</p>
<p>
The next article will discuss the mode - another useful descriptive statistic.
</p>
<p></p></div>descriptive-statisticsmedianpythonrstatisticshttp://tylermarrs.com/posts/quick-stats-descriptive-statistics-part-2-median/Wed, 25 Jan 2017 05:28:35 GMT