library(sna)
library(ergm)
library(sand)
library(igraph)
library(network)
(sort(mydata))
## [1] "alc.att" "alc.beh" "fem" "fri" "hob" "res.act" "res.pas"
## [8] "sch.att" "sch.beh" "spo.att" "spo.beh" "str.abs" "tob.att" "tob.beh"
Explore the given dataset such as its class, dataframe, and format
Notes
data cleansing the adjacency matrix: fri_V
“fri” : adjacency matrix
“fem” : gender
Gender Clustering: “the socio-demographic variable is not ethnicity, but gender”
fri_mat = matrix(fri)
fri_V = fri_mat[,1][[1]]
omitted_V_nodes = c(-23, -24,-25)
fri_V_final = fri_V[omitted_V_nodes , omitted_V_nodes ]
igraph_fV_directed = graph.adjacency(as.matrix(fri_V_final),mode = "directed",weighted = NULL)
mynet_V = igraph_fV_directed
mynet_V$gender = fem[omitted_V_nodes]
Introduction:
In the paper of Goodreau, Kitts, and Morris (2009), the scholars believe that friendship is interdependent to generate complicated and complexed social network structure.
They claim that friendship’s network is not originated from ethnicity but rather from gender.
According to Balance Theory, + a friend of a friend is a “mutual” and “reciprocal” relation existed in human behaviors; + but “friends of your friends are (or are not) your friends” may be unconditionally transitive or may be potentially transitive or may be intransitive in a friendship triad closure.
Gender can also be classified as homophilic relation between human, of which the network can build up either by assortative mixing or selective mixing.
Our ERGM Models: mutuality(= reciporality )
+ Model_01 : friendship's Network = mutual + density + Gender
+ Model_02 : friendship's Network = mutual + density + transitive
+ Model_03 : friendship's Network = reciporality + density + Gender + gwesp(triad closure)library(network)
fem_V = fem[omitted_V_nodes]
fri_V_network = network(fri_V_final,directed=T)
fri_V_network %v% "sexFem" = fem_V
par(mfrow=c(1,2))
odegree <- rowSums(fri_V_final)
idegree <- colSums(fri_V_final)
hist(odegree, col="yellow")
hist(idegree, col="lightsteelblue")
Welch Two Sample t-test: Null Hypothesis : No difference in their means
t.test(odegree[fem_V==1],odegree[fem_V==0],var.equal=FALSE)
##
## Welch Two Sample t-test
##
## data: odegree[fem_V == 1] and odegree[fem_V == 0]
## t = 1.698, df = 19.994, p-value = 0.105
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
## -0.2121848 2.0693276
## sample estimates:
## mean of x mean of y
## 2.928571 2.000000
t.test(idegree[fem_V==1],idegree[fem_V==0], var.equal=FALSE)
##
## Welch Two Sample t-test
##
## data: idegree[fem_V == 1] and idegree[fem_V == 0]
## t = 1.4191, df = 17.429, p-value = 0.1735
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
## -0.4494089 2.3065518
## sample estimates:
## mean of x mean of y
## 2.928571 2.000000
Results:
There is no reason to reject the null hypothesis at 5% significant level for both cases.
There is no mean difference beteen outdegree for female and male 5% significant level.
There is no mean difference beteen inddegree for female and male 5% significant level.
plot.sociomatrix(fri_V_final)
ERGM Model_01 : friendship’s Network = mutual + density + Gender
library(ergm)
model_01 = formula( fri_V_network~ mutual + density + nodematch("sexFem"))
summary(model_01)
## mutual density nodematch.sexFem
## 16.0000000 0.1233766 53.0000000
summary(results_01)
## Call:
## ergm(formula = model_01)
##
## Monte Carlo Maximum Likelihood Results:
##
## Estimate Std. Error MCMC % z value Pr(>|z|)
## mutual 2.3989 0.4863 0 4.933 <1e-04 ***
## density -1914.8424 231.5911 0 -8.268 <1e-04 ***
## nodematch.sexFem 2.1265 0.5322 0 3.996 <1e-04 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Null Deviance: 640.5 on 462 degrees of freedom
## Residual Deviance: 267.5 on 459 degrees of freedom
##
## AIC: 273.5 BIC: 285.9 (Smaller is better. MC Std. Err. = 0.4164)
mcmc.diagnostics(results_01,vars.per.page=4)
## Sample statistics summary:
##
## Iterations = 15360:298496
## Thinning interval = 512
## Number of chains = 1
## Sample size per chain = 554
##
## 1. Empirical mean and standard deviation for each variable,
## plus standard error of the mean:
##
## Mean SD Naive SE Time-series SE
## mutual -0.56318 3.53599 0.1502299 0.22072
## density -0.00168 0.01688 0.0007173 0.00095
## nodematch.sexFem -0.66968 7.52507 0.3197096 0.49891
##
## 2. Quantiles for each variable:
##
## 2.5% 25% 50% 75% 97.5%
## mutual -7.17500 -3.00000 -1.000000 2.00000 6.00000
## density -0.03463 -0.01299 -0.002165 0.01082 0.02852
## nodematch.sexFem -15.00000 -5.00000 -1.000000 5.00000 13.17500
##
##
## Are sample statistics significantly different from observed?
## mutual density nodematch.sexFem Overall (Chi^2)
## diff. -0.56317690 -0.001680029 -0.6696751 NA
## test stat. -2.55157478 -1.768480055 -1.3422766 11.863750921
## P-val. 0.01072373 0.076980684 0.1795063 0.008592598
##
## Sample statistics cross-correlations:
## mutual density nodematch.sexFem
## mutual 1.0000000 0.7996594 0.8100870
## density 0.7996594 1.0000000 0.9661908
## nodematch.sexFem 0.8100870 0.9661908 1.0000000
##
## Sample statistics auto-correlation:
## Chain 1
## mutual density nodematch.sexFem
## Lag 0 1.00000000 1.00000000 1.00000000
## Lag 512 0.36601290 0.27293105 0.30680323
## Lag 1024 0.12268441 0.10266150 0.12984213
## Lag 1536 0.08697859 0.10775561 0.12780541
## Lag 2048 0.02552898 0.07523624 0.07918691
## Lag 2560 0.02862002 0.08184612 0.08338788
##
## Sample statistics burn-in diagnostic (Geweke):
## Chain 1
##
## Fraction in 1st window = 0.1
## Fraction in 2nd window = 0.5
##
## mutual density nodematch.sexFem
## 0.2136 0.6727 0.6135
##
## Individual P-values (lower = worse):
## mutual density nodematch.sexFem
## 0.8308900 0.5011144 0.5395189
## Joint P-value (lower = worse): 0.6814496 .
##
## MCMC diagnostics shown here are from the last round of simulation, prior to computation of final parameter estimates. Because the final estimates are refinements of those used for this simulation run, these diagnostics may understate model performance. To directly assess the performance of the final model on in-model statistics, please use the GOF command: gof(ergmFitObject, GOF=~model).
Results: ERGM Mode_01
There is no reason to accept the null hypothesis at 1% significant level for both cases.
It concludes that all coefficients are statistically signifcant different from zero at 1% level.
ERGM Model_02 : friendship’s Network = mutual + density + transitive
library(ergm)
model_02 = formula( fri_V_network~ mutual + density + transitive )
summary(model_02)
## mutual density transitive
## 16.0000000 0.1233766 56.0000000
Results: Model_02
Model_02 has problem of “Unconstrained MCMC sampling”.
Computation process is crashed and stoped.
The reason is mainly due to the interdepedency of transitive triad with other main effects(mutuality and density)
ERGM Model_03 : friendship’s Network = reciporality + density + Gender + gwesp(triad Closure)
library(ergm)
model_03 = formula( fri_V_network~ mutual + density + nodematch("sexFem") + gwesp(.5,fixed=T) )
summary(model_03)
## mutual density nodematch.sexFem gwesp.fixed.0.5
## 16.0000000 0.1233766 53.0000000 44.8791232
summary(results_03)
## Call:
## ergm(formula = model_03)
##
## Monte Carlo Maximum Likelihood Results:
##
## Estimate Std. Error MCMC % z value Pr(>|z|)
## mutual 2.1626 0.5249 0 4.120 < 1e-04 ***
## density -1957.8554 213.3438 0 -9.177 < 1e-04 ***
## nodematch.sexFem 1.6431 0.5209 0 3.155 0.00161 **
## gwesp.fixed.0.5 0.4550 0.1520 0 2.993 0.00276 **
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Null Deviance: 640.5 on 462 degrees of freedom
## Residual Deviance: 258.5 on 458 degrees of freedom
##
## AIC: 266.5 BIC: 283.1 (Smaller is better. MC Std. Err. = 0.2965)
mcmc.diagnostics(results_03,vars.per.page=6)
## Sample statistics summary:
##
## Iterations = 40960:804352
## Thinning interval = 512
## Number of chains = 1
## Sample size per chain = 1492
##
## 1. Empirical mean and standard deviation for each variable,
## plus standard error of the mean:
##
## Mean SD Naive SE Time-series SE
## mutual -0.456434 5.89229 0.1525456 0.412308
## density -0.001361 0.03018 0.0007815 0.002173
## nodematch.sexFem -0.618633 13.68850 0.3543817 0.993668
## gwesp.fixed.0.5 -1.001169 23.22476 0.6012663 1.729272
##
## 2. Quantiles for each variable:
##
## 2.5% 25% 50% 75% 97.5%
## mutual -11.00000 -5.00000 -1.000000 4.00000 11.00000
## density -0.05844 -0.02381 -0.002165 0.01948 0.05568
## nodematch.sexFem -26.00000 -10.00000 0.000000 9.00000 26.00000
## gwesp.fixed.0.5 -39.31886 -18.93273 -1.624247 14.94599 48.28443
##
##
## Are sample statistics significantly different from observed?
## mutual density nodematch.sexFem gwesp.fixed.0.5
## diff. -0.4564343 -0.001360793 -0.6186327 -1.0011687
## test stat. -1.1070221 -0.626219164 -0.6225750 -0.5789538
## P-val. 0.2682844 0.531171199 0.5335638 0.5626203
## Overall (Chi^2)
## diff. NA
## test stat. 16.338125990
## P-val. 0.002842237
##
## Sample statistics cross-correlations:
## mutual density nodematch.sexFem gwesp.fixed.0.5
## mutual 1.0000000 0.9320008 0.9393037 0.9297090
## density 0.9320008 1.0000000 0.9877548 0.9452518
## nodematch.sexFem 0.9393037 0.9877548 1.0000000 0.9538360
## gwesp.fixed.0.5 0.9297090 0.9452518 0.9538360 1.0000000
##
## Sample statistics auto-correlation:
## Chain 1
## mutual density nodematch.sexFem gwesp.fixed.0.5
## Lag 0 1.0000000 1.0000000 1.0000000 1.0000000
## Lag 512 0.7590509 0.7316538 0.7424016 0.7530038
## Lag 1024 0.5881496 0.5769209 0.5845584 0.5998112
## Lag 1536 0.4635913 0.4592120 0.4669412 0.4788430
## Lag 2048 0.3775750 0.3772068 0.3809623 0.3885777
## Lag 2560 0.3093134 0.2930833 0.2990134 0.3023368
##
## Sample statistics burn-in diagnostic (Geweke):
## Chain 1
##
## Fraction in 1st window = 0.1
## Fraction in 2nd window = 0.5
##
## mutual density nodematch.sexFem gwesp.fixed.0.5
## -0.2888 -0.3107 -0.3348 -0.2616
##
## Individual P-values (lower = worse):
## mutual density nodematch.sexFem gwesp.fixed.0.5
## 0.7727193 0.7560153 0.7377989 0.7936380
## Joint P-value (lower = worse): 0.9785797 .
##
## MCMC diagnostics shown here are from the last round of simulation, prior to computation of final parameter estimates. Because the final estimates are refinements of those used for this simulation run, these diagnostics may understate model performance. To directly assess the performance of the final model on in-model statistics, please use the GOF command: gof(ergmFitObject, GOF=~model).