Combine ACLED data to cover South Sudan from 2011 - 2015.

setwd("C:/Users/Dan/Dropbox/work/MSI/South Sudan/ACLED/real time data/")

library(openxlsx)
library(dplyr)
## 
## Attaching package: 'dplyr'
## 
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## 
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
library(DescTools)
## Loading required package: manipulate
library(lubridate)
library(ggplot2)
library(TTR)
library(forecast)
## Loading required package: zoo
## 
## Attaching package: 'zoo'
## 
## The following objects are masked from 'package:base':
## 
##     as.Date, as.Date.numeric
## 
## Loading required package: timeDate
## This is forecast 6.1 
## 
## 
## Attaching package: 'forecast'
## 
## The following object is masked from 'package:DescTools':
## 
##     BoxCox
library(fUnitRoots)
## Loading required package: urca
## Loading required package: timeSeries
## 
## Attaching package: 'timeSeries'
## 
## The following object is masked from 'package:zoo':
## 
##     time<-
## 
## Loading required package: fBasics
## 
## 
## Rmetrics Package fBasics
## Analysing Markets and calculating Basic Statistics
## Copyright (C) 2005-2014 Rmetrics Association Zurich
## Educational Software for Financial Engineering and Computational Science
## Rmetrics is free software and comes with ABSOLUTELY NO WARRANTY.
## https://www.rmetrics.org --- Mail to: info@rmetrics.org
## 
## Attaching package: 'fBasics'
## 
## The following object is masked from 'package:TTR':
## 
##     volatility
## 
## 
## Attaching package: 'fUnitRoots'
## 
## The following objects are masked from 'package:urca':
## 
##     punitroot, qunitroot, unitrootTable
dat <- read.csv("ACLED All Africa File_20150101 to 20150801.csv")

dat <- dat[dat$COUNTRY=="South Sudan",]
datNames <- data.frame(names(dat))

dat14 <- read.csv("South Sudan ACLED 2011-2014.csv", header=T)
dat14Names <- data.frame(names(dat14))

dat14 <- select(dat14, GWNO:EVENT_ID_CNTY, EVENT_DATE:FATALITIES)

names(dat14) <- names(dat)

acled <- rbind(dat14, dat)

acled$EVENT_DATE <- strptime(acled$EVENT_DATE, format="%d/%m/%Y")

Use the date of the event to create new variables partitioning events by week, month, and quarter.

acled$week <- week(acled$EVENT_DATE)
acled$month <- month(acled$EVENT_DATE)
acled$weekyr <- paste(acled$YEAR, acled$week, sep="-")
acled$monthyr <- paste(acled$month, acled$YEAR, sep="-")
acled$yrmonth <- paste(acled$YEAR, acled$month, "01", sep="-")
acled$yrmonth2 <- strptime(acled$yrmonth, format="%Y-%m-%d")
acled$quarter <- quarter(acled$EVENT_DATE, T)

Code the different event types into categories we are interested in. For the moment, those categories are actions between militant actors and events that bring violence upon non-combatants by any militant actor.

acled$EVENT_TYPE <- as.factor(acled$EVENT_TYPE)

table(acled$EVENT_TYPE)
## 
##        Battle-Government regains territory 
##                                         42 
##              Battle-No change of territory 
##                                        901 
## Battle-Non-state actor overtakes territory 
##                                         58 
##           Headquarters or base established 
##                                          3 
##   Non-violent activity by a conflict actor 
##                                        191 
##          Non-violent transfer of territory 
##                                         14 
##                            Remote violence 
##                                        128 
##                             Riots/Protests 
##                                        138 
##                 Violence against civilians 
##                                        659 
##                            Remote Violence 
##                                          0
acled$Event <- ifelse(acled$EVENT_TYPE=="Battle-Government regains territory","Militant action", ifelse(acled$EVENT_TYPE=="Battle-Non-state actor overtakes territory","Militant action",ifelse(acled$EVENT_TYPE=="Remote violence","Militant action", ifelse(acled$EVENT_TYPE=="Violence against civilians","Militant action",ifelse(acled$EVENT_TYPE=="Battle-No change of territory","Militant action", "Non-militant action")))))

acled$Event2 <- ifelse(acled$EVENT_TYPE=="Battle-Government regains territory" | acled$EVENT_TYPE=="Battle-Non-state actor overtakes territory" | (acled$EVENT_TYPE=="Remote violence" & acled$ACTOR2!="Civilians (South Sudan)") | acled$EVENT_TYPE=="Battle-No change of territory","Militant action", ifelse(acled$EVENT_TYPE=="Violence against civilians" | (acled$EVENT_TYPE=="Remote violence" & acled$ACTOR2=="Civilians (South Sudan)"),"Violence against civilians","No violence"))

