# create two very small networks with covariates for illustrative purposes
Y1 <- matrix(c( 0,1,1,1,1,1,1,1,1,0,
1,0,1,0,1,1,1,1,1,1,
1,1,0,0,1,1,1,1,0,1,
1,0,0,0,1,0,0,1,0,0,
1,1,1,1,0,1,1,0,1,1,
1,1,1,0,1,0,1,0,1,1,
1,1,1,0,1,1,0,1,1,1,
1,1,1,1,0,0,1,0,0,1,
1,1,0,0,1,1,1,0,0,1,
0,1,1,0,1,1,1,1,1,0), ncol=10)
Y2 <- matrix(c( 0,0,1,0,1,1,0,1,0,0,
0,0,0,0,0,0,0,1,1,0,
1,0,0,1,0,1,0,1,0,0,
0,0,1,0,0,0,1,1,0,0,
1,0,0,0,0,0,1,1,0,0,
1,0,1,0,0,0,1,1,0,0,
0,0,0,1,1,1,0,1,0,0,
1,1,1,1,1,1,1,0,0,1,
0,1,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,1,0,0), ncol=10)
Y <- list(Y1, Y2)
Aa1 <- c(1,0,1,0,1,1,0,1,0,1)
Aa2 <- c(1,0,0,1,0,0,1,1,0,1)
Aa <- list(Aa1, Aa2)
Aat <- do.call(plyr::rbind.fill.matrix, Aa)
Ab1 <- c(0,0,0,0,0,0,0,0,0,0)
Ab2 <- c(1,1,1,1,1,1,1,1,1,1)
Ab <- list(Ab1, Ab2)
Abt <- do.call(plyr::rbind.fill.matrix, Ab)
Da1 <- abs(matrix(rep(Aa1,10), byrow = FALSE, ncol= 10) -
matrix(rep(Aa1,10), byrow = TRUE, ncol= 10))
Da2 <- abs(matrix(rep(Aa2,10), byrow = FALSE, ncol= 10) -
matrix(rep(Aa2,10), byrow = TRUE, ncol= 10))
Da <- list(Da1, Da2)
Dat <- do.call(plyr::rbind.fill.matrix, Da)
# estimate b2 model for two networks
M1 <- b2ML(Y,actor= ~ Aat + Abt, density = ~ Dat, adapt = 10, burnin = 100, densVar = FALSE)
summary(M1)
# Notice: burn-in, and number of adaptive sequenses are
# much smaller than recommended to keep computation time low.
# recommended code:
if (FALSE) {
M1 <- b2ML(Y,actor= ~ Aat + Abt, density = ~ Dat, densVar = FALSE)
summary(M1)
}
# estimate b2 model for a single network
M2 <- b2ML(list(Y[[1]]),actor= ~ Aat[1:10,], density = ~ Dat[1:10,], adapt = 10, burnin = 100,
densVar = FALSE)
summary(M2)
# Notice: burn-in, and number of adaptive sequenses are
# much smaller than recommended to keep computation time low.
# recommended code:
if (FALSE) {
M2 <- b2ML(list(Y[[1]]),actor= ~ Aat[1:10,], density = ~ Dat[1:10,], densVar = FALSE)
summary(M2)
}
Run the code above in your browser using DataLab