. * nwergm tutorial 4: missing data and comparing models . * Requires the core nwcommands and the package nwergm. . . * ---- missing dyads: blank out three marriages of the Florentine families . nwwebuse florentine, nwclear . nwtomata flomarriage, mat(A) . mata: A[1,2] = A[2,1] = . . mata: A[3,5] = A[5,3] = . . mata: A[4,9] = A[9,4] = . . mata: st_matrix("Am", A) . tempfile nodes . save `nodes' file /var/folders/hx/2zp2k5ps2y7d_6hx015fcr1h0000gn/T//S_25986.000001 saved as .dta format . nwset, mat(Am) undirected name(flomiss) . use `nodes', clear . . nwergm flomarriage, edges nodecov(wealth) Exponential-family random graph model Network: = flomarriage Nodes: = 16 Ties: = 20 Directed: = No Estimation: = MPLE -------------------------------------------------------------------------------- flomarriage | Coefficient Std. err. z P>|z| [95% conf. interval] ---------------+---------------------------------------------------------------- edges | -2.594929 .5360561 -4.84 0.000 -3.64558 -1.544278 nodecov_wealth | .0105459 .0046743 2.26 0.024 .0013845 .0197073 -------------------------------------------------------------------------------- Maximum pseudolikelihood estimate (not full ERGM maximum likelihood unless the model is dyad-independent). Null Deviance: 166.4 on 120 degrees of freedom Residual Deviance: 103.1 on 118 degrees of freedom Log-likelihood: -51.5543 (df = 2) AIC: 107.1 BIC: 112.7 (MC std. err. = 0) . nwergm flomiss, edges nodecov(wealth) Note: network flomiss has 3 missing dyad(s); they are excluded from the (pseudo)likelihood and handled as in R's ergm (mi > ssing-data MCMLE). Exponential-family random graph model Network: = flomiss Nodes: = 16 Ties: = 19 Directed: = No Estimation: = MPLE -------------------------------------------------------------------------------- flomiss | Coefficient Std. err. z P>|z| [95% conf. interval] ---------------+---------------------------------------------------------------- edges | -2.692927 .552001 -4.88 0.000 -3.774829 -1.611025 nodecov_wealth | .0111924 .0047613 2.35 0.019 .0018604 .0205244 -------------------------------------------------------------------------------- Maximum pseudolikelihood estimate (not full ERGM maximum likelihood unless the model is dyad-independent). Null Deviance: 162.2 on 117 degrees of freedom Residual Deviance: 98.3 on 115 degrees of freedom Log-likelihood: -49.1649 (df = 2) AIC: 102.3 BIC: 107.9 (MC std. err. = 0) . display "missing dyads: " e(nmissing) " informative dyads: " e(N) missing dyads: 3 informative dyads: 117 . nwergm flomiss, edges nodecov(wealth) gwesp(0.5) seed(1) Note: network flomiss has 3 missing dyad(s); they are excluded from the (pseudo)likelihood and handled as in R's ergm (mi > ssing-data MCMLE). Exponential-family random graph model Network: = flomiss Nodes: = 16 Ties: = 19 Directed: = No Estimation: = MCMLE MCMC sample size: = 243 -------------------------------------------------------------------------------- flomiss | Coefficient Std. err. z P>|z| [95% conf. interval] ---------------+---------------------------------------------------------------- edges | -2.695761 .5798708 -4.65 0.000 -3.832287 -1.559235 nodecov_wealth | .0110237 .0055696 1.98 0.048 .0001075 .0219399 gwesp_0.5 | .0274984 .2881655 0.10 0.924 -.5372955 .5922923 -------------------------------------------------------------------------------- MCMLE converged after 1 iteration(s). Evaluating log-likelihood at the estimate (bridge sampling with 16 bridges) ... Null Deviance: 162.2 on 117 degrees of freedom Residual Deviance: 98.3 on 114 degrees of freedom Log-likelihood: -49.1563 (df = 3) AIC: 104.3 BIC: 112.6 (MC std. err. = .00172) . display "missing dyads: " e(nmissing) " informative dyads: " e(N) missing dyads: 3 informative dyads: 117 . . * ---- comparing models for the Lazega friendship network . nwwebuse lazega, nwclear . encode practice, generate(prac) . nwergm lazega_fr, edges mutual nodematch(prac) seed(1) Exponential-family random graph model Network: = lazega_fr Nodes: = 71 Ties: = 575 Directed: = Yes Estimation: = MCMLE MCMC sample size: = 391 -------------------------------------------------------------------------------- lazega_fr | Coefficient Std. err. z P>|z| [95% conf. interval] ---------------+---------------------------------------------------------------- edges | -2.740879 .0801423 -34.20 0.000 -2.897955 -2.583803 mutual | .991566 .1626233 6.10 0.000 .6728302 1.310302 nodematch_prac | .907421 .0921732 9.84 0.000 .7267649 1.088077 -------------------------------------------------------------------------------- MCMLE converged after 4 iteration(s). Evaluating log-likelihood at the estimate (bridge sampling with 16 bridges) ... Null Deviance: 6889.9 on 4970 degrees of freedom Residual Deviance: 3403.9 on 4967 degrees of freedom Log-likelihood: -1701.9440 (df = 3) AIC: 3409.9 BIC: 3429.4 (MC std. err. = .06952) . estimates store m1 . nwergm lazega_fr, edges mutual nodematch(prac) gwesp(0.5) seed(1) Exponential-family random graph model Network: = lazega_fr Nodes: = 71 Ties: = 575 Directed: = Yes Estimation: = MCMLE MCMC sample size: = 382 -------------------------------------------------------------------------------- lazega_fr | Coefficient Std. err. z P>|z| [95% conf. interval] ---------------+---------------------------------------------------------------- edges | -3.477526 .1008631 -34.48 0.000 -3.675214 -3.279838 mutual | .8207466 .1635668 5.02 0.000 .5001615 1.141332 nodematch_prac | .7016325 .0845186 8.30 0.000 .5359792 .8672859 gwesp_0.5 | .496614 .0584773 8.49 0.000 .3820006 .6112274 -------------------------------------------------------------------------------- MCMLE converged after 6 iteration(s). Evaluating log-likelihood at the estimate (bridge sampling with 16 bridges) ... Null Deviance: 6889.9 on 4970 degrees of freedom Residual Deviance: 3341.9 on 4966 degrees of freedom Log-likelihood: -1670.9684 (df = 4) AIC: 3349.9 BIC: 3376.0 (MC std. err. = .17019) . estimates store m2 . estat ic Akaike's information criterion and Bayesian information criterion ----------------------------------------------------------------------------- Model | N ll(null) ll(model) df AIC BIC -------------+--------------------------------------------------------------- lazega_fr | 4970 -3444.9 -1671 4 3349.9 3376 ----------------------------------------------------------------------------- Note: BIC uses N = number of informative dyads; MC std. err. of the log-likelihood = .17019 . estimates stats m1 m2 Akaike's information criterion and Bayesian information criterion ----------------------------------------------------------------------------- Model | N ll(null) ll(model) df AIC BIC -------------+--------------------------------------------------------------- m1 | 4,970 -3444.941 -1701.944 3 3409.888 3429.422 m2 | 4,970 -3444.941 -1670.968 4 3349.937 3375.981 ----------------------------------------------------------------------------- Note: BIC uses N = number of observations. See [R] IC note. . lrtest m2 m1 Likelihood-ratio test Assumption: m1 nested within m2 LR chi2(1) = 61.95 Prob > chi2 = 0.0000 . . * ---- predicted tie probabilities . predict, frame(pp) pr (frame pp contains one row per informative dyad: tail, head, p = conditional tie probability) . frame pp: summarize p Variable | Obs Mean Std. dev. Min Max -------------+--------------------------------------------------------- p | 4,970 .1157708 .0926077 .0299585 .8028117 . frame pp: list in 1/5 +-------------------------+ | tail head p | |-------------------------| 1. | 1 2 .02995849 | 2. | 1 3 .36097975 | 3. | 1 4 .10338511 | 4. | 1 5 .30611146 | 5. | 1 6 .03618957 | +-------------------------+ .