Determine the gof and plot the gof, using the btergm approach

stat_plot_gof_as_btergm(
  m,
  ...,
  btergm_statistics = c(btergm::esp, btergm::geodesic, btergm::deg, btergm::rocpr),
  silent = FALSE,
  verbose = TRUE
)

Arguments

m

a fitted ergm or btergm model

...

optional arguments, see description

btergm_statistics

vector of statistics to be used in the gof

silent

logical, if TRUE fewer messages will be printed during the calculation of the gof (but the function will often still print some output)

verbose

logical, if FALSE, the printing of most details by the gof function is suppressed (but some warnings may still appear and errors are always shown)

Value

the goodness of fit is silently returned

Details

For a fitted ergm or btergm, this function calculates the goodness of fit (gof) and plots it. This is done using the btergm engine, which also works for fitted ergm models.

For calculating the gof, btergm provides the option to check the fit of the model against a range of statistics. See gof-statistics for an overview of the available statistics to check against. Note that these partly overlap with statistics available in the ergm package, but not exactly. If a statistic is required that is not inluded in the btergm package for use in the gof function (such as "nodecov"), you need to use the ergm package for this and can not use this function.

The ... argument allows one to pass arguments to the gof function, such as target, formula, parallel, ncpus. See the help of gof for the options.

Many messages that are returned during the whole process can be suppressed by setting silent = TRUE and verbose = FALSE.

NOTE: the goodness of fit is silently returned. The plot is always plotted.

NOTE: ergm and btergm are packages made by separate research groups. As a result, the objects and functions are not 100 percent compatible. If applying this function to an ergm-model returns weird errors, it is better to calculate the gof using the ergm package and then plot that (using stat_plot_gof or using the ergm package functions).

NOTE2: because the gof statistics for the models are determined inside the plotting functions (so they can be used for the plotting), they can take some time to run. This is why it is useful that the gof results themselves are not only calculated by this function, but also returned for further inspection.

See also

Other statistics functions: stat_ef_int(), stat_plot_gof()

Examples

if (FALSE) { # \dontrun{
### ergm model
data(florentine, package = "snafun")
flom <- to_network(florentine$flomarriage)
m_ergm <- ergm::ergm(flom ~ edges + nodecov("Wealth"))
gof_ergm <- stat_plot_gof_as_btergm(m_ergm)
gof_ergm <- stat_plot_gof_as_btergm(m_ergm, 
        btergm_statistics = c(btergm::esp, btergm::dsp, btergm::deg))
gof_ergm

### btergm model
data(alliances, package = "SNA4DSData")
m_btergm <- btergm::btergm(allianceNets ~ edges + 
  gwesp(0, fixed = TRUE) +
  edgecov(lastYearsSharedPartners) + 
  edgecov(militaryDisputes) + 
  nodecov("polity") +
  nodecov("Composite_Index_National_Capability") + 
  absdiff("polity") + 
  absdiff("Composite_Index_National_Capability") +
  edgecov(sharedBorder), 
  R = 100, # number of bootstraps, perhaps set lower to just try the example
  parallel = "snow", ncpus = 16  # optional line
)

# gof with only 10 simulations to keep time for the example low
gof_btergm <- stat_plot_gof_as_btergm(m_btergm, nsim = 10)
gof_btergm <- stat_plot_gof_as_btergm(m_btergm, 
  parallel = "snow", ncpus = 12)
gof_btergm
gof_btergm <- stat_plot_gof_as_btergm(m_btergm, 
  parallel = "snow", ncpus = 12, silent = TRUE)
gof_btergm <- stat_plot_gof_as_btergm(m_btergm, 
  parallel = "snow", ncpus = 12, verbose = FALSE, silent = TRUE)
} # }