DIY Conflict Model

November 17, 2026

Step 1: Get Data

peacesciencer package

library(peacesciencer)

conflict_df <- create_stateyears(system = 'gw') |>
  filter(year %in% c(1946:1999)) |>
  add_ucdp_acd(type=c("intrastate"), only_wars = FALSE) |>
  add_democracy() |>
  add_creg_fractionalization() |>
  add_sdp_gdp() |>
  add_rugged_terrain()

glimpse(conflict_df)
Rows: 7,624
Columns: 22
$ gwcode         <dbl> 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2…
$ gw_name        <chr> "United States of America", "United States of America",…
$ microstate     <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0…
$ year           <dbl> 1946, 1947, 1948, 1949, 1950, 1951, 1952, 1953, 1954, 1…
$ ucdpongoing    <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0…
$ ucdponset      <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0…
$ maxintensity   <dbl> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,…
$ conflict_ids   <chr> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,…
$ euds           <dbl> 0.9644538, 0.9644538, 0.9928312, 0.9810480, 1.0013730, …
$ aeuds          <dbl> 0.5677531, 0.5677531, 0.5961305, 0.5843473, 0.6046723, …
$ polity2        <dbl> 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9…
$ v2x_polyarchy  <dbl> 0.602, 0.611, 0.603, 0.580, 0.585, 0.612, 0.611, 0.606,…
$ ethfrac        <dbl> 0.2226323, 0.2248701, 0.2271561, 0.2294918, 0.2318781, …
$ ethpol         <dbl> 0.4152487, 0.4186156, 0.4220368, 0.4255134, 0.4290458, …
$ relfrac        <dbl> 0.4980802, 0.5009111, 0.5037278, 0.5065309, 0.5093204, …
$ relpol         <dbl> 0.7769888, 0.7770017, 0.7770303, 0.7770729, 0.7771274, …
$ wbgdp2011est   <dbl> 28.539, 28.519, 28.545, 28.534, 28.572, 28.635, 28.669,…
$ wbpopest       <dbl> 18.744, 18.756, 18.781, 18.804, 18.821, 18.832, 18.848,…
$ sdpest         <dbl> 28.478, 28.456, 28.483, 28.469, 28.510, 28.576, 28.611,…
$ wbgdppc2011est <dbl> 9.794, 9.762, 9.764, 9.730, 9.752, 9.803, 9.821, 9.857,…
$ rugged         <dbl> 1.073, 1.073, 1.073, 1.073, 1.073, 1.073, 1.073, 1.073,…
$ newlmtnest     <dbl> 3.214868, 3.214868, 3.214868, 3.214868, 3.214868, 3.214…

Your Turn!

  • Install/load the peacesciencer package
  • Visit the package website
  • Create a conflict dataset based on the Gleditsch-Ward system of state-years
  • Filter the dataset to include only years between 1946 and 1999
  • Add UCDP/PRIO Armed Conflict Dataset (ACD) data on intrastate wars
  • Add sets of variables and glimpse() the dataset after each set
    • Democracy variables
    • Fractionalization variables
    • GDP variables
    • Rugged terrain variables
  • Others?

Step 2: Approximate F&L

Replicate Fearon and Laitin (2003)


One way to do it:

conflict_model <- glm(ucdponset ~ ethfrac + relfrac + v2x_polyarchy + rugged +
                        wbgdppc2011est + wbpopest,
                  data = conflict_df,
                  family = "binomial")

summary(conflict_model)

Call:
glm(formula = ucdponset ~ ethfrac + relfrac + v2x_polyarchy + 
    rugged + wbgdppc2011est + wbpopest, family = "binomial", 
    data = conflict_df)

Coefficients:
               Estimate Std. Error z value Pr(>|z|)    
