sim.IV: Instrument Variables for SAR model

View source: R/simIV.R

sim.IVR Documentation

Instrument Variables for SAR model

Description

sim.IV generates Instrument Variables (IV) for linear-in-mean SAR models using only the distribution of the network. See Propositions 1 and 2 of Boucher and Houndetoungan (2020).

Usage

sim.IV(
  dnetwork,
  X,
  y = NULL,
  replication = 1L,
  power = 1L,
  exp.network = FALSE
)

Arguments

dnetwork

network matrix of list of sub-network matrices, where the (i, j)-th position is the probability that i be connected to j.

X

matrix of the individual observable characteristics.

y

(optional) the endogenous variable as a vector.

replication

(optional, default = 1) is the number of repetitions (see details).

power

(optional, default = 1) is the number of powers of the interaction matrix used to generate the instruments (see details).

exp.network

(optional, default = FALSE) indicates if simulated network should be exported.

Details

Bramoulle et al. (2009) show that one can use GX, G^2X, ..., G^P X as instruments for Gy, where P is the maximal power desired. sim.IV generate approximation of those instruments, based on Propositions 1 and 2 in Boucher and Houndetoungan (2020) (see also below). The argument power is the maximal power desired.
When Gy and the instruments GX, G^2X, ..., G^P X are not observed, Boucher and Houndetoungan (2022) show that we can use one drawn from the distribution of the network in order to approximate Gy, but that the same draw should not be used to approximate the instruments. Thus, each component in the function's output gives G1y and G1X computed with the same network and G2X computed with another network, which can be used in order to approximate the instruments. This process can be replicated several times and the argument replication can be used to set the number of replications desired.

Value

list of replication components. Each component is a list containing G1y (if the argument y was provided), G1 (if exp.network = TRUE), G2 (if exp.network = TRUE) , G1X, and G2X where G1 and G2 are independent draws of network from the distribution (see details).

G1y

is an approximation of Gy.

G1X

is an approximation of G^pX with the same network draw as that used in G1y. G1X is an array of dimension N \times K \times power, where K is the number of column in X. For any p \in \{1, 2, ..., power\}, the approximation of G^pX is given by G1X[,,p].

G2X

is an approximation of G^pX with a different different network. G2X is an array of dimension N \times K \times power. For any p \in \{1, 2, ..., power\}, the approximation of G^pX is given by G2X[,,p].

See Also

mcmcSAR

Examples


library(AER)
# Number of groups
M             <- 30
# size of each group
N             <- rep(50,M)
# individual effects
beta          <- c(2,1,1.5) 
# endogenous effects
alpha         <- 0.4
# std-dev errors
se            <- 2 
# prior distribution
prior         <- runif(sum(N*(N-1)))
prior         <- vec.to.mat(prior, N, normalise = FALSE)
# covariates
X             <- cbind(rnorm(sum(N),0,5),rpois(sum(N),7))
# true network
G0            <- sim.network(prior)
# normalise 
G0norm        <- norm.network(G0)
# simulate dependent variable use an external package
y             <- CDatanet::simsar(~ X, contextual = FALSE, Glist = G0norm, 
                                     theta = c(alpha, beta, se))
y             <- y$y
# generate instruments 
instr         <- sim.IV(prior, X, y, replication = 1, power = 1)

GY1c1         <- instr[[1]]$G1y       # proxy for Gy (draw 1)
GXc1          <- instr[[1]]$G1X[,,1]  # proxy for GX (draw 1)
GXc2          <- instr[[1]]$G2X[,,1]  # proxy for GX (draw 2)
# build dataset
# keep only instrument constructed using a different draw than the one used to proxy Gy
dataset           <- as.data.frame(cbind(y, X, GY1c1, GXc1, GXc2)) 
colnames(dataset) <- c("y","X1","X2","G1y", "G1X1", "G1X2", "G2X1", "G2X2") 

# Same draws
out.iv1           <- ivreg(y ~ X1 + X2 + G1y | X1 + X2 + G1X1 + G1X2, data = dataset)
summary(out.iv1)

# Different draws
out.iv2           <- ivreg(y ~ X1 + X2 + G1y | X1 + X2 + G2X1 + G2X2, data = dataset)
summary(out.iv2)


ahoundetoungan/PartialNetwork documentation built on March 15, 2024, 4:35 p.m.