Take Home Exercise 4

Author

Zachary Wong

Published

March 3, 2024

Modified

March 19, 2024

Prototyping Modules for Visual Analytics Shiny Application

Prototyping is Crucial

Prototyping first may help keep you from investing far too much time for marginal gains.

The Art of UNIX Programming (Raymond 2003)

The Task

In this take-home exercise, you are required to select one of the module of your proposed Shiny application and complete the following tasks:

  • To evaluate and determine the necessary R packages needed for your Shiny application are supported in R CRAN,

  • To prepare and test the specific R codes can be run and returned the correct output as expected,

  • To determine the parameters and outputs that will be exposed on the Shiny applications, and

  • To select the appropriate Shiny UI components for exposing the parameters determine above.

All teams must consult the prototype page of AY2022-2023 January Term Group 3: Tanzania Tourism Analysis. There are three main modules in ths application the are: Exploratory Data Analysis & Confirmatory Data Analysis, Cluster Analysis and Decision Tree Analysis. Each of them were prepared by one of the member of the project team. After that they combined them into the Prototype page of their project website.

Take-home Exercise 4 will be similar to one of the prototype module prepared above in term of content but with the following differences:

  • You are required to prepare the prototype module report as Take-home Exercise 4 submission. This mean, it has to be published on your own coursework page.

  • You are required to include a section called UI design for the different components of the UIs for the proposed design.

For storyboarding the UI Design, please consult Storyboard link.

Submission Instructions

This is an individual assignment. You are required to work on the take-home exercises and prepare submission individually.

The specific submission instructions are as follows:

  • The analytical visualisation must be prepared by using R and appropriate R packages. The report must provide detail discussion and explanation of:

    • the data preparation process,

    • the selection of data visualisation techniques used,

    • and the data visualisation design and interactivity principles and best practices implemented.

  • The write-up of the take-home exercise must be in Quarto html document format and publish on Netlify.

Topic: Decoding Chaos

The topic our group has chosen is about armed conflicts in Myanmar. The aim is to attempt to review through the open-sourced data obtained using various visual analytics techniques and possibly be able to weed out interesting conclusions. The shiny app would be create an analytical user interface whereby users are able to filter and explore by themselves if they can derive their own conclusion through their own assumptions and exploration.

Our main project website can be found here.

The Dataset

The dataset is obtained from Armed Conflict Location & Event Data Project website. The website provides datasets of conflict in various regions which users can obtain to conduct their own data analysis based on the region they are interested in. The datasets can also be used to conduct geospatial analysis which is something that is still developing and improving over time.

For our project, we would be mainly focusing on the Myanmar region due to the recent increase in conflict post military coup in 2021.

The data being used is titled 2010-01-01-2023-12-31-Southeast_Asia-Myanmar.csv.

Installing and Launching R Packages

Code
pacman::p_load(shiny, tidyverse, shinydashboard,dplyr,
               spatstat, spdep,
               lubridate, leaflet,
               plotly, DT, viridis,
               ggplot2, sf, tmap, readr,
               scales,ggthemes,gridExtra,knitr,data.table,
               CGPfunctions, ggHoriPlot, patchwork)

Data

Code
Myanmar <- read_csv("data/2010-01-01-2023-12-31-Southeast_Asia-Myanmar.csv")

