Learn R Programming

PartialNetwork (version 1.1.2)

simSAR: Simulating Linear Peer Effect Models

Description

simSAR simulates linear peer effect models.

Usage

simSAR(formula, Glist, parms, lambda, beta, epsilon, nthreads = 1, data)

Value

A list containing:

y

The simulated variable.

Gy

the average of y among friends.

Arguments

formula

An object of class formula: a symbolic description of the model. formula should be specified as, for example, ~ x1 + x2, where x1 and x2 are control variables, which can include contextual variables such as averages or quantiles among peers.

Glist

The adjacency matrix. For networks consisting of multiple subnets (e.g., schools), Glist must be a list of subnets, with the m-th element being an \(n_m \times n_m\) adjacency matrix, where \(n_m\) is the number of nodes in the m-th subnet.

parms

A vector defining the true values of \((\lambda', \beta')'\), where \(\lambda\) is the peer effect parameter and \(\beta\) is the parameter vector of control variables (including contextual variables if any). The parameters \(\lambda\) and \(\beta\) can also be specified separately using the arguments lambda, and beta.

lambda

The true value of the vector \(\lambda\).

beta

The true value of the vector \(\beta\).

epsilon

A vector of idiosyncratic error terms. If not specified, it will be simulated from a standard normal distribution.

nthreads

A strictly positive integer indicating the number of threads to use.

data

An optional data frame, list, or environment (or an object that can be coerced 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 simSAR is called.

See Also

smmSAR, mcmcSAR

Examples

Run this code
set.seed(123)
ngr  <- 50
nvec <- rep(30, ngr)
n    <- sum(nvec)
G    <- lapply(1:ngr, function(z){
  Gz <- matrix(rbinom(nvec[z]^2, 1, 0.3), nvec[z])
  diag(Gz) <- 0
  Gz/rowSums(Gz) # Row-normalized network
})
X    <- cbind(rnorm(n), rpois(n, 2))
l    <- 0.5
b    <- c(2, -0.5, 1)

out  <- simSAR(formula = ~ X, Glist = G, lambda = l, beta = b)
summary(out$y)

Run the code above in your browser using DataLab