This is an R package for replication of the methods and analysis in A Structural Model of Segregation in Social Networks.
To install the package from the Github repository, you need to have devtools
already installed.
If you don't have the devtools
, install it using the following command
install.packages("devtools")
Then open devtools
and use the install_github
command to download and install netnew
:
library(devtools)
install_github("meleangelo/netnew")
This should install the package. This works well in Windows, using RStudio.
To use the package just open it as an R library
library(netnew)
Now you should be able to run the codes.
We want to simulate a model with
library(netnew)
set.seed(1977)
n <- 100 # size of network
a <- c(-3,0,3/n) # parameters for simulations
g <- matrix(data = rbinom(n*n,1,0), nrow = n, ncol = n)
diag(g)<-0
net <- simulatemodel(model = "3params", g, a, skip = 15, samplesize = 10000)
The function simulatemodel
is used to simulate some specific model. 3params
has 3 parameters: direct utility, reciprocity, and indirect links. Here we set the parameter for reciprocity to zero. The result is the sample of simulated network statistics
head(net)
links mutual indirect
1 0 0 0
2 1 0 0
3 1 0 0
4 2 0 0
5 4 0 0
6 4 0 0
tail(net)
links mutual indirect
9995 722 26 5300
9996 721 26 5282
9997 720 26 5266
9998 720 26 5261
9999 718 26 5227
10000 719 26 5244
We can visualize the convergence of the algorithm using
plot.ts(net)
Here is a tutorial vignette that explains some more detail
vignette