gofN: Linear model diagnostics for multinetwork linear models

View source: R/gofN.R

gofNR Documentation

Linear model diagnostics for multinetwork linear models

Description

gofN() performs a simulation to obtain Pearson residuals for the multivariate linear model for ERGM parameters, which can then be used for a variety of diagnostics and diagnostic plots developed by \insertCiteKrCo22t;textualergm.multi.

Usage

gofN(
  object,
  GOF = NULL,
  subset = TRUE,
  control = control.gofN.ergm(),
  save_stats = FALSE,
  ...
)

## S3 method for class 'gofN'
x[i, j, ..., drop = FALSE]

## S3 method for class 'gofN'
augment(x, ...)

## S3 method for class 'gofN'
summary(object, by = NULL, ...)

Arguments

object

an ergm object.

GOF

a one-sided ergm formula specifying network statistics whose goodness of fit to test, or NULL; if NULL, uses the original model.

subset

argument for the N term.

control

See control.gofN.ergm().

save_stats

If TRUE, save the simulated network statistics; defaults to FALSE to save memory and disk space.

...

additional arguments to functions (simulate.ergm() and summary.ergm_model()) for the constructor.

x

a gofN object.

i

for the indexing operator, index of statistics to be kept in the subset.

j

for the indexing operator, index of networks to be kept in the subset.

drop

whether the indexing operator should drop attributes and return simply a list.

by

a numeric or character vector, or a formula whose RHS gives an expression in terms of network attributes, used as a grouping variable for summarizing the values.

Value

An object of class gofN: a named list containing a list for every statistic in the specified GOF formula with the following elements vectors of length equal to the number of subnetworks:

observed

For completely observed networks, their value of the statistic. For partially observed networks, the expected value of their imputations under the model.

fitted

Expected value of the statistic under the model.

var

Variance of the statistic under the model.

var.obs

Conditional variance under imputation statistic.

pearson

The Pearson residual computed from the above.

stats, stats.obs

If save_stats control parameter is TRUE, the simulated statistics.

In addition, the following attr-style attributes are included:

nw

The observed multinetwork object.

subset

A logical vector giving the subset of networks that were used.

control

Control parameters passed.

Methods (by generic)

  • [: Extract a subset of statistics for which goodness-of-fit had been computed.

  • augment(gofN): a method for constructing a tibble of network attributes augmented with goodness of fit information. Columns include:

    network attributes

    the attributes of each of the networks

    .stat_name

    name of the simulated statistic

    .stat_id

    index of the simulated statistic in the gofN object

    .network_id

    index of the network in the networks for which gofN was run (excluding those not in the subset)

    .fitted

    predicted value for the statistic

    .observed

    either the observed (for completely observed networks) or the predicted conditional on observed (for partially observed networks) value of the statistic

    .pearson

    the standardised Pearson residual

    .var, .var.obs

    estimated unconditional and average conditional variance of the statistic

    .weight

    inverse of the variance of the residual

  • summary(gofN): A simple summary function.

References

\insertAllCited

See Also

plot.gofN() and autoplot.gofN() for plotting gofN objects to make residual plots; ergm::gof() for single-network goodness-of-fit simulations in ergm

Examples

data(samplk)
monks <- Networks(samplk1, samplk2, samplk3,samplk1, samplk2, samplk3,samplk1, samplk2, samplk3)
fit <- ergm(monks~N(~edges+nodematch("group")))
fit.gof <- gofN(fit) # GOF = original model
summary(fit.gof)
plot(fit.gof)
fit.gof <- gofN(fit, GOF=~triangles)
summary(fit.gof)
plot(fit.gof)


samplk1[1,]<-NA
samplk2[,2]<-NA
monks <- Networks(samplk1, samplk2, samplk3,samplk1, samplk2, samplk3,samplk1, samplk2, samplk3)
fit <- ergm(monks~N(~edges+nodematch("group")))
fit.gof <- gofN(fit) # GOF = original model
summary(fit.gof)
plot(fit.gof)
fit.gof <- gofN(fit, GOF=~triangles)
summary(fit.gof)
plot(fit.gof)
plot(fit.gof, against=~log(.fitted)) # Plot against transformed fitted values.


### If 'ggplot2' and 'ggrepel' are installed, illustrate the autoplot() method.
if(require("ggplot2") && requireNamespace("ggrepel")){
  autoplot(fit.gof)
}

# Default is good enough in this case, but sometimes, we might want to set it higher. E.g.,
## Not run: 
fit.gof <- gofN(fit, GOF=~edges, control=control.gofN.ergm(nsim=400))

## End(Not run)


### If 'generics' is installed, illustrate the augment() method.
if(require("generics")){
  augment(fit.gof)
}


ergm.multi documentation built on May 29, 2024, 11:07 a.m.