<p><div><div><div><div data-width="100" data-show-faces="false" data-send="true" data-layout="button_count" data-height="21" data-href="https://www.r-bloggers.com/data-analytics-for-societal-good/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="http://aliarsalankazmi.github.io/posts/r/2017/03/22/data_for_social_good_pk_minorities.html"> R</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p>At my workplace, employees celebrate a month of Data Analysis for Societal good, every year. During this time, we try to help NPOs (Non-Profit Organisations) in gaining insights from their data, for free. Whilst we are engaged in this practice at workplace, I needed to do something at a personal level too. So I thought about analysing attacks on minorities in PK, following which I could contact any NPOs and share insights with them, to help them better raise awareness<br>
.</p>
<p>One of the minorities in PK are Shia Muslims, who are often targeted for their faith (<em>although this is, by no means, a problem limited to PK</em>). Target killing Shia professionals (Doctors, Administrators, Educators, etc.) and detonating bombs in their religious gatherings and marketplaces have <a target="_blank" rel="nofollow" href="http://www.shaheedfoundation.co.uk/shia-killing.asp">become the norm</a>. To help the bereaved families of the victims of such attacks, <a target="_blank" rel="nofollow" href="http://www.shaheedfoundation.co.uk/projects.asp#fin">Shaheed Foundation in the UK</a> and <a target="_blank" rel="nofollow" href="http://www.shaheedfoundation.org/">Pakistan</a> have been working on various projects, including those about <a target="_blank" rel="nofollow" href="http://www.shaheedfoundation.co.uk/projects.asp#edu">Education</a>, <a target="_blank" rel="nofollow" href="http://www.shaheedfoundation.co.uk/projects.asp#fam">Family Support</a>,<br>
<a target="_blank" rel="nofollow" href="http://www.shaheedfoundation.co.uk/projects.asp#med">Medical</a>, and <a target="_blank" rel="nofollow" href="http://www.shaheedfoundation.co.uk/projects.asp#fin">Micro-finance/Self-fund</a>.</p>
<p>The Foundation has shared a link to a flatfile database, which was formed by a third party and supposedly captures most of attacks on Shia Muslims across Pakistan from 2012 until Mid 2015 (the data go back to 1970s, but the third party have specifically asked not to use pre-2012 data for Statistical analysis. What follows is my attempt at gaining insights from the data.</p>
<h3>Basic Reporting</h3>
<p><a target="_blank" rel="nofollow" href="https://i1.wp.com/aliarsalankazmi.github.io/blog_DA/assets/img/sk_mar17_provComp_g1.png"><img src="https://i1.wp.com/aliarsalankazmi.github.io/blog_DA/assets/img/sk_mar17_provComp_g1.png?w=456" data-recalc-dims="1"></a></p>
<p>Graph above shows the number of Shias killed and injured in attacks for each province in Pakistan. Clearly, the Sindh has the highest number of Shias killed, followed by Balochistan, although for number of injuries, Balochistan ranks higher than Sindh. Also for injuries, we see other provinces like Punjab, FATA, and Khyber Pakhtunkhwa have similar figures, although they vary for number of deaths.<br>
Figures from Sindh are unsurprising, as one of its main city has been notorious for targeted killings, until the army took action recently against terrorists. On the other hand, the high number of injuries in Balochistan can be attributed to the large number of bomb detonations and suicide attacks.</p>
<p><a target="_blank" rel="nofollow" href="https://i0.wp.com/aliarsalankazmi.github.io/blog_DA/assets/img/sk_mar17_provComp_g2.png"><img src="https://i0.wp.com/aliarsalankazmi.github.io/blog_DA/assets/img/sk_mar17_provComp_g2.png?w=456" data-recalc-dims="1"></a></p>
<p>If we calculate the proportion of killings and injuries for each province, we see that Gilgit Baltistan and Sindh have had more killings than other provinces during 2012-2015.</p>
<p><a target="_blank" rel="nofollow" href="https://i2.wp.com/aliarsalankazmi.github.io/blog_DA/assets/img/sk_mar17_dist_g3.png"><img src="https://i2.wp.com/aliarsalankazmi.github.io/blog_DA/assets/img/sk_mar17_dist_g3.png?w=456" data-recalc-dims="1"></a></p>
<p>We can plot the distribution of killings (excluding injuries) for each province with a Violin plot, with a white point superimposed, showing the mean number of killings. We can further break down the violin plots for quartiles to see how the data distribution varies within each, whilst showing the raw data points in white and the mean number of killings in yellow.</p>
<p><a target="_blank" rel="nofollow" href="https://i2.wp.com/aliarsalankazmi.github.io/blog_DA/assets/img/sk_mar17_dist_g3.png"><img src="https://i2.wp.com/aliarsalankazmi.github.io/blog_DA/assets/img/sk_mar17_dist_g3.png?w=456" data-recalc-dims="1"></a><br>
<a target="_blank" rel="nofollow" href="https://i0.wp.com/aliarsalankazmi.github.io/blog_DA/assets/img/sk_mar17_dist_g4.png"><img src="https://i0.wp.com/aliarsalankazmi.github.io/blog_DA/assets/img/sk_mar17_dist_g4.png?w=456" data-recalc-dims="1"></a></p>
<p>We can see that Sindh and Balochistan have the highest number of killings in Quartile 1, although the mean number of killings is highest for Balochistan in each quartile (except in Quartile 2, wherein it is the second highest). For Sindh, most of the data points actually fall within the 1st Quartile.</p>
<p>It is often the case that during Religious festivities or gatherings, attacks on Shias are reported to increase. Muharram is such a month when Shia Muslims gather in large numbers, so it may be that they are increasingly targeted during this time. Following is a graph that shows a time series of Shia killings with the month of Muharram superimposed from each year (2012 – 2015).</p>
<p><a target="_blank" rel="nofollow" href="https://i2.wp.com/aliarsalankazmi.github.io/blog_DA/assets/img/sk_mar17_ts_g5.png"><img src="https://i2.wp.com/aliarsalankazmi.github.io/blog_DA/assets/img/sk_mar17_ts_g5.png?w=456" data-recalc-dims="1"></a></p>
<p>After superimposing Muharram months, only Punjab and Khyber Pakhtunkhwa stand out as provinces where at least one spike in number of killings is seen during Muharram. But the chart above only accounts for the number of killings. We can, instead, sum up the number of Shia Muslims killed and injured to calculate the number of casualties, and then subtract each month’s ‘distance’ from the month of Muharram to see if attacks increase close to or during the month of Muharram.</p>
<p>For this, I first generated a simple time series plot, as shown below.</p>
<p><a target="_blank" rel="nofollow" href="https://i1.wp.com/aliarsalankazmi.github.io/blog_DA/assets/img/sk_mar17_cts_g6a0.png"><img src="https://i1.wp.com/aliarsalankazmi.github.io/blog_DA/assets/img/sk_mar17_cts_g6a0.png?w=456" data-recalc-dims="1"></a></p>
<p>But I felt the above was slightly difficult to look at, because I wanted to present the information in a different way: Muharram is the 1st month of the Islamic calendar (which comprises of 12 months), and I needed to show the flow of months such that the 2nd or 3rd months are as close to Muharram as the 11th or 12th months. This was possible to achieve if we changed to polar coordinates, ending up with the following circular time-series plot.</p>
<p><a target="_blank" rel="nofollow" href="https://i1.wp.com/aliarsalankazmi.github.io/blog_DA/assets/img/sk_mar17_cts_g6a.png"><img src="https://i1.wp.com/aliarsalankazmi.github.io/blog_DA/assets/img/sk_mar17_cts_g6b.png?w=456" data-recalc-dims="1"></a></p>
<p>With this plot, I think it becomes easier to spot any surge or drop in the GAM smoother. As it appears, Punjab, Sindh, and FATA do appear to have more data points in or close to Muharram, with the smoother slightly shifting up in the case of Punjab. We can further split the smoother on years.</p>
<p><a target="_blank" rel="nofollow" href="https://i1.wp.com/aliarsalankazmi.github.io/blog_DA/assets/img/sk_mar17_cts_g6c.png"><img src="https://i0.wp.com/aliarsalankazmi.github.io/blog_DA/assets/img/sk_mar17_cts_g6d.png?w=456" data-recalc-dims="1"></a></p>
<p>Now, it appears that for years prior to 2014, casualties in or close to Muharram were higher than they were in 2014. This is not applicable to Sindh, however, as we see that the trend remains constant throughout the years, with very little difference (if any) in the number of casualties.</p>
<h3>Inference: Permutation Testing</h3>
<p>I was recently introduced to Permutation Testing whilst reading the <a target="_blank" rel="nofollow" href="https://ismayc.github.io/moderndiver-book/7-hypo.html">Modern Dive – An Introduction to Statistical and Data Sciences via R</a>. Having specialised in Data Mining, I had not had to dwell so much on checking assumptions for normality, learning the various distributions, etc. – the focus would be on prediction rather than inference. But Permutation Testing and Bootstrapped Confidence Intervals were intuitive to me, so I took to reading about it.</p>
<p>Following my reading, I thought about comparing the mean number of casualties from Muharram and non-Muharram months, assuming an exchangeable sequence of random variables (or that future samples will be similar to the present sample).</p>
<p>Null Hypothesis: There is <em>no</em> difference in the average number of casualties in Muharram and non-Muharram months<br>
Alternative Hypothesis: There is a difference in the average number of casualties in Muharram and non-Muharram months</p>
<p>The average number of casualties in Muharram (from 2012 to 2015) was 5.34, whereas for other months this figure is 3.45; the difference is 1.89. Doing permutation testing on this with 50,000 repetitions, the following distribution of the differences in means is produced, with the original difference highlighted with a red line.</p>
<p><a target="_blank" rel="nofollow" href="https://i1.wp.com/aliarsalankazmi.github.io/blog_DA/assets/img/sk_mar17_hyptst_g7a.png"><img src="https://i1.wp.com/aliarsalankazmi.github.io/blog_DA/assets/img/sk_mar17_hyptst_g7a.png?w=456" data-recalc-dims="1"></a></p>
<p>The p-value achieved here is 0.075, which is higher than our significance level of 0.05, hence we are unable to reject the Null Hypothesis.</p>
<h3>Bootstrapped Confidence Intervals</h3>
<p>I then thought about calculating the 95% Confidence Intervals to identify the range in which the mean number of casualties in provinces (regardless of the month) will fall. This was done with bootstrapping the data for each province. The following shows a histogram of means from each bootstrapped sample (total 10,000).</p>
<p><a target="_blank" rel="nofollow" href="https://i1.wp.com/aliarsalankazmi.github.io/blog_DA/assets/img/sk_mar17_hyptst_g7b.png"><img src="https://i1.wp.com/aliarsalankazmi.github.io/blog_DA/assets/img/sk_mar17_hyptst_g7b.png?w=456" data-recalc-dims="1"></a></p>
<p><a target="_blank" rel="nofollow" href="https://i1.wp.com/aliarsalankazmi.github.io/blog_DA/assets/img/sk_mar17_hyptst_g7c.png"><img src="https://i1.wp.com/aliarsalankazmi.github.io/blog_DA/assets/img/sk_mar17_hyptst_g7c.png?w=456" data-recalc-dims="1"></a></p>
<p>Sindh again comes out as having a very small confidence interval, showing that on average a person or two of Shia Muslims are either killed or injured. The confidence interval is highest for Balochistan and FATA (Federally Administered Tribal Areas), for which the range of casualties on average is from 6 to 15, and 5 to 17, respectively.</p>
<p>The code used in this post can be found <a target="_blank" rel="nofollow" href="https://github.com/aliarsalankazmi/skPk_analysis/blob/master/excelDB_analysis_v1.txt">here</a>.</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="http://aliarsalankazmi.github.io/posts/r/2017/03/22/data_for_social_good_pk_minorities.html"> R</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 title="The R Project for Statistical Computing" rel="nofollow" href="https://www.r-project.org/">R</a> news and <a title="R tutorials" rel="nofollow" href="https://www.r-bloggers.com/search/tutorial">tutorials</a> on topics such as: <a title="Data science" rel="nofollow" href="https://www.r-bloggers.com/search/data%20science">Data science</a>, <a title="Big Data" rel="nofollow" href="https://www.r-bloggers.com/search/Big%20Data">Big Data, <a title="R jobs" rel="nofollow" href="https://www.r-users.com/">R jobs</a>, visualization (<a title="ggplot and ggplot2 tutorials" rel="nofollow" href="https://www.r-bloggers.com/search/ggplot2">ggplot2</a>, <a title="Boxplots using lattice and ggplot2 tutorials" rel="nofollow" href="https://www.r-bloggers.com/search/boxplot">Boxplots</a>, <a title="Maps and gis" rel="nofollow" href="https://www.r-bloggers.com/search/map">maps</a>, <a title="Animation in R" rel="nofollow" href="https://www.r-bloggers.com/search/animation">animation</a>), programming (<a title="RStudio IDE for R" rel="nofollow" href="https://www.r-bloggers.com/search/RStudio">RStudio</a>, <a title="Sweave and literate programming" rel="nofollow" href="https://www.r-bloggers.com/search/sweave">Sweave</a>, <a title="LaTeX in R" rel="nofollow" href="https://www.r-bloggers.com/search/LaTeX">LaTeX</a>, <a title="SQL and databases" rel="nofollow" href="https://www.r-bloggers.com/search/SQL">SQL</a>, <a title="Eclipse IDE for R" rel="nofollow" href="https://www.r-bloggers.com/search/eclipse">Eclipse</a>, <a title="git and github, Version Control System" rel="nofollow" href="https://www.r-bloggers.com/search/git">git</a>, <a title="Large data in R using Hadoop" rel="nofollow" href="https://www.r-bloggers.com/search/hadoop">hadoop</a>, <a title="Web Scraping of google, facebook, yahoo, twitter and more using R" rel="nofollow" href="https://www.r-bloggers.com/search/Web+Scraping">Web Scraping</a>) statistics (<a title="Regressions and ANOVA analysis tutorials" rel="nofollow" href="https://www.r-bloggers.com/search/regression">regression</a>, <a title="principal component analysis tutorial" rel="nofollow" href="https://www.r-bloggers.com/search/PCA">PCA</a>, <a title="Time series" rel="nofollow" href="https://www.r-bloggers.com/search/time+series">time series</a>, <a title="finance trading" rel="nofollow" href="https://www.r-bloggers.com/search/trading">trading</a>) and more...
<img height="1" alt="" width="1" src="http://feeds.feedburner.com/~r/RBloggers/~4/kE2XxdAt4m0"></a></div>