glimpse(Myanmar)
Rows: 55,574
Columns: 31
$ event_id_cnty      <chr> "MMR56099", "MMR56222", "MMR56370", "MMR56376", "MM…
$ event_date         <chr> "31 December 2023", "31 December 2023", "31 Decembe…
$ year               <dbl> 2023, 2023, 2023, 2023, 2023, 2023, 2023, 2023, 202…
$ time_precision     <dbl> 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, …
$ disorder_type      <chr> "Political violence", "Political violence", "Politi…
$ event_type         <chr> "Explosions/Remote violence", "Explosions/Remote vi…
$ sub_event_type     <chr> "Shelling/artillery/missile attack", "Shelling/arti…
$ actor1             <chr> "Military Forces of Myanmar (2021-)", "Military For…
$ assoc_actor_1      <chr> NA, NA, NA, NA, NA, NA, "Daw Na Column; YGF: Ye Gue…
$ inter1             <dbl> 1, 1, 3, 6, 1, 1, 3, 1, 2, 1, 1, 2, 2, 1, 1, 3, 3, …
$ actor2             <chr> NA, "Civilians (Myanmar)", "Military Forces of Myan…
$ assoc_actor_2      <chr> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,…
$ inter2             <dbl> 0, 7, 1, 0, 7, 0, 1, 0, 1, 7, 7, 1, 1, 0, 0, 1, 1, …
$ interaction        <dbl> 10, 17, 13, 60, 17, 10, 13, 10, 12, 17, 17, 12, 12,…
$ civilian_targeting <chr> NA, "Civilian targeting", NA, NA, NA, NA, NA, NA, N…
$ iso                <dbl> 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, 1…
$ region             <chr> "Southeast Asia", "Southeast Asia", "Southeast Asia…
$ country            <chr> "Myanmar", "Myanmar", "Myanmar", "Myanmar", "Myanma…
$ admin1             <chr> "Mon", "Rakhine", "Bago-West", "Sagaing", "Bago-Wes…
$ admin2             <chr> "Mawlamyine", "Maungdaw", "Thayarwady", "Yinmarbin"…
$ admin3             <chr> "Ye", "Maungdaw", "Nattalin", "Salingyi", "Nattalin…
$ location           <chr> "Aing Shey", "Kaing Gyi (NaTaLa)", "Kyauk Pyoke", "…
$ latitude           <dbl> 15.2856, 20.7219, 18.6245, 22.0608, 18.6245, 21.199…
$ longitude          <dbl> 98.0052, 92.4429, 95.8295, 95.1387, 95.8295, 92.200…
$ geo_precision      <dbl> 1, 2, 2, 2, 1, 1, 1, 2, 2, 1, 1, 1, 1, 1, 1, 1, 2, …
$ source             <chr> "Democratic Voice of Burma", "Development Media Gro…
$ source_scale       <chr> "National", "Subnational", "National", "National", …
$ notes              <chr> "On 31 December 2023, in Aing Shey village (Ye town…
$ fatalities         <dbl> 0, 0, 4, 0, 0, 0, 3, 0, 0, 0, 1, 0, 0, 0, 0, 1, 2, …
$ tags               <chr> NA, NA, NA, "crowd size=no report", NA, NA, NA, NA,…
$ timestamp          <dbl> 1704831212, 1704831213, 1704831214, 1704831214, 170…
Code
kable(head(Myanmar))
event_id_cnty event_date year time_precision disorder_type event_type sub_event_type actor1 assoc_actor_1 inter1 actor2 assoc_actor_2 inter2 interaction civilian_targeting iso region country admin1 admin2 admin3 location latitude longitude geo_precision source source_scale notes fatalities tags timestamp
MMR56099 31 December 2023 2023 1 Political violence Explosions/Remote violence Shelling/artillery/missile attack Military Forces of Myanmar (2021-) NA 1 NA NA 0 10 NA 104 Southeast Asia Myanmar Mon Mawlamyine Ye Aing Shey 15.2856 98.0052 1 Democratic Voice of Burma National On 31 December 2023, in Aing Shey village (Ye township, Mawlamyine district, Mon state), following a clash between the military and resistance forces in Kyaung Ywar village (coded separately), the military (LIB-591 and LIB-583) fired artillery rounds into the village. Casualties unknown. 0 NA 1704831212
MMR56222 31 December 2023 2023 1 Political violence Explosions/Remote violence Shelling/artillery/missile attack Military Forces of Myanmar (2021-) NA 1 Civilians (Myanmar) NA 7 17 Civilian targeting 104 Southeast Asia Myanmar Rakhine Maungdaw Maungdaw Kaing Gyi (NaTaLa) 20.7219 92.4429 2 Development Media Group; Narinjara News Subnational On 31 December 2023, in Kaing Gyi (Mro) village (coded as Kaing Gyi (NaTaLa)) (Maungdaw township, Maungdaw district, Rakhine state), Myanmar military troops from the Maw Ra Waddy strategic hill fired artillery rounds indiscriminately into the village at around 8:30 am. Some artillery shells landed on the village main road, injuring two women and a man. 0 NA 1704831213
MMR56370 31 December 2023 2023 1 Political violence Battles Armed clash Phoenix DF: Phoenix Defense Force (Nattalin) NA 3 Military Forces of Myanmar (2021-) NA 1 13 NA 104 Southeast Asia Myanmar Bago-West Thayarwady Nattalin Kyauk Pyoke 18.6245 95.8295 2 Khit Thit Media; Myanmar Pressphoto Agency National On 31 December 2023, near Kyauk Pyoke village (Nattalin township, Thayarwady district, Bago-West region), the Phoenix Defense Force (Nattalin) carried out mine attacks against a Myanmar military column of about 130 troops advancing towards Bago Yoma mountain range in the morning. The two sides then exchanged fire. Four military troops were killed. 4 NA 1704831214
MMR56376 31 December 2023 2023 1 Demonstrations Protests Peaceful protest Protesters (Myanmar) NA 6 NA NA 0 60 NA 104 Southeast Asia Myanmar Sagaing Yinmarbin Salingyi Let Pa Taung 22.0608 95.1387 2 Myanmar Labour News National On 31 December 2023, in the Let Pa Taung area of Salingyi township (Yinmarbin district, Sagaing region), protesters and locals held a protest against the Myanmar military coup with the banner ‘China: Stand Together with the Oppressed People of Myanmar’. 0 crowd size=no report 1704831214
MMR56380 31 December 2023 2023 1 Strategic developments Strategic developments Looting/property destruction Military Forces of Myanmar (2021-) NA 1 Civilians (Myanmar) NA 7 17 NA 104 Southeast Asia Myanmar Bago-West Thayarwady Nattalin Kyauk Pyoke 18.6245 95.8295 1 Myanmar Pressphoto Agency National Property destruction: On 31 December 2023, in Kyauk Pyoke village (Nattalin township, Thayarwady district, Bago-West region), the Myanmar military set fire to some houses in the village. 0 NA 1704831214
MMR56869 31 December 2023 2023 1 Strategic developments Strategic developments Change to group/activity Military Forces of Myanmar (2021-) NA 1 NA NA 0 10 NA 104 Southeast Asia Myanmar Rakhine Maungdaw Maungdaw Taungpyoletwea 21.1999 92.2007 1 Democratic Voice of Burma National Movement of forces: On 31 December 2023, in Taungpyoletwea town (Maungdaw township, Maungdaw district, Rakhine state), the Myanmar military secretly transported weapons, ammunition, and rations to the town using motorboats at night. 0 NA 1704831216
Code
str(Myanmar)
spc_tbl_ [55,574 × 31] (S3: spec_tbl_df/tbl_df/tbl/data.frame)
 $ event_id_cnty     : chr [1:55574] "MMR56099" "MMR56222" "MMR56370" "MMR56376" ...
 $ event_date        : chr [1:55574] "31 December 2023" "31 December 2023" "31 December 2023" "31 December 2023" ...
 $ year              : num [1:55574] 2023 2023 2023 2023 2023 ...
 $ time_precision    : num [1:55574] 1 1 1 1 1 1 1 1 1 1 ...
 $ disorder_type     : chr [1:55574] "Political violence" "Political violence" "Political violence" "Demonstrations" ...
 $ event_type        : chr [1:55574] "Explosions/Remote violence" "Explosions/Remote violence" "Battles" "Protests" ...
 $ sub_event_type    : chr [1:55574] "Shelling/artillery/missile attack" "Shelling/artillery/missile attack" "Armed clash" "Peaceful protest" ...
 $ actor1            : chr [1:55574] "Military Forces of Myanmar (2021-)" "Military Forces of Myanmar (2021-)" "Phoenix DF: Phoenix Defense Force (Nattalin)" "Protesters (Myanmar)" ...
 $ assoc_actor_1     : chr [1:55574] NA NA NA NA ...
 $ inter1            : num [1:55574] 1 1 3 6 1 1 3 1 2 1 ...
 $ actor2            : chr [1:55574] NA "Civilians (Myanmar)" "Military Forces of Myanmar (2021-)" NA ...
 $ assoc_actor_2     : chr [1:55574] NA NA NA NA ...
 $ inter2            : num [1:55574] 0 7 1 0 7 0 1 0 1 7 ...
 $ interaction       : num [1:55574] 10 17 13 60 17 10 13 10 12 17 ...
 $ civilian_targeting: chr [1:55574] NA "Civilian targeting" NA NA ...
 $ iso               : num [1:55574] 104 104 104 104 104 104 104 104 104 104 ...
 $ region            : chr [1:55574] "Southeast Asia" "Southeast Asia" "Southeast Asia" "Southeast Asia" ...
 $ country           : chr [1:55574] "Myanmar" "Myanmar" "Myanmar" "Myanmar" ...
 $ admin1            : chr [1:55574] "Mon" "Rakhine" "Bago-West" "Sagaing" ...
 $ admin2            : chr [1:55574] "Mawlamyine" "Maungdaw" "Thayarwady" "Yinmarbin" ...
 $ admin3            : chr [1:55574] "Ye" "Maungdaw" "Nattalin" "Salingyi" ...
 $ location          : chr [1:55574] "Aing Shey" "Kaing Gyi (NaTaLa)" "Kyauk Pyoke" "Let Pa Taung" ...
 $ latitude          : num [1:55574] 15.3 20.7 18.6 22.1 18.6 ...
 $ longitude         : num [1:55574] 98 92.4 95.8 95.1 95.8 ...
 $ geo_precision     : num [1:55574] 1 2 2 2 1 1 1 2 2 1 ...
 $ source            : chr [1:55574] "Democratic Voice of Burma" "Development Media Group; Narinjara News" "Khit Thit Media; Myanmar Pressphoto Agency" "Myanmar Labour News" ...
 $ source_scale      : chr [1:55574] "National" "Subnational" "National" "National" ...
 $ notes             : chr [1:55574] "On 31 December 2023, in Aing Shey village (Ye township, Mawlamyine district, Mon state), following a clash betw"| __truncated__ "On 31 December 2023, in Kaing Gyi (Mro) village (coded as Kaing Gyi (NaTaLa)) (Maungdaw township, Maungdaw dist"| __truncated__ "On 31 December 2023, near Kyauk Pyoke village (Nattalin township, Thayarwady district, Bago-West region), the P"| __truncated__ "On 31 December 2023, in the Let Pa Taung area of Salingyi township (Yinmarbin district, Sagaing region), protes"| __truncated__ ...
 $ fatalities        : num [1:55574] 0 0 4 0 0 0 3 0 0 0 ...
 $ tags              : chr [1:55574] NA NA NA "crowd size=no report" ...
 $ timestamp         : num [1:55574] 1.7e+09 1.7e+09 1.7e+09 1.7e+09 1.7e+09 ...
 - attr(*, "spec")=
  .. cols(
  ..   event_id_cnty = col_character(),
  ..   event_date = col_character(),
  ..   year = col_double(),
  ..   time_precision = col_double(),
  ..   disorder_type = col_character(),
  ..   event_type = col_character(),
  ..   sub_event_type = col_character(),
  ..   actor1 = col_character(),
  ..   assoc_actor_1 = col_character(),
  ..   inter1 = col_double(),
  ..   actor2 = col_character(),
  ..   assoc_actor_2 = col_character(),
  ..   inter2 = col_double(),
  ..   interaction = col_double(),
  ..   civilian_targeting = col_character(),
  ..   iso = col_double(),
  ..   region = col_character(),
  ..   country = col_character(),
  ..   admin1 = col_character(),
  ..   admin2 = col_character(),
  ..   admin3 = col_character(),
  ..   location = col_character(),
  ..   latitude = col_double(),
  ..   longitude = col_double(),
  ..   geo_precision = col_double(),
  ..   source = col_character(),
  ..   source_scale = col_character(),
  ..   notes = col_character(),
  ..   fatalities = col_double(),
  ..   tags = col_character(),
  ..   timestamp = col_double()
  .. )
 - attr(*, "problems")=<externalptr> 

