j2ML: MCMC estimates for the (multilevel) j2 model

j2MLR Documentation

MCMC estimates for the (multilevel) j2 model

Description

Estimates the (multilevel) j2 model parameters, as described in Zijlstra (2017) <doi:10.1080/0022250X.2017.1387858>.

Usage

j2ML(nets, sender = NULL, receiver = NULL, density =~ 1, reciprocity =~ 1, 
adapt = NULL, burnin = NULL, center = NULL, separateSigma= NULL, seed = NULL, 
densVar = NULL, recVar = NULL) 

Arguments

nets

List with n dichotomous dependent directed networks.

sender

Optional matrix with a stacked actor-level sender covariate, corresponding to the n networks. Multiple sender covariates can be added as a formula object, see example below

receiver

Optional matrix with a stacked actor-level receiver covariate, corresponding to the n networks. Multiple receiver covariates can be added as a formula object

density

Optional stacked matrix with a density covariate, with dimensions similar to the n dependent networks. Multiple density covariates can be added as a formula object, see example below

reciprocity

Optional stacked matrix with a symmetric reciprocity covariate, with dimensions similar to the n dependent networks. Multiple reciprocity covariates can be added as a formula object

adapt

Optional minumum effective sample size to be reached for the model parameters before ending MCMC simulations (default is 300 for the total sample, including burn-in).

burnin

Optional specification of number of burn-in iterations (default is 2500).

center

Optional argument for centering predictors (default is TRUE).

separateSigma

Optional argument for estimating separate variance-covariance matrices for the random sender and receiver effects in the dependent networks (default is FALSE).

seed

Optional specification of random seed (delfault is 1).

densVar

Optional argument for estimating density variance at the network level instead of separate density effects (default is TRUE).

recVar

Optional argument for estimating reciprocity variance at the network level instead of separate reciprocity effects (default is TRUE).

Value

Returns a fitted model of class 2ML, to be opened with the function summary().

Author(s)

Bonne J.H. Zijlstra b.j.h.zijlstra@uva.nl

References

Zijlstra, B.J.H. (2017). Regression of directed graphs on independent effects for density and reciprocity. The Journal of Mathematical Sociology 41 (4).

Examples


# create two very small networks with covariates for illustrative purposes
Y1 <- matrix(c(0,1,0,1,0,1,0,1,0,0,
               0,0,1,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,1,
               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,
               0,0,1,1,1,0,0,0,0,0), ncol=10)
Y2 <- matrix(c(0,0,1,0,1,0,0,1,0,0,
               0,0,0,0,0,0,0,1,1,0,
               0,0,0,1,0,1,0,1,0,1,
               0,0,1,0,0,0,1,1,0,0,
               1,0,0,1,0,0,1,0,0,1,
               0,0,1,0,0,0,1,1,0,0,
               0,1,0,0,1,0,0,0,0,0,
               1,0,1,0,1,1,1,0,0,1,
               0,1,0,1,0,0,0,0,0,0,
               0,1,0,1,0,0,0,1,0,0), ncol=10) 
Y <- list(Y1, Y2)                
Sa1 <- c(1,0,1,0,1,1,0,1,0,1)
Sa2 <- c(1,0,0,1,0,0,1,1,0,1)
Sa <- list(Sa1, Sa2)
Sat <- Rat <-  do.call(plyr::rbind.fill.matrix, Sa)
Sb1 <- c(0,1,1,0,1,0,1,0,1,0)
Sb2 <- c(1,0,1,0,0,1,0,1,0,1)
Sb <- list(Sb1, Sb2)
Sbt <- do.call(plyr::rbind.fill.matrix, Sb)
Da1 <- abs(matrix(rep(Sa1,10), byrow = FALSE, ncol= 10) -
              matrix(rep(Sa1,10), byrow = TRUE, ncol= 10))
Da2 <- abs(matrix(rep(Sa2,10), byrow = FALSE, ncol= 10) -
              matrix(rep(Sa2,10), byrow = TRUE, ncol= 10))
Da <- list(Da1, Da2)
Dat <- do.call(plyr::rbind.fill.matrix, Da)

# estimate j2 model for two networks
M1 <- j2ML(Y,sender= ~ Sat + Sbt, receiver= ~ Rat, density = ~ Dat, adapt = 10, burnin = 100)
summary(M1)
# Notice: burn-in, and number of adaptive sequenses are 
# much smaller than recommended to keep computation time low.
# recommended code: 

   M1 <- j2ML(Y,sender= ~ Sat + Sbt, receiver= ~ Rat, density = ~ Dat, separateSigma = FALSE)
summary(M1)


# estimate j2 model for a single network
M2 <- j2ML(list(Y[[1]]), sender= ~ Sat[1:10,] + Sbt[1:10,], receiver= ~ Rat[1:10,], 
density = ~ Dat[1:10,], adapt = 10, burnin = 100)
summary(M2)
# Notice: burn-in, and number of adaptive sequenses are 
# much smaller than recommended to keep computation time low.
# recommended code: 

   M2 <- j2ML(list(Y[[1]]),sender= ~ Sat[1:10,] + Sbt[1:10,], receiver= ~ Rat[1:10,], 
   density = ~ Dat[1:10,])
summary(M2)


dyads documentation built on Sept. 18, 2026, 5:08 p.m.