Skip to content
ergmito: Estimation of Little ‘ERGMs’ using exact likelihood
Branch: master
Clone or download
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
R
data-raw
data
man Documenting and trying to fix travis [skip appveyor] Apr 10, 2019
playground
src
tests Working on GOF, adding geodesics (although not sure how to use that i… Apr 8, 2019
.Rbuildignore Working on new functions to manipulate network objects better Mar 12, 2019
.gitignore
.travis.yml Documenting and trying to fix travis [skip appveyor] Apr 10, 2019
CODE_OF_CONDUCT.md
DESCRIPTION Adding routine to compute GOF statistics. Still work in progress, but… Mar 29, 2019
LICENSE Making it usable R package Nov 16, 2018
LICENSE.md Making it usable R package Nov 16, 2018
NAMESPACE Documenting and trying to fix travis [skip appveyor] Apr 10, 2019
README.Rmd Working on GOF, adding geodesics (although not sure how to use that i… Apr 8, 2019
README.md Working on GOF, adding geodesics (although not sure how to use that i… Apr 8, 2019
appveyor.yml Fixing travis and appveyor Mar 29, 2019
codecov.yml Adding tests Nov 18, 2018
ergmito.Rproj
makefile Working on new functions to manipulate network objects better Mar 12, 2019

README.md

ergmito: Estimation of Little ‘ERGMs’ using exact likelihood

lifecycle CRAN status Travis build status AppVeyor Build status codecov

This R package, which has been developed on top of the amazing work that the Statnet team has done, implements estimation and simulation methods for Exponential Random Graph Models of small networks, in particular, less than 7 nodes. In the case of small networks, the calculation of the likelihood of ERGMs becomes computationally feasible, which allows us avoiding approximations and do exact calculation, ultimately obtaining MLEs directly.

Support

This material is based upon work support by, or in part by, the U.S. Army Research Laboratory and the U.S. Army Research Office under grant number W911NF-15-1-0577

Computation for the work described in this paper was supported by the University of Southern California’s Center for High-Performance Computing (hpcc.usc.edu).

Installation

The development version from GitHub with:

# install.packages("devtools")
devtools::install_github("muriteams/ergmito")

This requires compilation. Windows users can download the lates compiled version from appveyor here. The file to download is the one named ergmito_[version number].zip. Once donwloaded, you can install typing the following:

install.packages("[path to the zipfile]/ergmito_[version number].zip", repos = FALSE)

Example

An example from the manual

When ergm is not enough

library(ergmito)
library(sna)

# Generating a small graph
set.seed(12)
n <- 4
net <- rbernoulli(n, p = .7)
gplot(net)

model <- net ~ edges + mutual + ctriad

library(ergm)
ans_ergmito <- ergmito(model)
ans_ergm  <- ergm(model)
#> Error in solve.default(H, tol = 1e-20) : 
#>   Lapack routine dgesv: system is exactly singular: U[2,2] = 0

# The ergmito should have a larger value when computing exact loglikelihood
ergm.exact(ans_ergmito$coef, model) >
  ergm.exact(ans_ergm$coef, model)
#>       [,1]
#> [1,] FALSE

summary(ans_ergmito)
#> $coefs
#>          Estimate Std. Error    z value  Pr(>|z|)
#> edges    8.664306   43.72599  0.1981500 0.8429277
#> mutual  -7.207248   43.71588 -0.1648657 0.8690497
#> ctriple -0.639525    1.32637 -0.4821619 0.6296909
#> 
#> $aic
#> [1] 18.23709
#> 
#> $bic
#> [1] 19.69181
#> 
#> $model
#> [1] "net ~ edges + mutual + ctriad"
#> 
#> attr(,"class")
#> [1] "ergmito_summary"
summary(ans_ergm)
#> 
#> ==========================
#> Summary of model fit
#> ==========================
#> 
#> Formula:   net ~ edges + mutual + ctriad
#> 
#> Iterations:  2 out of 20 
#> 
#> Monte Carlo MLE Results:
#>         Estimate Std. Error MCMC % z value Pr(>|z|)
#> edges     20.296         NA     NA      NA       NA
#> mutual   -18.832         NA     NA      NA       NA
#> ctriple   -0.643         NA     NA      NA       NA
#> 
#>      Null Deviance: 16.64  on 12  degrees of freedom
#>  Residual Deviance: 12.28  on  9  degrees of freedom
#>  
#> AIC: 18.28    BIC: 19.74    (Smaller is better.)

Checking convergence diagnostics

plot(ans_ergmito)

Do we get the same?

# Generating a small graph
set.seed(12123)
n   <- 4
net <- rbernoulli(n, p = .3)
gplot(net)

model <- net ~ edges + mutual

library(ergm)
ans_ergmito <- ergmito(model)
ans_ergm  <- ergm(model, control = control.ergm(
  MCMC.effectiveSize = 4000,
  seed = 444)
  )

# The ergmito should have a larger value
ergm.exact(ans_ergmito$coef, model) > ergm.exact(ans_ergm$coef, model)
#>      [,1]
#> [1,]   NA

summary(ans_ergmito)
#> $coefs
#>         Estimate Std. Error    z value  Pr(>|z|)
#> edges  -0.691919  0.8165109 -0.8474094 0.3967669
#> mutual -8.195552 69.4693583 -0.1179736 0.9060886
#> 
#> $aic
#> [1] 16.47707
#> 
#> $bic
#> [1] 17.44688
#> 
#> $model
#> [1] "net ~ edges + mutual"
#> 
#> attr(,"class")
#> [1] "ergmito_summary"
summary(ans_ergm)
#> 
#> ==========================
#> Summary of model fit
#> ==========================
#> 
#> Formula:   net ~ edges + mutual
#> 
#> Iterations:  2 out of 20 
#> 
#> Monte Carlo MLE Results:
#>        Estimate Std. Error MCMC % z value Pr(>|z|)    
#> edges   -0.6834     0.8189      0  -0.835    0.404    
#> mutual     -Inf     0.0000      0    -Inf   <1e-04 ***
#> ---
#> Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#> 
#>      Null Deviance: 16.64  on 12  degrees of freedom
#>  Residual Deviance:   NaN  on 10  degrees of freedom
#>  
#> AIC: NaN    BIC: NaN    (Smaller is better.) 
#> 
#>  Warning: The following terms have infinite coefficient estimates:
#>   mutual

Estimating data with known parameters

The following example shows the estimation of a dataset that is included in the package, fivenets. This set of five networks was generated using the new_rergmito function which allows creating a function to draw random ERGMs with a fixed set of parameters, in this case, edges = -2.0 and nodematch("female") = 2.0

data(fivenets)

model1 <- ergmito(fivenets ~ edges + nodematch("female"))

summary(model1) # This data has know parameters equal to -2.0 and 2.0
#> $coefs
#>                   Estimate Std. Error   z value    Pr(>|z|)
#> edges            -1.704748  0.5435573 -3.136280 0.001711055
#> nodematch.female  1.586965  0.6430475  2.467882 0.013591530
#> 
#> $aic
#> [1] 73.34109
#> 
#> $bic
#> [1] 77.52978
#> 
#> $model
#> [1] "fivenets ~ edges + nodematch(\"female\")"
#> 
#> attr(,"class")
#> [1] "ergmito_summary"

We can also compute GOF

fivenets_gof <- gof_ergmito(model1)
fivenets_gof
#> 
#> Goodness-of-fit for edges 
#> 
#>       obs min mean max lower upper lower prob. upper prob.
#> net 1   2   0  3.7  12     0     6      0.0081        0.96
#> net 2   7   0  3.7  12     0     6      0.0081        0.96
#> net 3   4   0  3.1  12     0     6      0.0206        0.99
#> net 4   5   0  5.6  12     2     8      0.0309        0.95
#> net 5   2   0  3.7  12     0     6      0.0081        0.96
#> 
#> 
#> Goodness-of-fit for nodematch.female 
#> 
#>       obs min mean max lower upper lower prob. upper prob.
#> net 1   2   0  2.8   6     0     5       0.022        0.99
#> net 2   5   0  2.8   6     0     5       0.022        0.99
#> net 3   3   0  1.9   4     0     3       0.079        0.95
#> net 4   5   0  5.6  12     2     8       0.031        0.95
#> net 5   1   0  2.8   6     0     5       0.022        0.99
#> 
#> Note: Exact confidence intervals where used. This implies that the requestes CI may differ from the one used (see ?gof).
plot(fivenets_gof)

Similarity indices

https://cran.r-project.org/web/packages/proxy/proxy.pdf

A Survey of Binary Similarity and Distance Measures Seung-Seok Choi, Sung-Hyuk Cha, Charles C. Tappert Department of Computer Science, Pace University New York, US

Contributing

Please note that the ‘ergmito’ project is released with a Contributor Code of Conduct. By contributing to this project, you agree to abide by its terms.

You can’t perform that action at this time.