# create a very small network with covariates for illustrative purposes
S <- c(1,0,1,0,1,1,0,1,0,1)
REC <- (S*-1)+1
D1 <- matrix(c(0,1,0,1,0,1,0,1,0,1,
0,0,0,1,0,1,0,1,0,1,
1,1,0,0,1,0,0,0,0,0,
1,1,1,0,1,0,0,0,0,1,
1,0,1,0,0,1,1,0,1,0,
0,0,0,0,0,0,1,1,1,1,
0,0,0,0,0,1,0,1,0,1,
1,0,0,0,0,1,1,0,1,1,
0,1,0,1,0,1,0,1,0,0,
1,0,1,1,1,0,0,0,0,0), ncol=10)
D2 <- abs(matrix(rep(S,10), byrow = FALSE, ncol= 10) -
matrix(rep(REC,10), byrow = TRUE, ncol= 10))
R <- D1*t(D1)
Y <- matrix(c(0,1,1,1,1,1,0,0,1,1,
0,0,0,1,1,1,0,0,1,0,
1,1,0,1,1,1,0,0,1,1,
1,1,1,0,1,1,0,1,1,0,
1,1,1,1,0,1,1,0,1,1,
0,1,1,1,1,0,1,1,1,0,
1,0,1,0,1,1,0,1,0,1,
0,1,1,1,0,1,1,0,1,1,
1,0,1,0,1,0,1,1,0,1,
1,1,1,0,0,1,1,1,1,0), ncol=10)
# estimate p2 model
p2(Y,sender= ~ S, receiver = ~ REC, density = ~ D1 + D2, reciprocity= ~ R,
burnin = 100, sample = 400, adapt = 10)
# Notice: burn-in, sample size and number of adaptive sequenses are
# much smaller than recommended to keep computation time low.
# recommended code:
if (FALSE) {
p2(Y,sender= ~ S, receiver = ~ REC, density = ~ D1+ D2, reciprocity= ~ R)
}
Run the code above in your browser using DataLab