(Intercept)    -5.37951    1.40988  -3.816 0.000136 ***
ethfrac         0.70837    0.37170   1.906 0.056679 .  
relfrac        -0.28718    0.40943  -0.701 0.483047    
v2x_polyarchy  -0.66026    0.51379  -1.285 0.198764    
rugged          0.08355    0.07564   1.105 0.269329    
wbgdppc2011est -0.39099    0.11996  -3.259 0.001116 ** 
wbpopest        0.28465    0.06774   4.202 2.64e-05 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

(Dispersion parameter for binomial family taken to be 1)

    Null deviance: 1205.0  on 6128  degrees of freedom
Residual deviance: 1147.9  on 6122  degrees of freedom
  (1495 observations deleted due to missingness)
AIC: 1161.9

Number of Fisher Scoring iterations: 7

Your Turn!

  • Approximate the Fearon and Laitin (2003) model
  • Use the glm() function to run the model
  • Add measures of ethnicity, democracy, terrain, population and wealth
  • Try replacing the original measures with different ones of the same concept
    • What happens?
  • What else could you add?

Step 3: Visualize Your Model


So we can use ggplot to make a coefficient plot instead…


Two steps… First, we need a coeficient map:

coef_map <- c("ethfrac" = "Ethnic Frac",  # map coefficients
        "relfrac" = "Religions Frac",     #(change names and order)
        "v2x_polyarchy" = "Polyarchy",
        "rugged" = "Terrain",
        "wbgdppc2011est" = "Per capita GDP",
        "wbpopest" = "Population",
        "(Intercept)" = "Intercept")


Then, we can use modelplot to visualize the model:

library(modelsummary)
library(ggplot2)

modelplot(conflict_model, 
          coef_map = rev(coef_map), # rev() reverses list order
          coef_omit = "Intercept", 
          color = "blue") + # use plus to add customizations like any ggplot object
  geom_vline(xintercept = 0, color = "red", linetype = "dashed", linewidth = .75) + # red 0 line
  labs(
    title = "Figure 1: Predictors of Conflict Onset",
    caption = "See appendix for data sources."
  ) 

Your Turn!


  • Create a coefficient map for your model
  • Use modelplot to visualize your model
  • Don’t forget to add the title and caption

Step 4: Exponentiate the Coefficients

Exponentiate the Coefficients

Exponentiate the Coefficients

modelplot(conflict_model, 
          exponentiate = TRUE, # exponentiate coefficients
          coef_map = rev(coef_map), # rev() reverses list order
          coef_omit = "Intercept", 
          color = "blue") + # use plus to add customizations like any ggplot object
  geom_vline(xintercept = 1, color = "red", linetype = "dashed", linewidth = .75) + # red 0 line
  labs(
    title = "Figure 1: Predictors of Conflict Onset",
    caption = "See appendix for data sources."
  ) 

Your Turn!

  • Exponentiate the coefficients in your model
  • Do this by setting exponentiate = TRUE in modelplot
  • Interpret the results

Step 5: Model Predictions

Using marginaleffects

# load the marginaleffects library
library(marginaleffects)

# select some countries for a given year
selected_countries <- conflict_df |>
  filter(
    gw_name %in% c("United States of America", "Venezuela", "Rwanda"),
    year == 1999)

# calculate margins for the subset
marg_effects <- predictions(conflict_model, newdata = selected_countries)

# tidy the results
tidy(marg_effects) |>
  select(estimate, p.value, conf.low, conf.high, gw_name)

Using marginaleffects


# A tibble: 3 × 5
  estimate  p.value conf.low conf.high gw_name                 
     <dbl>    <dbl>    <dbl>     <dbl> <chr>                   
1   0.0115 1.65e-28  0.00526    0.0249 United States of America
2   0.0136 5.77e-80  0.00878    0.0210 Venezuela               
3   0.0331 3.00e-38  0.0201     0.0540 Rwanda                  

Your Turn!


  • Use marginaleffects to calculate the predicted probabilities for a few countries
  • Interpret the results