. * nwlsm tutorial 1: a latent space model for the karate club . * Requires the core nwcommands and the package nwlsm. The data (Zachary 1977) ar > e loaded from the nwcommands website. . set linesize 80 . . nwwebuse zachary, nwclear . nwsummarize zachary_bin -------------------------------------------------- Network name: zachary_bin Network id: 1 Directed: false Valued: false Two-mode: false Nodes: 34 Selfloop: false Edges: 78 Minimum value: 0 Maximum value: 1 Density: .139 Mean degree: 4.59 Temporal: false . . * --- a two-dimensional Euclidean latent space model, two chains of 1,000 draw > s --- . nwlsm zachary_bin, dim(2) nsample(2000) burnin(5000) interval(10) chains(2) se > ed(20261120) ------------------------------------------------------------------------------ Latent space model (Euclidean distance; bernoulli family), posterior by MCMC Network: zachary_bin (34 actors, undirected) Latent dimensions: 2 Draws: 2000 burn-in: 5000 interval: 10 Seed: 20261120 Chains: 2 (1000 draws each, pooled) Posterior mean log likelihood: -170.621 (sd 7.596) ------------------------------------------------------------------------------ Mean Sd MC s.e. Lower 95% Upper 95% ------------------------------------------------------------------------------ _cons 1.0127 0.3748 0.0271 0.3151 1.7703 ------------------------------------------------------------------------------ Variance parameters (posterior): sigma2 4.6310 1.5218 0.0955 2.2146 8.3254 ------------------------------------------------------------------------------ Acceptance rate of the latent positions: 0.239 Gelman-Rubin statistic: largest value 1.005 (see estat mcmcdiag) Positions: minimum Kullback-Leibler estimate e(Z) (also estat positions); mean of the draws aligned to it e(Zmean); posterior mean distances e(D); posterior mean tie probabilities e(P). Positions are identified up to rotation, reflection and translation only. . . * --- did the chains converge? --- . estat mcmcdiag MCMC diagnostics (2000 draws in 2 chains, interval 10) -------------------------------------------------------------------------- Parameter Mean Sd ESS ESS/draw Geweke z Rhat -------------------------------------------------------------------------- _cons 1.0127 0.3748 160.8 0.080 -0.73 1.005 loglik -170.6210 7.5961 263.2 0.132 -1.47 1.001 sigma2 4.6310 1.5218 229.0 0.114 -0.72 1.003 -------------------------------------------------------------------------- Acceptance rates: positions 0.239, _cons 0.233 ESS: effective sample size by the initial monotone positive sequence estimator. With 2 chains: ESS is the sum over the chains, Geweke z (above) the value of largest size over the chains, Rhat the Gelman-Rubin potential scale reduction factor (values close to 1, say below 1.1, indicate that the chains agree). Geweke z by chain ------------------------------ Parameter chain1 chain2 ------------------------------ _cons -0.73 -0.69 loglik -1.47 -1.46 sigma2 -0.72 -0.58 ------------------------------ Geweke z: first 10% of the draws against the last 50%, as geweke.diag() of R's coda (spectral density at frequency zero of each part from an autoregressive fit); |z| > 1.96 is the nominal two-sided 5% limit. 0 of the 6 z values (3 parameters, 2 chains) exceed it (largest |z| 1.47); about 0.3 (5%) would exceed it by chance with long settled chains, and more with short chains (a first part of a few dozen draws gives a noisy z), so read the z values together with the trace plots (graph) and the effective sample sizes; they are no test of convergence. . . * --- the positions of the actors --- . estat positions Positions of the actors (minimum Kullback-Leibler estimate) -------------------------------------- Actor dim1 dim2 -------------------------------------- r1 -0.8032 -0.1903 r2 -0.7085 -0.2280 r3 -0.2556 -0.1406 r4 -0.7419 -0.2159 r5 -1.8200 0.5175 r6 -1.8975 0.7206 r7 -1.8975 0.7206 r8 -0.7419 -0.2159 r9 0.3700 -0.1619 r10 0.3990 -0.9081 r11 -1.8488 0.5115 r12 -1.8130 -1.2628 r13 -1.3779 -0.3285 r14 -0.5628 -0.1852 r15 1.4787 -0.7135 r16 1.3684 -0.4310 r17 -2.1228 0.9878 r18 -1.2708 -0.6409 r19 1.2105 -0.7938 r20 -0.4703 -0.4931 r21 1.6313 -0.1158 r22 -1.0880 -0.8928 r23 1.6835 -0.3917 r24 1.1858 0.4073 r25 0.9974 1.2651 r26 1.0545 1.2014 r27 1.9793 0.3312 r28 0.9008 0.6457 r29 0.4682 0.4535 r30 1.4516 0.2141 r31 0.5026 -0.1847 r32 0.7656 0.5851 r33 1.0081 -0.0427 r34 0.9653 -0.0242 -------------------------------------- Positions are identified up to rotation, reflection and translation only. . . * --- the network drawn in the latent space --- . nwlsmplot, title("The karate club in the latent space") . graph export "karate_positions.png", width(900) replace . . * --- the uncertainty of the positions: 100 posterior draws as a faint cloud - > -- . nwlsmplot, draws(100) title("The karate club with 100 posterior draws of the p > ositions") . graph export "karate_draws.png", width(900) replace . . * --- does the fitted model reproduce the degrees and distances of the network > ? --- . estat gof Goodness of fit: degree (100 networks simulated from the posterior) ------------------------------------------------------------------ Degree | Observed Min Mean Max MC p-value -------------+---------------------------------------------------- 0 | 0 0 0.98 4 0.70 1 | 1 0 2.12 7 0.70 2 | 11 1 3.91 10 0.00 3 | 6 1 4.94 11 0.80 4 | 6 1 5.46 12 0.94 5 | 3 1 5.03 12 0.44 6 | 2 1 4.25 10 0.22 7 | 0 0 3.23 8 0.10 8 | 0 0 1.98 8 0.26 9 | 1 0 1.19 5 1.00 10 | 1 0 0.48 2 0.76 11 | 0 0 0.30 3 1.00 12 | 1 0 0.10 2 0.18 13 | 0 0 0.03 1 1.00 16 | 1 0 0.00 0 0.00 17 | 1 0 0.00 0 0.00 ------------------------------------------------------------------ Goodness of fit: minimum geodesic distance (100 networks simulated from the post > erior) ------------------------------------------------------------------ Distance | Observed Min Mean Max MC p-value -------------+---------------------------------------------------- 1 | 78 53 78.05 104 1.00 2 | 265 104 193.75 273 0.02 3 | 137 110 172.50 206 0.10 4 | 73 11 63.74 114 0.74 5 | 8 0 13.45 45 0.88 6 | 0 0 2.25 30 1.00 7 | 0 0 0.35 16 1.00 8 | 0 0 0.06 5 1.00 Inf | 0 0 36.85 126 0.64 ------------------------------------------------------------------ Each simulated network is drawn from the model at one of 100 posterior draws (evenly spaced over the stored draws). MC p-value: 2 min(P(simulated <= observed), P(simulated >= observed)), at most 1, as in latentnet. Missing dyads of the observed network count as no tie. .