. * nwalaam tutorial 2: smoking in the Glasgow friendship network . * Requires the core nwcommands and the package nwalaam. The data (Teenage Friend > s and Lifestyle Study) are loaded from the nwcommands website. . set linesize 80 . . * --- the outcome: occasional or regular smoker, wave 1; the network: who name > s whom as a friend --- . nwwebuse glasgow, nwclear . generate byte smoker1 = (smoke1 > 1) . tabulate smoker1 smoker1 | Freq. Percent Cum. ------------+----------------------------------- 0 | 38 76.00 76.00 1 | 12 24.00 100.00 ------------+----------------------------------- Total | 50 100.00 . . * --- contagion alone: the pseudo-likelihood is a logit on the number of ties > to smokers --- . nwalaam smoker1 glasgow1, effects(density contagion) mple ---------------------------------------------------------------------- Autologistic actor attribute model (maximum pseudo-likelihood) Outcome: smoker1 (12 of 50) Network: glasgow1 ---------------------------------------------------------------------- ----------------------------------------------------- smoker1 | Coefficient Std. err. z P>|z| -------------+--------------------------------------- density | -1.769064 .4589819 -3.85 0.000 contagion | .4525797 .1989247 2.28 0.023 ----------------------------------------------------- . . * --- the maximum likelihood estimate, with activity effects of the senders an > d receivers of ties --- . nwalaam smoker1 glasgow1, effects(density contagion sender receiver) seed(2026 > 1118) ---------------------------------------------------------------------- Autologistic actor attribute model (stochastic approximation) Outcome: smoker1 (12 of 50) Network: glasgow1 SA repetitions: 1 (converged: yes) Proposals per iteration: 1000 ---------------------------------------------------------------------- ----------------------------------------------------- smoker1 | Coefficient Std. err. z P>|z| -------------+--------------------------------------- density | -1.120924 .7140531 -1.57 0.116 contagion | .7415663 .2825708 2.62 0.009 sender | -.5224544 .39374 -1.33 0.185 receiver | .0293046 .2652388 0.11 0.912 ----------------------------------------------------- All convergence t-ratios are within .1 in absolute value. . . * --- covariates: the command does not centre them, so centre them first --- . quietly summarize alcohol1 . generate double alc_c = alcohol1 - r(mean) . quietly summarize sport1 . generate double sport_c = sport1 - r(mean) . nwalaam smoker1 glasgow1, effects(density contagion sender receiver ego(alc_c) > ego(sport_c)) seed(20261118) ---------------------------------------------------------------------- Autologistic actor attribute model (stochastic approximation) Outcome: smoker1 (12 of 50) Network: glasgow1 SA repetitions: 1 (converged: yes) Proposals per iteration: 1000 ---------------------------------------------------------------------- ----------------------------------------------------- smoker1 | Coefficient Std. err. z P>|z| -------------+--------------------------------------- density | -1.202652 1.062661 -1.13 0.258 contagion | .4173669 .3472694 1.20 0.229 sender | -.3880205 .5812799 -0.67 0.504 receiver | -.2609823 .3967369 -0.66 0.511 ego_alc_c | 1.859464 .6992444 2.66 0.008 ego_sport_c | .2146388 .9961019 0.22 0.829 ----------------------------------------------------- All convergence t-ratios are within .1 in absolute value. . . * --- does the model reproduce statistics that are not in it? --- . estat gof, nsim(1000) seed(7) Goodness of fit: 1,000 simulated outcome vectors from the fitted model (burn-in > 10,000, interval 1,000) ------------------------------------------------------------ Statistic | Observed Sim. mean Sim. SD t-ratio ---------------+-------------------------------------------- density | 12.000 12.113 2.612 0.043 contagion | 14.000 14.335 6.067 0.055 sender | 26.000 26.331 6.380 0.052 receiver | 30.000 30.423 7.887 0.054 ego_alc_c | 13.440 13.666 2.802 0.080 ego_sport_c | 0.120 0.111 1.081 -0.008 ---------------+-------------------------------------------- not in the model: | reciprocity | 20.000 19.911 5.077 -0.018 outstar2 | 18.000 20.382 6.496 0.367 * instar2 | 46.000 45.922 15.777 -0.005 mixedstar | 52.000 56.643 18.112 0.256 mixedsource | 48.000 45.129 12.160 -0.236 mixedsink | 75.000 61.750 17.497 -0.757 * contagionrecip | 5.000 5.333 2.501 0.133 transitive1 | 21.000 22.928 6.253 0.308 * transitive3 | 8.000 10.284 7.156 0.319 * transitived1 | 22.000 22.001 5.106 0.000 transitiveu1 | 27.000 26.372 7.554 -0.083 cyclic1 | 15.000 15.631 4.642 0.136 cyclic3 | 2.000 2.199 1.736 0.115 alterinstar2 | 13.000 10.196 5.430 -0.516 * alteroutstar2 | 22.000 13.505 6.240 -1.361 * ------------------------------------------------------------ Mahalanobis distance of the observed statistics from the simulated ones: 5.2 > 08 t-ratio = (simulated mean - observed) / simulated SD; * marks |t| > 0.3 (t-ratios of the statistics in the model should be near 0 after a converged fit; for the other statistics, values within about 0.3 indicate a good fit). . . * --- simulate outcome vectors from the fitted model --- . nwalaam simulate, nsim(100) generate(sim) seed(2) Simulated 100 outcome vectors on 50 actors, stored in variables sim1 to sim100 ( > seed 2, burn-in 10000 and interval 1000 proposals). . egen simsmoke = rowtotal(sim1-sim100) . summarize simsmoke Variable | Obs Mean Std. dev. Min Max -------------+--------------------------------------------------------- simsmoke | 50 23.3 27.18362 0 93 . . * --- a different quantity: the exposure regression on the share of friends wh > o smoke --- . nwaltergen frsmoke = proportion(alter.smoker1==1), net(glasgow1) . logit smoker1 frsmoke Iteration 0: log likelihood = -26.402367 Iteration 1: log likelihood = -23.114555 Iteration 2: log likelihood = -23.017159 Iteration 3: log likelihood = -23.017074 Iteration 4: log likelihood = -23.017074 Logistic regression Number of obs = 46 LR chi2(1) = 6.77 Prob > chi2 = 0.0093 Log likelihood = -23.017074 Pseudo R2 = 0.1282 ------------------------------------------------------------------------------ smoker1 | Coefficient Std. err. z P>|z| [95% conf. interval] -------------+---------------------------------------------------------------- frsmoke | 2.588576 1.050983 2.46 0.014 .5286875 4.648465 _cons | -1.83919 .5196682 -3.54 0.000 -2.857721 -.8206591 ------------------------------------------------------------------------------ .