Learn R Programming

⚠️There's a newer version (1.9.1) of this package.Take me there.

ivmodel

ivmodel is a comprehensive R package for linear instrumental variables analysis with one endogenous variable (e.g. confounded treatment/policy/intervention). The package can handle large data, data from matched sets, and is designed to be robust to many data types (or mixtures of data types). The package contains the usual instrumental variables methods, methods for weak instruments, sensitivity analysis, and power calculations. The package also contains diagnostic tools to assess assumptions underlying IV analyses. All the methods in the software are outlined in Kang, Jiang, Zhao, and Small (2020) and Branson and Keele (2020).

To install this package in R from GitHub, run the following commands:

install.packages("devtools")
library(devtools) 
install_github("hyunseungkang/ivmodel")

To install this package in R from CRAN, run the following command:

install.packages("ivmodel")

Examples

library(ivmodel)

### Use Card (1995) data to estimate the effect of education on log earnings ###
# n: sample size; L: # of IVs; p: # of covariates 
# Y: n by 1 vector of outcomes (must be continuous)
# D: n by 1 vector of treatments (continuous or discrete)
# Z: n by L vector of instruments (continuous or discrete)
# X: n by L vector of instruments (continuous or discrete)
data(card.data)

# One Instrument Anaylsis with Proximity to 4yr College as IV#
Y=card.data[,"lwage"]
D=card.data[,"educ"] 
Z=card.data[,"nearc4"]
Xname=c("exper", "expersq", "black", "south", "smsa", "reg661",
"reg662", "reg663", "reg664", "reg665", "reg666", "reg667",
"reg668", "smsa66")
X=card.data[,Xname]

# Run command #
card.model1IV = ivmodel(Y=Y,D=D,Z=Z,X=X)
card.model1IV

# Obtain estimates of exogenous covariates' effects on outcome under #
# different k-class estimatos                                        #
coefOther(card.model1IV)

# Multiple IV Analysis with Proximito to 2yr and 4yr Colleges as IVs#
Z = card.data[,c("nearc4","nearc2")]
card.model2IV = ivmodel(Y=Y,D=D,Z=Z,X=X)
card.model2IV

# Use the formula environment
X = as.matrix(X)
card.modelFormula = ivmodelFormula(Y ~ D + X | Z + X)
card.modelFormula

References

Card, D. (1995). "Using Geographic Variations in College Proximity to Estimate the Return to Schooling.” In LN Christofides, EK Grant, R Swidinsky (eds.), Aspects of Labor Market Behaviour: Essays in Honour of John Vanderkamp. University of Toronto Press.

Kang, H., Jiang, Y., Zhao, Q., and Small, D. S. (2020). ivmodel: An R Package for Inference and Sensitivity Analysis of Instrumental Variables Models with One Endogenous Variable. Technical Report.

Branson, Z., Keele, J. (2020). Evaluating A Key Instrumental Variable Assumption Using Randomization Tests. American Journal of Epidemiology.

Copy Link

Version

Install

install.packages('ivmodel')

Monthly Downloads

808

Version

1.9.0

License

GPL-2 | file LICENSE

Maintainer

Hyunseung Kang

Last Published

January 14th, 2021

Functions in ivmodel (1.9.0)

AR.test

Anderson-Rubin (1949) Test
IVpower

Power calculation for IV models
AR.power

Power of the Anderson-Rubin (1949) Test
AR.size

Sample Size Calculator for the Power of the Anderson-Rubin (1949) Test
IVsize

Calculating minimum sample size for achieving a certain power
ARsens.test

Sensitivity Analysis for the Anderson-Rubin (1949) Test
ARsens.power

Power of the Anderson-Rubin (1949) Test with Sensitivity Analysis
coefOther

Exogenous Coefficients of the Fitted Model in the ivmodel Object
ARsens.size

Sample Size Calculator for the Power of the Anderson-Rubin (1949) Test with Sensitivity Analysis
Fuller

Fuller-k Estimator
CLR

Conditional Likelihood Ratio Test
card.data

Card (1995) Data
coef.ivmodel

Coefficients of the Fitted Model in the ivmodel Object
getCovMeanDiffs

Get Covariate Mean Differences
biasLovePlot

Create Love plot of treatment bias and instrument bias
TSLS.size

Sample Size Calculator for the Power of Asymptotic T-test
TSLS.power

Power of TSLS Estimator
balanceLovePlot

Create Love plot of standardized covariate mean differences
KClass

k-Class Estimator
ivmodel-package

tools:::Rd_package_title("ivmodel")
ivmodel-internal

Internal ivmodel functions
vcovOther

Variance of Exogenous Coefficients of the Fitted Model in the ivmodel Object
confint.ivmodel

Confidence Intervals for the Fitted Model in ivmodel Object
LIML

Limited Information Maximum Likelihood Ratio (LIML) Estimator
iv.diagnosis

Diagnostics of instrumental variable analysis
icu.data

Pseudo-data based on Branson and Keele (2020)
getStandardizedCovMeanDiffs

Get Standardized Covariate Mean Differences
distributionBalancePlot

Plot randomization distributions of the Mahalanobis distance
ivmodel

Fitting Instrumental Variables (IV) Models
residuals.ivmodel

Residuals from the Fitted Model in the ivmodel Object
ivmodelFormula

Fitting Instrumental Variables (IV) Models
vcov.ivmodel

Calculate Variance-Covariance Matrix (i.e. Standard Error) for k-Class Estimators in the ivmodel Object
ivmodel-bransonKeele-internal

Internal ivmodel functions for Branson and Keele (2020)
fitted.ivmodel

Extract Model Fitted values in the ivmodel Object
model.matrix.ivmodel

Extract Design Matrix for ivmodel Object
para

Parameter Estimation from Ivmodel
getMD

Get Mahalanobis Distance
permTest.md

Perform a permutation test using the Mahalanobis distance
permTest.absBias

Perform a permutation test using the sum of absolute biases