Based on the information above, our dataset consists of 31 variables and 55,574 observations. The date range used for our study would be between 1st Jan 2010 to 31st Dec 2023. The detailed description and explanation of each variable can be found in the codebook provided by ACLED.

Data Wrangling

The flowchart above shows some of the additional variables that will be created and used in this project.

Adjusting Attributes

The code below changes the attributes of some of the variables shown above so that we can properly use them for analysis

Code
Myanmar <- Myanmar %>%
  mutate(year =factor(year))

Myanmar$event_date <- dmy(Myanmar$event_date)

str(Myanmar)
tibble [55,574 × 31] (S3: tbl_df/tbl/data.frame)
 $ event_id_cnty     : chr [1:55574] "MMR56099" "MMR56222" "MMR56370" "MMR56376" ...
 $ event_date        : Date[1:55574], format: "2023-12-31" "2023-12-31" ...
 $ year              : Factor w/ 14 levels "2010","2011",..: 14 14 14 14 14 14 14 14 14 14 ...
 $ time_precision    : num [1:55574] 1 1 1 1 1 1 1 1 1 1 ...
 $ disorder_type     : chr [1:55574] "Political violence" "Political violence" "Political violence" "Demonstrations" ...
 $ event_type        : chr [1:55574] "Explosions/Remote violence" "Explosions/Remote violence" "Battles" "Protests" ...
 $ sub_event_type    : chr [1:55574] "Shelling/artillery/missile attack" "Shelling/artillery/missile attack" "Armed clash" "Peaceful protest" ...
 $ actor1            : chr [1:55574] "Military Forces of Myanmar (2021-)" "Military Forces of Myanmar (2021-)" "Phoenix DF: Phoenix Defense Force (Nattalin)" "Protesters (Myanmar)" ...
 $ assoc_actor_1     : chr [1:55574] NA NA NA NA ...
 $ inter1            : num [1:55574] 1 1 3 6 1 1 3 1 2 1 ...
 $ actor2            : chr [1:55574] NA "Civilians (Myanmar)" "Military Forces of Myanmar (2021-)" NA ...
 $ assoc_actor_2     : chr [1:55574] NA NA NA NA ...
 $ inter2            : num [1:55574] 0 7 1 0 7 0 1 0 1 7 ...
 $ interaction       : num [1:55574] 10 17 13 60 17 10 13 10 12 17 ...
 $ civilian_targeting: chr [1:55574] NA "Civilian targeting" NA NA ...
 $ iso               : num [1:55574] 104 104 104 104 104 104 104 104 104 104 ...
 $ region            : chr [1:55574] "Southeast Asia" "Southeast Asia" "Southeast Asia" "Southeast Asia" ...
 $ country           : chr [1:55574] "Myanmar" "Myanmar" "Myanmar" "Myanmar" ...
 $ admin1            : chr [1:55574] "Mon" "Rakhine" "Bago-West" "Sagaing" ...
 $ admin2            : chr [1:55574] "Mawlamyine" "Maungdaw" "Thayarwady" "Yinmarbin" ...
 $ admin3            : chr [1:55574] "Ye" "Maungdaw" "Nattalin" "Salingyi" ...
 $ location          : chr [1:55574] "Aing Shey" "Kaing Gyi (NaTaLa)" "Kyauk Pyoke" "Let Pa Taung" ...
 $ latitude          : num [1:55574] 15.3 20.7 18.6 22.1 18.6 ...
 $ longitude         : num [1:55574] 98 92.4 95.8 95.1 95.8 ...
 $ geo_precision     : num [1:55574] 1 2 2 2 1 1 1 2 2 1 ...
 $ source            : chr [1:55574] "Democratic Voice of Burma" "Development Media Group; Narinjara News" "Khit Thit Media; Myanmar Pressphoto Agency" "Myanmar Labour News" ...
 $ source_scale      : chr [1:55574] "National" "Subnational" "National" "National" ...
 $ notes             : chr [1:55574] "On 31 December 2023, in Aing Shey village (Ye township, Mawlamyine district, Mon state), following a clash betw"| __truncated__ "On 31 December 2023, in Kaing Gyi (Mro) village (coded as Kaing Gyi (NaTaLa)) (Maungdaw township, Maungdaw dist"| __truncated__ "On 31 December 2023, near Kyauk Pyoke village (Nattalin township, Thayarwady district, Bago-West region), the P"| __truncated__ "On 31 December 2023, in the Let Pa Taung area of Salingyi township (Yinmarbin district, Sagaing region), protes"| __truncated__ ...
 $ fatalities        : num [1:55574] 0 0 4 0 0 0 3 0 0 0 ...
 $ tags              : chr [1:55574] NA NA NA "crowd size=no report" ...
 $ timestamp         : num [1:55574] 1.7e+09 1.7e+09 1.7e+09 1.7e+09 1.7e+09 ...

