Debian Codegraph @

R/btergm.R

raw
1 #' @templateVar class btergm
2 #' @template title_desc_tidy
3 #'
4 #' @description This method tidies the coefficients of a bootstrapped
5 #' temporal exponential random graph model estimated with the \pkg{xergm}.
6 #' It simply returns the coefficients and their confidence intervals.
7 #'
8 #' @param x A [btergm::btergm()] object.
9 #' @param conf.level Confidence level for confidence intervals. Defaults to
10 #' 0.95.
11 #' @template param_exponentiate
12 #' @template param_unused_dots
13 #'
14 #' @evalRd return_tidy("term", "estimate", "conf.low", "conf.high")
15 #'
16 #' @export
17 #' @aliases btergm_tidiers
18 #' @seealso [tidy()], [btergm::btergm()]
19 #' @examplesIf rlang::is_installed(c("btergm", "network"))
20 #'
21 #' library(btergm)
22 #' library(network)
23 #'
24 #' set.seed(5)
25 #'
26 #' # create 10 random networks with 10 actors
27 #' networks <- list()
28 #' for (i in 1:10) {
29 #' mat <- matrix(rbinom(100, 1, .25), nrow = 10, ncol = 10)
30 #' diag(mat) <- 0
31 #' nw <- network(mat)
32 #' networks[[i]] <- nw
33 #' }
34 #'
35 #' # create 10 matrices as covariates
36 #' covariates <- list()
37 #' for (i in 1:10) {
38 #' mat <- matrix(rnorm(100), nrow = 10, ncol = 10)
39 #' covariates[[i]] <- mat
40 #' }
41 #'
42 #' # fit the model
43 #' mod <- btergm(networks ~ edges + istar(2) + edgecov(covariates), R = 100)
44 #'
45 #' # summarize model fit with tidiers
46 #' tidy(mod)
47 #'
48 tidy.btergm <- function(x, conf.level = .95, exponentiate = FALSE, ...) {
49 co <- btergm::confint(x, level = conf.level)[, -2]
50
51 ret <- as_tidy_tibble(
52 co,
53 new_names = c("estimate", "conf.low", "conf.high")[1:ncol(co)]
54 )
55
56 if (exponentiate) {
57 ret <- exponentiate(ret)
58 }
59
60 as_tibble(ret)
61 }