table(acled$Event2)
## 
##            Militant action                No violence 
##                       1082                        346 
## Violence against civilians 
##                        706
table(acled$Event)
## 
##     Militant action Non-militant action 
##                1788                 346
table(acled$month)
## 
##   1   2   3   4   5   6   7   8   9  10  11  12 
## 285 204 207 235 247 177 174 123 100  90  89 203
acled$Event <- as.factor(acled$Event)

Aggregate event location data to region, in case we’d ever like to disaggregate the time series.

acled$Region <- ifelse(acled$ADM_LEVEL_1=="Lakes" | acled$ADM_LEVEL_1=="Northern Bahr el Ghazal" | acled$ADM_LEVEL_1=="Western Bahr el Ghazal" | acled$ADM_LEVEL_1=="Bahr el Ghazal" | acled$ADM_LEVEL_1=="Warrap", "Bahr el Ghazal", ifelse(acled$ADM_LEVEL_1=="Central Equatoria" | acled$ADM_LEVEL_1=="Western Equatoria" | acled$ADM_LEVEL_1=="West Equatoria" | acled$ADM_LEVEL_1=="Eastern Equatoria" | acled$ADM_LEVEL_1=="Equatoria","Equatoria", ifelse(acled$ADM_LEVEL_1=="Jonglei" | acled$ADM_LEVEL_1=="Jungoli" | acled$ADM_LEVEL_1=="Unity" | acled$ADM_LEVEL_1=="Upper Nile","Greater Upper Nile", "No region")))

table(acled$Region)
## 
##     Bahr el Ghazal          Equatoria Greater Upper Nile 
##                502                378               1254

Pare down the dataset to contain just the variables we need to plot a time series.

acled <- select(acled,Date=EVENT_DATE, Year=YEAR, Event_Type=EVENT_TYPE, Fatalities=FATALITIES, week:Region, State=ADM_LEVEL_1, County=ADM_LEVEL_2, Payam=ADM_LEVEL_3, Location=LOCATION, Actor1=ACTOR1, Ally_Actor1=ALLY_ACTOR_1, Actor2=ACTOR2, Ally_Actor2=ALLY_ACTOR_2,lat=LATITUDE, lon=LONGITUDE, Source=SOURCE, Notes=NOTES)