Filtering Data Columns

The code chunk below creates a new dataset whilst removing those not being used in the study

Code
Myanmar_final <- Myanmar %>%
  select(-time_precision, -geo_precision, -source_scale, -timestamp, -tags)

Geo-data Wrangling

Due to the changes of some of the township names through the years, the following code chunk below corrects them such that they can be recognized.

Code
ACLED_MMR_1 <- Myanmar_final %>%
  mutate(admin1 = case_when(
    admin1 == "Bago-East" ~ "Bago (East)",
    admin1 == "Bago-West" ~ "Bago (West)",
    admin1 == "Shan-North" ~ "Shan (North)",
    admin1 == "Shan-South" ~ "Shan (South)",
    admin1 == "Shan-East" ~ "Shan (East)",
    TRUE ~ as.character(admin1)
  ))
Code
ACLED_MMR_1 <- Myanmar_final %>%
  mutate(admin2 = case_when(
    admin2 == "Yangon-East" ~ "Yangon (East)",
    admin2 == "Yangon-West" ~ "Yangon (West)",
    admin2 == "Yangon-North" ~ "Yangon (North)",
    admin2 == "Yangon-South" ~ "Yangon (South)",
    admin2 == "Mong Pawk (Wa SAD)" ~ "Tachileik",
    admin2 == "Nay Pyi Taw" ~ "Det Khi Na",
    admin2 == "Yangon" ~ "Yangon (West)",
    TRUE ~ as.character(admin2)
  ))

