<p><div><div><div><div data-show-faces="false" data-height="21" data-width="100" data-layout="button_count" data-send="true" data-href="https://www.r-bloggers.com/undemocratic-democracies/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="https://diffuseprior.wordpress.com/2018/01/07/undemocratic-democracies/"> R – DiffusePrioR</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p><img data-orig-file="https://diffuseprior.files.wordpress.com/2018/01/democratic.png?w=456" data-orig-size="401,251" data-medium-file="https://diffuseprior.files.wordpress.com/2018/01/democratic.png?w=456?w=300" data-attachment-id="806" data-image-meta="{" data-image-description="" src="https://diffuseprior.files.wordpress.com/2018/01/democratic.png?w=456" data-permalink="https://diffuseprior.wordpress.com/2018/01/07/undemocratic-democracies/democratic/#main" data-large-file="https://diffuseprior.files.wordpress.com/2018/01/democratic.png?w=456?w=401" alt="democratic.png" data-image-title="democratic" sizes="(max-width: 401px) 100vw, 401px" data-comments-opened="1" class="wp-image-806" data-recalc-dims="1"></p>
<p>I’ve always thought that it was ironic that most countries with the word “Democratic” in their name are exceptionally un-democratic in reality. So I was very interested in the following post on Reddit this week showing exactly this (<a rel="nofollow" href="https://www.reddit.com/r/dataisbeautiful/comments/7nkyek/countries_with_the_word_democratic_in_their/" target="_blank">https://www.reddit.com/r/dataisbeautiful/comments/7nkyek/countries_with_the_word_democratic_in_their/</a>).</p>
<p>However, there are only 8 countries that have “democratic” in their name: People’s Democratic Republic of Algeria, Democratic Republic of the Congo, Democratic Republic of Timor-Leste, Federal Democratic Republic of Ethiopia, Lao People’s Democratic Republic, Democratic People’s Republic of Korea, Federal Democratic Republic of Nepal, and the Democratic Socialist Republic of Sri Lanka. This and the fact that I am back teaching next week got me thinking that this might be a nice example to show how two-sample t-tests work.</p>
<p>The 8 “democratic” countries have an overall democracy index score of 3.89 with a sample standard deviation of 2.174942. This contrasts with a mean and standard deviation of 5.602013 and 2.172326 for the remaining 159 countries in the Economist Intelligence Unit’s democracy index (<a rel="nofollow" href="https://en.wikipedia.org/wiki/Democracy_Index" target="_blank">https://en.wikipedia.org/wiki/Democracy_Index</a>).</p>
<p>Let’s conduct a two-sample t-test that assumes equal variances to test whether this difference in means is statistically significant. The null hypothesis is that both sample means are equal. This is a two-tailed test. The test statistic follows Gosset’s t-distribution with n1+n2-2 degrees of freedom (159+8-2=165). The test statistic is calculated (formula here: <a rel="nofollow" href="https://en.wikipedia.org/wiki/Student%27s_t-test" target="_blank">https://en.wikipedia.org/wiki/Student%27s_t-test</a>):</p>
<p>s = sqrt(((158*2.172326^2)+(7*2.174942^2))/(159+8-2))<br>
t = (5.602013-3.89)/(s*(sqrt(1/159+1/8)))=2.1749</p>
<p>which allows us to reject at the conventional alpha of 0.05. The p-value is ~0.03 meaning we would not be able to reject at the 1% level. Interestingly, if you do not follow the equal variance assumption, you can no longer reject the null at the 5% level.</p>
<p>Hopefully, this example will be of interest to people teaching stats and econometrics for undergrads!</p>
<p>
<p>
<p>
<p>
<pre>
rm(list = ls())
other &lt;- c(9.93, 9.5,	9.39,	9.26,	9.2,	9.15,	9.15,	9.09,	9.03,	9.01,	8.81,	8.8,	8.63,	8.41,	8.39,	8.36,	8.3,	8.28,	8.17,	7.99,	7.98,	7.98,	7.94,	7.92,	7.92,	7.88,	7.87,	7.86,	7.85,	7.85,	7.82,	7.81,	7.79,	7.78,	7.77,	7.65,	7.51,	7.47,	7.41,	7.39,	7.31,	7.29,	7.23,	7.13,	7.1,	7.01,	6.97,	6.96,	6.94,	6.9,	6.83,	6.77,	6.75,	6.75,	6.72,	6.67,	6.67,	6.65,	6.64,	6.62,	6.62,	6.59,	6.57,	6.54,	6.47,	6.42,	6.4,	6.38,	6.31,	6.27,	6.25,	6.21,	6.03,	6.01,	5.99,	5.93,	5.92,	5.92,	5.91,	5.81,	5.76,	5.73,	5.72,	5.7,	5.7,	5.67,	5.64,	5.63,	5.55,	5.33,	5.31,	5.26,	5.23,	5.07,	5.04,	4.93,	4.93,	4.92,	4.87,	4.86,	4.81,	4.77,	4.7,	4.68,	4.55,	4.5,	4.49,	4.33,	4.27,	4.2,	4.08,	4.02,	4.02,	3.96,	3.96,	3.96,	3.88,	3.85,	3.81,	3.74,	3.71,	3.54,	3.46,	3.46,	3.4,	3.38,	3.32,	3.31,	3.24,	3.18,	3.14,	3.14,	3.07,	3.06,	3.05,	3.04,	3.03,	2.91,	2.91,	2.83,	2.79,	2.75,	2.65,	2.55,	2.4,	2.37,	2.37,	2.34,	2.25,	2.06,	1.98,	1.95,	1.93,	1.89,	1.83,	1.7,	1.61,	1.5,	1.43)
demo &lt;- c(7.24, 6.48, 4.86, 3.6, 3.56, 2.37, 1.93, 1.08)

mean(other) ; sd(other) ; length(other)
mean(demo) ; sd(demo) ; length(demo)

t.test(other, demo, var.equal = T)
s = sqrt(((158*2.172326^2)+(7*2.174942^2))/(159+8-2))
t = (5.602013-3.89)/(s*(sqrt(1/159+1/8)))

t.test(other, demo, var.equal = F)

library(ggplot2)
data1 &lt;- data.frame(Score = other, Name = &quot;No&quot;)
data2 &lt;- data.frame(Score = demo, Name = &quot;Yes&quot;)
data &lt;- rbind(data1, data2)

ggplot(data, aes(Name, Score)) + 
  geom_boxplot(fill=&quot;lightblue&quot;) +
  theme_bw() +
  xlab(&quot;Democratic in Name&quot;) +
  ylab(&quot;Democracy Score&quot;)

</pre>
<p> </p>
<p> <a rel="nofollow" href="https://feeds.wordpress.com/1.0/gocomments/diffuseprior.wordpress.com/805/" target="_blank"><img border="0" alt="" src="https://feeds.wordpress.com/1.0/comments/diffuseprior.wordpress.com/805/"></a> <img border="0" src="https://i1.wp.com/pixel.wp.com/b.gif?resize=1%2C1&ssl=1" alt="" width="1" data-recalc-dims="1" height="1"></p>
	<p>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="https://diffuseprior.wordpress.com/2018/01/07/undemocratic-democracies/"> R – DiffusePrioR</a></strong>.</div>
<hr>
<a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers.com</a> offers <strong><a rel="nofollow" href="https://feedburner.google.com/fb/a/mailverify?uri=RBloggers">daily e-mail updates</a></strong> about <a rel="nofollow" href="https://www.r-project.org/" title="The R Project for Statistical Computing">R</a> news and <a rel="nofollow" href="https://www.r-bloggers.com/search/tutorial" title="R tutorials">tutorials</a> on topics such as: <a rel="nofollow" href="https://www.r-bloggers.com/search/data%20science" title="Data science">Data science</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Big%20Data" title="Big Data">Big Data, <a rel="nofollow" href="https://www.r-users.com/" title="R jobs">R jobs</a>, visualization (<a rel="nofollow" href="https://www.r-bloggers.com/search/ggplot2" title="ggplot and ggplot2 tutorials">ggplot2</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/boxplot" title="Boxplots using lattice and ggplot2 tutorials">Boxplots</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/map" title="Maps and gis">maps</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/animation" title="Animation in R">animation</a>), programming (<a rel="nofollow" href="https://www.r-bloggers.com/search/RStudio" title="RStudio IDE for R">RStudio</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/sweave" title="Sweave and literate programming">Sweave</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/LaTeX" title="LaTeX in R">LaTeX</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/SQL" title="SQL and databases">SQL</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/eclipse" title="Eclipse IDE for R">Eclipse</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/git" title="git and github, Version Control System">git</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/hadoop" title="Large data in R using Hadoop">hadoop</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Web+Scraping" title="Web Scraping of google, facebook, yahoo, twitter and more using R">Web Scraping</a>) statistics (<a rel="nofollow" href="https://www.r-bloggers.com/search/regression" title="Regressions and ANOVA analysis tutorials">regression</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/PCA" title="principal component analysis tutorial">PCA</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/time+series" title="Time series">time series</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/trading" title="finance trading">trading</a>) and more...
<img alt="" width="1" src="http://feeds.feedburner.com/~r/RBloggers/~4/Ze96qh1DtOc" height="1"></a></div>