How to use ggcoefstats to present results of multiple BTERGMs in R?

Viewed 103

I am using the ggcoefstats function in ggstatsplot package in R to present the results of temporal exponential random graph model by bootstrapped pseudolikelihood (BTERGM). Here is the example code I get from https://indrajeetpatil.github.io/ggstatsplot/articles/web_only/ggcoefstats.html:

# setup
library(ggstatsplot)
library(network)
library(btergm)
set.seed(123)

# create 10 random networks with 10 actors
networks <- list()
for (i in 1:10) {
  mat <- matrix(rbinom(100, 1, .25), nrow = 10, ncol = 10)
  diag(mat) <- 0 # loops are excluded
  nw <- network(mat) # create network object
  networks[[i]] <- nw # add network to the list
}

# create 10 matrices as covariate
covariates <- list()
for (i in 1:10) {
  mat <- matrix(rnorm(100), nrow = 10, ncol = 10)
  covariates[[i]] <- mat # add matrix to the list
}

# model
fit_btergm <-
  btergm::btergm(
    formula = networks ~ edges + istar(2) + edgecov(covariates),
    parallel = "multicore",
    ncpus = 4,
    R = 100,
    verbose = FALSE
  )

# plot
ggcoefstats(
  x = fit_btergm,
  title = "Terms used in Exponential Family Random Graph Models",
  subtitle = "by bootstrapped pseudolikelihood or MCMC MLE"
)

However, I have multiple BTERGMs and I would like to present their results in one graph:

fit_btergm1 <-
  btergm::btergm(
    formula = networks ~ edges + istar(2),
    parallel = "multicore",
    ncpus = 4,
    R = 100,
    verbose = FALSE
  )

fit_btergm2 <-
  btergm::btergm(
    formula = networks ~ edges + istar(2) + edgecov(covariates),
    parallel = "multicore",
    ncpus = 4,
    R = 100,
    verbose = FALSE
  )

I have tried the following but it does not work:

# plot
ggcoefstats(
  x = list(fit_btergm1, fit_btergm2),
  title = "Terms used in Exponential Family Random Graph Models",
  subtitle = "by bootstrapped pseudolikelihood or MCMC MLE"
)

Any ideas on how to do this? Thank you so much :)

1 Answers

ggcoefstats doesn't allow a list of models as input. So you have two options if you want to show estimates from two separate models:

  1. Plot them in separate plots using ggcoefstats
  2. Use a different package to plot them in the same plot
# setup
library(ggstatsplot)
library(network)
set.seed(123)

# create 10 random networks with 10 actors
networks <- list()
for (i in 1:10) {
  mat <- matrix(rbinom(100, 1, .25), nrow = 10, ncol = 10)
  diag(mat) <- 0 # loops are excluded
  nw <- network(mat) # create network object
  networks[[i]] <- nw # add network to the list
}

# create 10 matrices as covariate
covariates <- list()
for (i in 1:10) {
  mat <- matrix(rnorm(100), nrow = 10, ncol = 10)
  covariates[[i]] <- mat # add matrix to the list
}

# models
fit_btergm1 <-
  btergm::btergm(
    formula = networks ~ edges + istar(2),
    parallel = "multicore",
    ncpus = 4,
    R = 100,
    verbose = FALSE
  )

fit_btergm2 <-
  btergm::btergm(
    formula = networks ~ edges + istar(2) + edgecov(covariates),
    parallel = "multicore",
    ncpus = 4,
    R = 100,
    verbose = FALSE
  )

library(patchwork)

wrap_plots(ggcoefstats(fit_btergm1), ggcoefstats(fit_btergm2))

library(modelsummary)

modelplot(list(fit_btergm1, fit_btergm2))

Created on 2021-04-20 by the reprex package (v2.0.0)

Related