README.md

CIIV

CIIV is a set of functions to implement the Confidence Interval method, which is to select the valid instrumental variables from a set of potential instruments that may contain invalid ones in linear models. It also provides post-selection IV estimation for the causal effect of the treatment/exposure on the outcome. The method in these R functions is based on the paper The Confidence Interval Method for Selecting Valid Instrumental Variables (Windmeijer, Liang, Hartwig, Bowden, 2020).

Installation

source("https://raw.githubusercontent.com/xlbristol/CIIV/main/R/CIIV_Functions.R")

Input and Output of CIIV Functions

## Working Example

# Load CIIV Functions
source("https://raw.githubusercontent.com/xlbristol/CIIV/main/R/CIIV_Functions.R")

# Load Dependent R Packages
library(AER)
library(sandwich)
library(MASS) ## The MASS package is only needed to run the working example.

# Generate Data
n = 2000; L = 10; s = 3
pi = c(rep(3,s),rep(0,L-s)); beta = 1; gamma = c(0, rep(1,(L-2)), 0)
epsilonSigma = matrix(c(1,0.8,0.8,1),2,2)
epsilon = mvrnorm(n,rep(0,2),epsilonSigma)
Z = matrix(rnorm(n*L),n,L)
D = 0.5 + Z %*% gamma + epsilon[,1]
Y = -0.5 + Z %*% pi + D * beta + epsilon[,2]

result = CIIV(Y,D,Z,robust=FALSE, firststage=TRUE)
result


xlbristol/CIIV documentation built on Oct. 30, 2022, 10:17 p.m.