str(acled)
## 'data.frame':    2134 obs. of  26 variables:
##  $ Date       : POSIXlt, format: "2011-07-23" "2011-08-03" ...
##  $ Year       : int  2011 2011 2011 2011 2011 2011 2011 2011 2011 2011 ...
##  $ Event_Type : Factor w/ 10 levels "Battle-Government regains territory",..: 2 5 5 9 2 9 9 2 2 9 ...
##  $ Fatalities : int  1 0 0 67 67 67 66 24 24 66 ...
##  $ week       : num  30 31 31 33 33 34 34 34 34 34 ...
##  $ month      : num  7 8 8 8 8 8 8 8 8 8 ...
##  $ weekyr     : chr  "2011-30" "2011-31" "2011-31" "2011-33" ...
##  $ monthyr    : chr  "7-2011" "8-2011" "8-2011" "8-2011" ...
##  $ yrmonth    : chr  "2011-7-01" "2011-8-01" "2011-8-01" "2011-8-01" ...
##  $ yrmonth2   : POSIXlt, format: "2011-07-01" "2011-08-01" ...
##  $ quarter    : num  2011 2011 2011 2011 2011 ...
##  $ Event      : Factor w/ 2 levels "Militant action",..: 1 2 2 1 1 1 1 1 1 1 ...
##  $ Event2     : chr  "Militant action" "No violence" "No violence" "Violence against civilians" ...
##  $ Region     : chr  "Greater Upper Nile" "Equatoria" "Equatoria" "Greater Upper Nile" ...
##  $ State      : Factor w/ 487 levels "Central Equatoria",..: 3 1 1 3 3 5 7 5 7 3 ...
##  $ County     : Factor w/ 1562 levels "Abiemnhom","Abyei region",..: 16 24 24 68 68 8 37 8 37 68 ...
##  $ Payam      : chr  NA NA NA NA ...
##  $ Location   : Factor w/ 3330 levels "Abelek","Abiemnom",..: 123 98 98 222 222 22 104 22 104 222 ...
##  $ Actor1     : Factor w/ 733 levels "Acholi Ethnic Militia (South Sudan)",..: 102 76 93 65 65 57 57 57 57 65 ...
##  $ Ally_Actor1: Factor w/ 653 levels "","Adol Clan Dinka Ethnic Group (South Sudan)",..: 1 1 1 1 1 1 1 1 1 1 ...
##  $ Actor2     : Factor w/ 614 levels "","Adol Clan Dinka Ethnic Militia (South Sudan)",..: 50 1 1 17 50 17 17 50 50 17 ...
##  $ Ally_Actor2: Factor w/ 512 levels "","Alel Thony Communal Group (South Sudan)",..: 1 1 1 1 1 1 1 1 1 1 ...
##  $ lat        : num  7.63 4.85 4.85 8.03 8.03 ...
##  $ lon        : num  31.4 31.6 31.6 32 32 ...
##  $ Source     : Factor w/ 1274 levels "","Africa News",..: 219 166 4 250 250 259 259 259 259 250 ...
##  $ Notes      : Factor w/ 10101 levels " A major South Sudanese opposition party, the Sudan Peoples Liberation Movement for Democratic Change (SPLM-DC) protested again"| __truncated__,..: 155 167 1308 327 328 28 28 28 28 322 ...
head(acled)
##         Date Year                               Event_Type Fatalities week
## 1 2011-07-23 2011            Battle-No change of territory          1   30
## 2 2011-08-03 2011 Non-violent activity by a conflict actor          0   31
## 3 2011-08-04 2011 Non-violent activity by a conflict actor          0   31
## 4 2011-08-18 2011               Violence against civilians         67   33
## 5 2011-08-18 2011            Battle-No change of territory         67   33
## 6 2011-08-19 2011               Violence against civilians         67   34
##   month  weekyr monthyr   yrmonth   yrmonth2 quarter               Event
## 1     7 2011-30  7-2011 2011-7-01 2011-07-01  2011.3     Militant action
## 2     8 2011-31  8-2011 2011-8-01 2011-08-01  2011.3 Non-militant action
## 3     8 2011-31  8-2011 2011-8-01 2011-08-01  2011.3 Non-militant action
## 4     8 2011-33  8-2011 2011-8-01 2011-08-01  2011.3     Militant action
## 5     8 2011-33  8-2011 2011-8-01 2011-08-01  2011.3     Militant action
## 6     8 2011-34  8-2011 2011-8-01 2011-08-01  2011.3     Militant action
##                       Event2             Region                   State
## 1            Militant action Greater Upper Nile                 Jonglei
## 2                No violence          Equatoria       Central Equatoria
## 3                No violence          Equatoria       Central Equatoria
## 4 Violence against civilians Greater Upper Nile                 Jonglei
## 5            Militant action Greater Upper Nile                 Jonglei
## 6 Violence against civilians     Bahr el Ghazal Northern Bahr el Ghazal
##       County Payam       Location
## 1        Duk  <NA>          Koich
## 2       Juba  <NA>           Juba
## 3       Juba  <NA>           Juba
## 4       Uror  <NA> Pieri District
## 5       Uror  <NA> Pieri District
## 6 Aweil West  <NA>           Alan
##                                         Actor1 Ally_Actor1
## 1             Unidentified Armed Group (Sudan)            
## 2                      Peter Gadet Rebel Group            
## 3 SSLM/A: South Sudan Liberation Movement/Army            
## 4           Murle Ethnic Militia (South Sudan)            
## 5           Murle Ethnic Militia (South Sudan)            
## 6             Military Forces of Sudan (1989-)            
##                                   Actor2 Ally_Actor2     lat      lon
## 1 Military Forces of South Sudan (2011-)             7.63333 31.43333
## 2                                                    4.85165 31.58247
## 3                                                    4.85165 31.58247
## 4                      Civilians (Sudan)             8.03333 32.03333
## 5 Military Forces of South Sudan (2011-)             8.03333 32.03333
## 6                      Civilians (Sudan)             9.06089 27.10903
##                  Source
## 1         Sudan Tribune
## 2 Platts Commodity News
## 3  Agence France Presse
## 4    The Canadian Press
## 5    The Canadian Press
## 6     The Katmandu Post
##                                                                                                                                                                                                                                                                                                                                                                                                     Notes
## 1                                                                                                                                                       A rebel leader in South Sudans Unity State was shot dead in Koich, only three days after he signed a peace deal with South Sudan army, the Sudan Peoples Liberation Army (SPLA). It was later learned there was conspiring among his lieutenants.
## 2                                                                                                                                                                                                                                   A South Sudan rebel group led by renegade general Peter Gadet has agreed to an unconditional ceasefire and is committed to talks on merging its troops with the army.
## 3                                                                                                                                                                                                                                      The SSLM rejected a peace deal with the Sudanese government believing their former leader, Peter Gadet, had been corrupted by members of the Sudanese government. 
## 4                                                                                               Cattle raiders of the Murle ethnic group crossed the border from Sudan, raided and looted five unincorporated locations in Jonglei state including the villages of Matot, Pulchuol, Guancot, Rumaker, Dorganwel, and Tongyang. 600 deaths spread over these days unless specifically reported in an event
## 5                                                                                Cattle raiders of the Murle ethnic group crossed the border from Sudan, raided and looted five unincorporated locations in Jonglei state including the villages of Matot, Pulchuol, Guancot, Rumaker, Dorganwel, and Tongyang. This is believed to be revenge against the Lou Nuer tribe for earlier raids against them.
## 6 15 South Sudanese fighters are killed, 31 injured in clashes with border-crossing Sudanese forces, who attacked several towns, including an unnamed area on day two, and returned across the border the following day. 57 members of the raiding force were killed in the incident. Many believe this was an effort by the north to intimidate civilians expose the Souths new government as a failure.

