homophily {CDatanet} R Documentation

## Estimate Network Formation Model with Degree Heterogeneity as Random Effects

### Description

homophily implements a Bayesian estimator for network formation model with homophily. The model includes degree heterogeneity as random effects (see details).

### Usage

homophily(
network,
formula,
data,
fixed.effects = FALSE,
init = list(),
iteration = 1000,
print = TRUE
)


### Arguments

 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 formula should be as for example ~ x1 + x2 where x1, x2 are explanatory variable of links formation 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 environment(formula), typically the environment from which homophily is called. fixed.effects boolean indicating if sub-network heterogeneity as fixed effects should be included. init (optional) list of starting values containing beta, an K-dimensional vector of the explanatory variables parameter, mu an n-dimensional vector, and nu an n-dimensional vector, smu2 the variance of mu, and snu2 the variance of nu, where K is the number of explanatory variables and n is the number of individuals. iteration the number of iterations to be performed. print boolean indicating if the estimation progression should be printed.

### Details

Let p_{ij} be a probability for a link to go from the individual i to the individual j. This probability is specified as

p_{ij} = F(\mathbf{x}_{ij}'\beta + \mu_j + \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.

### Value

A list consisting of:

 n number of individuals in each network. n.obs number of observations. n.links number of links. K number of explanatory variables. posterior list of simulations from the posterior distribution. iteration number of performed iterations. init returned list of starting values.

homophily.FE.

### Examples


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(network =  Glist, formula = ~ dX, fixed.effects = TRUE,
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")



[Package CDatanet version 2.1.2 Index]