simCDnet: Simulate data from Count Data Model with Social Interactions

Description Usage Arguments Details Value See Also Examples

View source: R/simCDnet.R

Description

Simulate data from Count Data Model with Social Interactions

Usage

1
simCDnet(formula, contextual, Glist, theta, tol = 1e-15, maxit = 500, data)

Arguments

formula

an object of class formula: a symbolic description of the model. The formula should be as for example y ~ x1 + x2 | x1 + x2 where y is the endogenous vector, the listed variables before the pipe, x1, x2 are the individual exogenous variables and the listed variables after the pipe, x1, x2 are the contextual observable variables. Other formulas may be y ~ x1 + x2 for the model without contextual effects, y ~ -1 + x1 + x2 | x1 + x2 for the model without intercept or y ~ x1 + x2 | x2 + x3 to allow the contextual variable to be different from the individual variables.

contextual

(optional) logical; if true, this means that all individual variables will be set as contextual variables. Set the formula as y ~ x1 + x2 and contextual as TRUE is equivalent to set the formula as y ~ x1 + x2 | x1 + x2.

Glist

the adjacency matrix or list sub-adjacency matrix.

theta

the parameter value as θ = (λ, β, γ, σ). The parameter γ should be removed if the model does not contain contextual effects (see details).

tol

the tolerance value used in the Fixed Point Iteration Method to compute the expectancy of y. The process stops if the L distance between two consecutive values of the expectancy of y is less than tol.

maxit

the maximal number of iterations in the Fixed Point Iteration Method.

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 mcmcARD is called.

Details

Following Houndetoungan (2020), the count data y is generated from a latent variable ys. The latent variable is given for all i as

ys_i = λ g_i*ybar + x_i'β + g_i*Xγ + ε_i,

where ε_i --> N(0, σ^2).
The count variable y_i is then define by the next (greater or equal) non negative integer to ys_i; that is y_i = 0 if ys_i ≤ 0 and y_i = q + 1 if q < ys_i ≤ q + 1, where q is a non-negative integer.

Value

A list consisting of:

yst

ys (see details), the latent variable.

y

the observed count data.

yb

ybar (see details), the expectation of y.

Gyb

the average of the expectation of y among friends.

iteration

number of iterations performed by sub-network in the Fixed Point Iteration Method.

See Also

CDnetNPL.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# Groups' size
M      <- 5 # Number of sub-groups
nvec   <- round(runif(M, 100, 1000))
n      <- sum(nvec)

# Parameters
lambda <- 0.4
beta   <- c(2, -1.9, 0.8)
gamma  <- c(1.5, -1.2)
sigma  <- 1.5
theta  <- c(lambda, beta, gamma, sigma)

# X
X      <- cbind(rnorm(n, 1, 1), rexp(n, 0.4))

# Network
Glist  <- list()

for (m in 1:M) {
  nm           <- nvec[m]
  Gm           <- matrix(0, nm, nm)
  max_d        <- 30
  for (i in 1:nm) {
    tmp        <- sample((1:nm)[-i], sample(0:max_d, 1))
    Gm[i, tmp] <- 1
  }
  rs           <- rowSums(Gm); rs[rs == 0] <- 1
  Gm           <- Gm/rs
  Glist[[m]]   <- Gm
}


# data
data    <- data.frame(x1 = X[,1], x2 =  X[,2])

rm(list = ls()[!(ls() %in% c("Glist", "data", "theta"))])

ytmp    <- simCDnet(formula = ~ x1 + x2 | x1 + x2, Glist = Glist, 
                    theta = theta, data = data)

y       <- ytmp$y

# plot histogram
hist(y, breaks = max(y))

CDatanet documentation built on Feb. 18, 2021, 1:07 a.m.