Aggregate raw count data by month.

acledMonth <- acled %>%
     select(-Date, -yrmonth2) %>%
     group_by(yrmonth) %>%
     summarise(Militant_actions=sum(Event2=="Militant action"), Civilian_violence=sum(Event2=="Violence against civilians"), Fatalities=sum(Fatalities))

acledMonth$yrmonth2 <- strptime(acledMonth$yrmonth, format="%Y-%m-%d")
acledMonth <- acledMonth[order(acledMonth$yrmonth2),]
acledMonth$month <- 1:50

str(acledMonth)
## Classes 'tbl_df' and 'data.frame':   50 obs. of  6 variables:
##  $ yrmonth          : chr  "2011-7-01" "2011-8-01" "2011-9-01" "2011-10-01" ...
##  $ Militant_actions : int  1 10 1 2 3 5 6 4 7 16 ...
##  $ Civilian_violence: int  0 6 2 1 1 6 3 0 4 5 ...
##  $ Fatalities       : int  1 734 2 95 25 244 177 237 7 43 ...
##  $ yrmonth2         : POSIXlt, format: "2011-07-01" "2011-08-01" ...
##  $ month            : int  1 2 3 4 5 6 7 8 9 10 ...
head(acledMonth)
## Source: local data frame [6 x 6]
## Warning in `[<-.data.frame`(`*tmp*`, is_list, value =
## structure(list(yrmonth2 = structure(c("<dbl[6]>", : replacement element 1
## has 11 rows to replace 6 rows
##      yrmonth Militant_actions Civilian_violence Fatalities yrmonth2 month
## 1  2011-7-01                1                 0          1 <dbl[6]>     1
## 2  2011-8-01               10                 6        734 <int[6]>     2
## 3  2011-9-01                1                 2          2 <int[6]>     3
## 4 2011-10-01                2                 1         95 <int[6]>     4
## 5 2011-11-01                3                 1         25 <int[6]>     5
## 6 2011-12-01                5                 6        244 <int[6]>     6

Plot militant and civilian violence together.

ggplot(acledMonth, aes(x=month)) + 
     geom_line(aes(y=Militant_actions, color="Militant actions"), lwd=1) + 
     geom_line(aes(y=Civilian_violence, color="Civilian violence"), lwd=1) + 
     scale_x_discrete(breaks=c(7,19,31,43), labels=c("Jan 2012","Jan 2013", "Jan 2014", "Jan 2015")) + 
     scale_colour_manual("", 
                         values=c("Militant actions"="firebrick3","Civilian violence"="blue")) +
     theme(axis.title=element_text(size=16), 
           plot.title=element_text(size=22, face="bold"),
           axis.text=element_text(size=16),
           legend.justification=c(0,1), 
           legend.text=element_text(size=14), 
           legend.title=element_text(size=14),
           legend.position=c(0,1)) + 
     guides(fill=guide_legend(reverse=T)) + 
     labs(fill="Type of violence") + 
     ylab("Events") + ggtitle("South Sudan violence by month\nJuly 2011 - July 2015")