Exploratory Data Analysis

Code
Summary_Data <- ACLED_MMR_1 %>%
  group_by(year,admin1, event_type) %>%
  summarize(
    Total_incidents = n(),
    Total_Fatalities = sum(fatalities, na.rm=TRUE)
  )
Info on Code Chunk Above:

The code above groups the year, admin1, and event type together so that we can create a data table summarizing the total number of incidents for the year based on the township(admin1) and event type as well as a column totaling the amount of fatalities based on the same grouping selection

Summary of Incidents

Code
ggplot(Summary_Data, 
       aes(x = year, 
           y = Total_incidents, 
           color = event_type)) +
  geom_point() +
  facet_wrap(~event_type) + 
  theme_minimal() +
  labs(y = "Total Number of Incidents", x = "Years") +
  theme(
    panel.grid.major.y = element_line(color = "pink", linetype = 2),
    strip.background = element_rect(fill = "black"),
    strip.text = element_text(colour = "white"),
    legend.position = "none"
  )

Takeaway from Chart Above

Based on the chart above, it can be seen that there was an increase incidents for all incident types except for riot. The spikes in the increased incident can be attributed to the start of the Civil War within the country itself.

With the civil unrest, the highest incidents occurs with protests and strategic developments.

Next, we will look at the total amount of fatalities by event_type.

