## ----include = FALSE---------------------------------------------------------- knitr::opts_chunk$set(collapse = TRUE, comment = "#>", fig.width = 7, fig.height = 4) ## ----data--------------------------------------------------------------------- library(slxr) data(defense_burden_panel) panel <- defense_burden_panel dim(panel$data) range(panel$data$year) length(panel$W_contig) # one W per year ## ----wrap--------------------------------------------------------------------- wrap_list <- function(W_list) { lapply(W_list, \(m) slx_weights(style = "custom", matrix = m, row_standardize = FALSE)) } Wc <- wrap_list(panel$W_contig) # year-varying contiguity Wa <- wrap_list(panel$W_alliance) # year-varying alliances Wd <- wrap_list(panel$W_defense) # year-varying defense pacts ## ----fit---------------------------------------------------------------------- fit <- slx( ch_milex ~ milex_tm1 + log_pop_tm1 + civilwar_tm1 + total_wars_tm1 + alliance_us + ch_milex_us + ch_milex_ussr, data = panel$data, spatial = list( civilwar_tm1 = Wc, total_wars_tm1 = list(contig = Wc, alliance = Wa), milex_tm1 = list(contig = Wc, defense = Wd) ), id = "ccode", time = "year" ) summary(fit) ## ----effects------------------------------------------------------------------ slx_effects(fit) ## ----plot, fig.height = 5----------------------------------------------------- library(ggplot2) slx_plot_effects(fit, types = c("indirect", "total"))