Decompose time series into random, seasonal, and trend components.

month <- ts(acledMonth$Militant_actions, start=c(2011, 7), end=c(2015, 7),frequency=12)
month
##      Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec
## 2011                           1  10   1   2   3   5
## 2012   6   4   7  16   8   9   2   3   6   3   2   9
## 2013   8  10  14   7  14   4  24   2   3   3   9  51
## 2014 112  50  62  91  40  30  40  33  31  27  26  25
## 2015  30  31  41  38  62  44  22
dec <- decompose(month)
dec
## $x
##      Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec
## 2011                           1  10   1   2   3   5
## 2012   6   4   7  16   8   9   2   3   6   3   2   9
## 2013   8  10  14   7  14   4  24   2   3   3   9  51
## 2014 112  50  62  91  40  30  40  33  31  27  26  25
## 2015  30  31  41  38  62  44  22                    
## 
## $seasonal
##              Jan         Feb         Mar         Apr         May
## 2011                                                            
## 2012  17.5419560   3.2259838   8.8232060  18.3926505   0.3926505
## 2013  17.5419560   3.2259838   8.8232060  18.3926505   0.3926505
## 2014  17.5419560   3.2259838   8.8232060  18.3926505   0.3926505
## 2015  17.5419560   3.2259838   8.8232060  18.3926505   0.3926505
##              Jun         Jul         Aug         Sep         Oct
## 2011               0.5176505  -9.5240162  -9.7045718 -12.8156829
## 2012  -6.5379051   0.5176505  -9.5240162  -9.7045718 -12.8156829
## 2013  -6.5379051   0.5176505  -9.5240162  -9.7045718 -12.8156829
## 2014  -6.5379051   0.5176505  -9.5240162  -9.7045718 -12.8156829
## 2015  -6.5379051   0.5176505                                    
##              Nov         Dec
## 2011 -12.5379051   2.2259838
## 2012 -12.5379051   2.2259838
## 2013 -12.5379051   2.2259838
## 2014 -12.5379051   2.2259838
## 2015                        
## 
## $trend
##            Jan       Feb       Mar       Apr       May       Jun       Jul
## 2011                                                                    NA
## 2012  6.041667  5.791667  5.708333  5.958333  5.958333  6.083333  6.333333
## 2013  7.750000  8.625000  8.458333  8.333333  8.625000 10.666667 16.750000
## 2014 40.416667 42.375000 44.833333 47.000000 48.708333 48.333333 43.833333
## 2015 34.916667        NA        NA        NA        NA        NA        NA
##            Aug       Sep       Oct       Nov       Dec
## 2011        NA        NA        NA        NA        NA
## 2012  6.666667  7.208333  7.125000  7.000000  7.041667
## 2013 22.750000 26.416667 31.916667 36.500000 38.666667
## 2014 39.625000 37.958333 34.875000 33.583333 35.083333
## 2015                                                  
## 
## $random
##              Jan         Feb         Mar         Apr         May
## 2011                                                            
## 2012 -17.5836227  -5.0176505  -7.5315394  -8.3509838   1.6490162
## 2013 -17.2919560  -1.8509838  -3.2815394 -19.7259838   4.9823495
## 2014  54.0413773   4.3990162   8.3434606  25.6073495  -9.1009838
## 2015 -22.4586227          NA          NA          NA          NA
##              Jun         Jul         Aug         Sep         Oct
## 2011                      NA          NA          NA          NA
## 2012   9.4545718  -4.8509838   5.8573495   8.4962384   8.6906829
## 2013  -0.1287616   6.7323495 -11.2259838 -13.7120949 -16.1009838
## 2014 -11.7954282  -4.3509838   2.8990162   2.7462384   4.9406829
## 2015          NA          NA                                    
##              Nov         Dec
## 2011          NA          NA
## 2012   7.5379051  -0.2676505
## 2013 -14.9620949  10.1073495
## 2014   4.9545718 -12.3093171
## 2015                        
## 
## $figure
##  [1]   0.5176505  -9.5240162  -9.7045718 -12.8156829 -12.5379051
##  [6]   2.2259838  17.5419560   3.2259838   8.8232060  18.3926505
## [11]   0.3926505  -6.5379051
## 
## $type
## [1] "additive"
## 
## attr(,"class")
## [1] "decomposed.ts"
plot(dec)

monthTrend <- HoltWinters(month) monthTrend plot(monthTrend) monthForecast <- forecast.HoltWinters(monthTrend, h=3) monthForecast plot(monthForecast)