Code
ggplot(Summary_Data, 
       aes(x = year, y = Total_Fatalities, color = event_type)) +
  geom_point() +
  facet_wrap(~event_type) + 
  theme_minimal() +
  labs(y = "Total Number of Fatalities", x = "Years") +
  theme(
    panel.grid.major.y = element_line(color = "pink", linetype = 2),
    strip.background = element_rect(fill = "black"),
    strip.text = element_text(colour = "white"),
    legend.position = "none"
  )

Incidents and Fatalities by Region and Year

Code
gg1 <-  ggplot(Summary_Data,
              aes(x = admin1, y=Total_incidents,size = Total_Fatalities,  color = event_type)) +
  geom_point(aes(frame = year)) +
  theme_minimal() +
  labs(y = "Total Number of Incidents", x = "Regions") +
  theme(axis.text.x = element_blank())

ggplotly(gg1)
Takeaway from Chart Above

The chart above builds on the earlier summary of incidents and fatalities where it further splits the event types according to region. As you move the slider through the years, it seems that some regions have increased incidents as well as fatalities depending on the event type.

What is interesting to see is that at the start of 2021, there was an increased number of protests where in most regions but as time progressed the number dropped. This drop in number of protest eventually led to other types of events being increased such as battles which also has the higher amount of fatalities as compared to other event types.

