. * nwergm tutorial 5: constraints, two-mode networks and operators . * Requires the core nwcommands and the package nwergm. . . * ---- a constraint: keep the number of ties fixed . nwwebuse florentine, nwclear . nwergm flomarriage, edges nodecov(wealth) gwesp(0.5) seed(1) Exponential-family random graph model Network: = flomarriage Nodes: = 16 Ties: = 20 Directed: = No Estimation: = MCMLE MCMC sample size: = 243 -------------------------------------------------------------------------------- flomarriage | Coefficient Std. err. z P>|z| [95% conf. interval] ---------------+---------------------------------------------------------------- edges | -2.599772 .5426303 -4.79 0.000 -3.663308 -1.536237 nodecov_wealth | .0107953 .0051785 2.08 0.037 .0006457 .0209449 gwesp_0.5 | -.0170638 .2676109 -0.06 0.949 -.5415716 .5074439 -------------------------------------------------------------------------------- MCMLE converged after 1 iteration(s). Evaluating log-likelihood at the estimate (bridge sampling with 16 bridges) ... Null Deviance: 166.4 on 120 degrees of freedom Residual Deviance: 103.1 on 117 degrees of freedom Log-likelihood: -51.5528 (df = 3) AIC: 109.1 BIC: 117.5 (MC std. err. = .00149) . nwergm flomarriage, edges nodecov(wealth) gwesp(0.5) constraints(edges) seed(1) Note: the specified model's sample space constraint holds statistic(s) edges constant. They will be ignored. Exponential-family random graph model Network: = flomarriage Nodes: = 16 Ties: = 20 Directed: = No Estimation: = MCMLE MCMC sample size: = 243 -------------------------------------------------------------------------------- flomarriage | Coefficient Std. err. z P>|z| [95% conf. interval] ---------------+---------------------------------------------------------------- edges | 0 (omitted) nodecov_wealth | .0100932 .0048998 2.06 0.039 .0004898 .0196966 gwesp_0.5 | .0213663 .2638801 0.08 0.935 -.4958292 .5385619 -------------------------------------------------------------------------------- MCMLE converged after 1 iteration(s). Evaluating log-likelihood at the estimate (bridge sampling with 16 bridges) ... Null Deviance: 166.4 on 120 degrees of freedom Residual Deviance: 110.7 on 118 degrees of freedom Log-likelihood: -55.3402 (df = 2) AIC: 114.7 BIC: 120.3 (MC std. err. = .16122) . . * ---- a two-mode network: 30 people by 12 clubs (simulated for this tutorial) . clear . set seed 20261024 . nwclear . mata: ------------------------------------------------- mata (type end to exit) ----------------------------------------------- : g1 = (runiform(30,1) :> 0.5) :+ 1 : g2 = (runiform(12,1) :> 0.5) :+ 1 : P = J(30,12,0.08) : for (i=1;i<=30;i++) for (j=1;j<=12;j++) if (g1[i]==g2[j]) P[i,j] = 0.30 > B = (runiform(30,12) :< P) : st_matrix("B", B') : end ------------------------------------------------------------------------------------------------------------------------- . nwset, mat(B) bipartite name(clubs) . set obs 42 Number of observations (_N) was 42, now 42. . generate byte kind = . (42 missing values generated) . mata: st_store(., "kind", (g1 \ g2)) . nwsummarize -------------------------------------------------- Network name: clubs Network id: 1 Directed: false Valued: false Two-mode: true Nodes: 42 Level 1: 30 () Level 2: 12 () Selfloop: false Edges: 71 Minimum value: 0 Maximum value: 1 Density: .197 Temporal: false . nwergm clubs, edges nodemix(kind) Exponential-family random graph model Network: = clubs Nodes: = 42 Ties: = 71 Directed: = No Estimation: = MPLE ---------------------------------------------------------------------------------- clubs | Coefficient Std. err. z P>|z| [95% conf. interval] -----------------+---------------------------------------------------------------- edges | -.7563261 .1787266 -4.23 0.000 -1.106624 -.4060283 nodemix_kind_2_1 | -1.512357 .3931267 -3.85 0.000 -2.282872 -.7418434 nodemix_kind_1_2 | -2.379168 .6162542 -3.86 0.000 -3.587004 -1.171332 nodemix_kind_2_2 | -.2340726 .3707259 -0.63 0.528 -.9606821 .4925369 ---------------------------------------------------------------------------------- Maximum pseudolikelihood estimate (not full ERGM maximum likelihood unless the model is dyad-independent). Null Deviance: 499.1 on 360 degrees of freedom Residual Deviance: 321.2 on 356 degrees of freedom Log-likelihood: -160.5841 (df = 4) AIC: 329.2 BIC: 344.7 (MC std. err. = 0) . nwergm clubs, edges nodemix(kind) bgwdegree2(0.5) seed(1) Exponential-family random graph model Network: = clubs Nodes: = 42 Ties: = 71 Directed: = No Estimation: = MCMLE MCMC sample size: = 243 ---------------------------------------------------------------------------------- clubs | Coefficient Std. err. z P>|z| [95% conf. interval] -----------------+---------------------------------------------------------------- edges | -.7414179 .1930383 -3.84 0.000 -1.119766 -.3630697 nodemix_kind_2_1 | -1.506756 .4068944 -3.70 0.000 -2.304254 -.7092575 nodemix_kind_1_2 | -2.212356 .5936993 -3.73 0.000 -3.375985 -1.048727 nodemix_kind_2_2 | -.0559743 .4063925 -0.14 0.890 -.8524889 .7405403 bgwdegree2_0.5 | -1.690794 1.394711 -1.21 0.225 -4.424378 1.04279 ---------------------------------------------------------------------------------- MCMLE converged after 2 iteration(s). Evaluating log-likelihood at the estimate (bridge sampling with 16 bridges) ... Null Deviance: 499.1 on 360 degrees of freedom Residual Deviance: 320.2 on 355 degrees of freedom Log-likelihood: -160.1196 (df = 5) AIC: 330.2 BIC: 349.7 (MC std. err. = .0943) . . * ---- operators (development version): terms evaluated on a derived network . nwergm clubs, edges nodemix(kind) operators(Proj1(edges triangle)) seed(1) Exponential-family random graph model Network: = clubs Nodes: = 42 Ties: = 71 Directed: = No Estimation: = MCMLE MCMC sample size: = 503 ---------------------------------------------------------------------------------- clubs | Coefficient Std. err. z P>|z| [95% conf. interval] -----------------+---------------------------------------------------------------- edges | -1.103858 .3445076 -3.20 0.001 -1.77908 -.4286353 nodemix_kind_2_1 | -1.775325 .5405127 -3.28 0.001 -2.834711 -.7159399 nodemix_kind_1_2 | -2.355423 .6577301 -3.58 0.000 -3.64455 -1.066296 nodemix_kind_2_2 | -.3295673 .4577906 -0.72 0.472 -1.22682 .5676857 Proj1~edges | .1847007 .198093 0.93 0.351 -.2035545 .5729559 Proj1~triangle | -.012532 .0275408 -0.46 0.649 -.0665108 .0414469 ---------------------------------------------------------------------------------- MCMLE converged after 3 iteration(s). Evaluating log-likelihood at the estimate (bridge sampling with 16 bridges) ... Null Deviance: 499.1 on 360 degrees of freedom Residual Deviance: 317.8 on 354 degrees of freedom Log-likelihood: -158.9038 (df = 6) AIC: 329.8 BIC: 353.1 (MC std. err. = .09301) . nwwebuse lazega, nwclear . encode practice, generate(prac) . nwergm lazega_fr, edges mutual nodematch(prac) operators(Symmetrize(triangle, rule(strong))) seed(1) Exponential-family random graph model Network: = lazega_fr Nodes: = 71 Ties: = 575 Directed: = Yes Estimation: = MCMLE MCMC sample size: = 266 --------------------------------------------------------------------------------------------- lazega_fr | Coefficient Std. err. z P>|z| [95% conf. interval] ----------------------------+---------------------------------------------------------------- edges | -2.736101 .0829356 -32.99 0.000 -2.898652 -2.57355 mutual | .900128 .1705302 5.28 0.000 .5658949 1.234361 nodematch_prac | .8942052 .1007393 8.88 0.000 .6967598 1.091651 Symmetrize(strong)~triangle | .7278742 .4769188 1.53 0.127 -.2068695 1.662618 --------------------------------------------------------------------------------------------- MCMLE converged after 2 iteration(s). Evaluating log-likelihood at the estimate (bridge sampling with 16 bridges) ... Null Deviance: 6889.9 on 4970 degrees of freedom Residual Deviance: 3404.2 on 4966 degrees of freedom Log-likelihood: -1702.0947 (df = 4) AIC: 3412.2 BIC: 3438.2 (MC std. err. = .08466) .