| homophily.re | R Documentation | 
homophily.re implements a Bayesian Probit estimator for network formation model with homophily. The model includes degree heterogeneity using random effects (see details).
homophily.re(
  network,
  formula,
  data,
  symmetry = FALSE,
  group.fe = FALSE,
  re.way = 1,
  init = list(),
  iteration = 1000,
  print = TRUE
)
network | 
 matrix or list of sub-matrix of social interactions containing 0 and 1, where links are represented by 1.  | 
formula | 
 an object of class formula: a symbolic description of the model. The   | 
data | 
 an optional data frame, list, or environment (or object coercible by as.data.frame to a data frame) containing the variables
in the model. If not found in data, the variables are taken from   | 
symmetry | 
 indicates whether the network model is symmetric (see details).  | 
group.fe | 
 indicates whether the model includes group fixed effects.  | 
re.way | 
 indicates whether it is a one-way or two-way random effect model. The expected value is 1 or 2 (see details).  | 
init | 
 (optional) list of starting values containing   | 
iteration | 
 the number of iterations to be performed.  | 
print | 
 boolean indicating if the estimation progression should be printed.  | 
Let p_{ij} be a probability for a link to go from the individual i to the individual j.
This probability is specified for two-way effect models (re.way = 2) as
p_{ij} = F(\mathbf{x}_{ij}'\beta + \mu_i + \nu_j),
where F is the cumulative of the standard normal distribution. Unobserved degree heterogeneity is captured by
\mu_i and \nu_j. The latter are treated as random effects (see homophily.fe for fixed effect models).
For one-way random effect models (re.way = 1), \nu_j = \mu_j. For symmetric models, the network is not directed and the
random effects need to be one way.
A list consisting of:
model.info | 
 list of model information, such as the type of random effects, whether the model is symmetric, number of observations, etc.  | 
posterior | 
 list of simulations from the posterior distribution.  | 
init | 
 returned list of starting values.  | 
homophily.fe.
set.seed(1234)
library(MASS)
M            <- 4 # Number of sub-groups
nvec         <- round(runif(M, 100, 500))
beta         <- c(.1, -.1)
Glist        <- list()
dX           <- matrix(0, 0, 2)
mu           <- list()
nu           <- list()
cst          <- runif(M, -1.5, 0)
smu2         <- 0.2
snu2         <- 0.2
rho          <- 0.8
Smunu        <- matrix(c(smu2, rho*sqrt(smu2*snu2), rho*sqrt(smu2*snu2), snu2), 2)
for (m in 1:M) {
  n          <- nvec[m]
  tmp        <- mvrnorm(n, c(0, 0), Smunu)
  mum        <- tmp[,1] - mean(tmp[,1])
  num        <- tmp[,2] - mean(tmp[,2])
  X1         <- rnorm(n, 0, 1)
  X2         <- rbinom(n, 1, 0.2)
  Z1         <- matrix(0, n, n)  
  Z2         <- matrix(0, n, n)
  
  for (i in 1:n) {
    for (j in 1:n) {
      Z1[i, j] <- abs(X1[i] - X1[j])
      Z2[i, j] <- 1*(X2[i] == X2[j])
    }
  }
  
  Gm           <- 1*((cst[m] + Z1*beta[1] + Z2*beta[2] +
                       kronecker(mum, t(num), "+") + rnorm(n^2)) > 0)
  diag(Gm)     <- 0
  diag(Z1)     <- NA
  diag(Z2)     <- NA
  Z1           <- Z1[!is.na(Z1)]
  Z2           <- Z2[!is.na(Z2)]
  
  dX           <- rbind(dX, cbind(Z1, Z2))
  Glist[[m]]   <- Gm
  mu[[m]]      <- mum
  nu[[m]]      <- num
}
mu  <- unlist(mu)
nu  <- unlist(nu)
out   <- homophily.re(network =  Glist, formula = ~ dX, group.fe = TRUE, 
                      re.way = 2, iteration = 1e3)
# plot simulations
plot(out$posterior$beta[,1], type = "l")
abline(h = cst[1], col = "red")
plot(out$posterior$beta[,2], type = "l")
abline(h = cst[2], col = "red")
plot(out$posterior$beta[,3], type = "l")
abline(h = cst[3], col = "red")
plot(out$posterior$beta[,4], type = "l")
abline(h = cst[4], col = "red")
plot(out$posterior$beta[,5], type = "l")
abline(h = beta[1], col = "red")
plot(out$posterior$beta[,6], type = "l")
abline(h = beta[2], col = "red")
plot(out$posterior$sigma2_mu, type = "l")
abline(h = smu2, col = "red")
plot(out$posterior$sigma2_nu, type = "l")
abline(h = snu2, col = "red")
plot(out$posterior$rho, type = "l")
abline(h = rho, col = "red")
i <- 10
plot(out$posterior$mu[,i], type = "l")
abline(h = mu[i], col = "red")
plot(out$posterior$nu[,i], type = "l")
abline(h = nu[i], col = "red")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.