How to Interpret and Create
March 24, 2026
Download the data using the peacesciencer package if you haven’t already…
Example, including multiple predictors associated with conflict:
conflict_model <- logistic_reg() |>
set_engine("glm") |>
fit(factor(ucdponset) ~ ethfrac + relfrac + v2x_polyarchy +
rugged + wbgdppc2011est + wbpopest,
data= conflict_df,
family = "binomial")
tidy(conflict_model)# A tibble: 7 × 5
term estimate std.error statistic p.value
<chr> <dbl> <dbl> <dbl> <dbl>
1 (Intercept) -5.38 1.41 -3.81 0.000138
2 ethfrac 0.709 0.372 1.91 0.0566
3 relfrac -0.288 0.409 -0.702 0.482
4 v2x_polyarchy -0.652 0.513 -1.27 0.204
5 rugged 0.0836 0.0756 1.11 0.269
6 wbgdppc2011est -0.392 0.120 -3.26 0.00110
7 wbpopest 0.285 0.0677 4.20 0.0000263
# load the
library(marginaleffects)
# seledct some countries for a given year
selected_countries <- conflict_df |>
filter(
gw_name %in% c("United States of America", "Venezuela", "Rwanda"),
year == 1999)
# extract the model
conflict_fit <- conflict_model$fit
# calculate margins for the subset
marg_effects <- predictions(conflict_fit, newdata = selected_countries)
# tidy the results
tidy(marg_effects) |>
select(estimate, p.value, conf.low, conf.high, gw_name)# A tibble: 3 × 5
estimate p.value conf.low conf.high gw_name
<dbl> <dbl> <dbl> <dbl> <chr>
1 0.0115 1.63e-28 0.00527 0.0250 United States of America
2 0.0136 1.88e-79 0.00876 0.0211 Venezuela
3 0.0331 3.17e-38 0.0201 0.0541 Rwanda
modelsummarymodelsummary packageethnicity <- glm(ucdponset ~ ethfrac + relfrac + wbgdppc2011est + wbpopest, # store each model in an object
data = conflict_df,
family = "binomial")
democracy <- glm(ucdponset ~ v2x_polyarchy + wbgdppc2011est + wbpopest,
data = conflict_df,
family = "binomial")
terrain <- glm(ucdponset ~ rugged + wbgdppc2011est + wbpopest ,
data = conflict_df,
family = "binomial")
full_model <- glm(ucdponset ~ ethfrac + relfrac + v2x_polyarchy + rugged +
wbgdppc2011est + wbpopest,
data = conflict_df,
family = "binomial")models <- list("Ethnicity" = ethnicity, # store list of models in an object
"Democracy" = democracy,
"Terrain" = terrain,
"Full Model" = full_model)
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")
caption = "Table 1: Predictors of Conflict Onset" # store caption
reference = "See appendix for data sources." # store reference notes| Ethnicity | Democracy | Terrain | Full Model | |
|---|---|---|---|---|
| + p < 0.1, * p < 0.05, ** p < 0.01, *** p < 0.001 | ||||
| See appendix for data sources. | ||||
| Ethnic Frac | 0.733* | 0.709+ | ||
| (0.365) | (0.372) | |||
| Religions Frac | -0.429 | -0.288 | ||
| (0.409) | (0.409) | |||
| Polyarchy | -0.801* | -0.652 | ||
| (0.390) | (0.513) | |||
| Terrain | 0.035 | 0.084 | ||
| (0.075) | (0.076) | |||
| Per capita GDP | -0.485*** | -0.275*** | -0.553*** | -0.392** |
| (0.104) | (0.059) | (0.092) | (0.120) | |
| Population | 0.278*** | 0.300*** | 0.296*** | 0.285*** |
| (0.067) | (0.051) | (0.050) | (0.068) | |
| Intercept | -4.571*** | -6.184*** | -4.166*** | -5.376*** |
| (1.323) | (0.967) | (1.140) | (1.410) | |
| Num.Obs. | 6364 | 6955 | 6840 | 6129 |
modelsummaryThis don’t look too good…
| (1) | |
|---|---|
| + p < 0.1, * p < 0.05, ** p < 0.01, *** p < 0.001 | |
| See appendix for data sources. | |
| Ethnic Frac | 0.709+ |
| (0.372) | |
| Religions Frac | -0.288 |
| (0.409) | |
| Polyarchy | -0.652 |
| (0.513) | |
| Terrain | 0.084 |
| (0.076) | |
| Per capita GDP | -0.392** |
| (0.120) | |
| Population | 0.285*** |
| (0.068) | |
| Intercept | -5.376*** |
| (1.410) | |
| Num.Obs. | 6129 |
So we can use ggplot to make a coefficient plot instead…
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."
) modelplot to create a coefficient plot of it