Next, we would do some Confirmatory Data Analysis to see if what we see above is true.

Confirmatory Data Analysis

This next section would delve more into confirmatory data analysis where we would be testing for statistical significance based on a few null hypothesis that would be described according to the EDA portion in the earlier section. For the analysis and comparisons, we would mainly be using ggstatsplot package for analysis.

Launching ggstats package
pacman::p_load(ggstatsplot, corrplot)

Hypothesis 1

Null Hypothesis: Are there specific event types more correlated with number of fatalities?

In order to test the above hypothesis, there would be some data wrangling that needs to be done first.

Code
Incident_hypo1 <- ACLED_MMR_1 %>%
  group_by(event_type,year) %>%
  summarize(
    Total_incidents = n(),
    Total_Fatalities = sum(fatalities, na.rm=TRUE)
  )
Code
gg2 <- ggplot(Incident_hypo1,
              aes(x = year, y=Total_Fatalities)) +
  geom_boxplot() +
  stat_summary(geom = "point",       
               fun.y="mean",         
               colour ="red",        
               size=2)

ggplotly(gg2)
Code
ACLED_Filtered <- ACLED_MMR_1 %>%
  filter(year == c(2020,2021,2022,2023))



 ggstatsplot::grouped_ggbetweenstats(ACLED_Filtered, 
              x = year, 
              y = fatalities,
              grouping.var = event_type,
              type = "np",
              pairwise.display = "s",
              pairwise_comparisons = TRUE,
              output = "plot")

Additional Plots

Code
set.seed(123)

ggbetweenstats(ACLED_Filtered,
               x = year,
               y = fatalities)

Code
ggbetweenstats(Incident_hypo1,
               x= event_type,
               y= Total_incidents)

Code
ggbetweenstats(ACLED_Filtered,
               x= event_type,
               y= fatalities)

Splitting up datasets via event_type to study by regions

Code
Battles_Summary <- ACLED_MMR_1 %>%
  filter(event_type == "Battles")

Explosion_Summary <- ACLED_MMR_1 %>%
  filter(event_type == "Explosions/Remote violence")

Protests_Summary <- ACLED_MMR_1 %>%
  filter(event_type == "Protests")

StratD_Summary <- ACLED_MMR_1 %>%
  filter(event_type == "Strategic developments")

VioCiv_Summary <- ACLED_MMR_1 %>%
  filter(event_type == "Violence against civilians")
Code
set.seed(123)

Battles_Summary_Grouped <- Battles_Summary %>%
  group_by(admin1) %>%
  summarize(
    Total_Incidents = n(),
    Total_Fatalities = sum(fatalities, na.rm=TRUE),
    Mean_Fatalities = mean(fatalities)
  )


gg3 <- ggbarstats(ACLED_Filtered,
           x = event_type,
           y = admin1)

ggplotly(gg3)