Learn R Programming

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. (2021). ivmodel: An R Package for Inference and Sensitivity Analysis of Instrumental Variables Models with One Endogenous Variable. Observational Studies. 7:1-24.

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

554

Version

1.9.1

License

GPL-2 | file LICENSE

Maintainer

Last Published

April 9th, 2023

Functions in ivmodel (1.9.1)

card.data

Card (1995) Data
coef.ivmodel

Coefficients of the Fitted Model in the ivmodel Object
coefOther

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

Sample Size Calculator for the Power of Asymptotic T-test
confint.ivmodel

Confidence Intervals for the Fitted Model in ivmodel Object
TSLS.power

Power of TSLS Estimator
balanceLovePlot

Create Love plot of standardized covariate mean differences
LIML

Limited Information Maximum Likelihood Ratio (LIML) Estimator
KClass

k-Class Estimator
biasLovePlot

Create Love plot of treatment bias and instrument bias
ivmodel-internal

Internal ivmodel functions
iv.diagnosis

Diagnostics of instrumental variable analysis
getStandardizedCovMeanDiffs

Get Standardized Covariate Mean Differences
getMD

Get Mahalanobis Distance
getCovMeanDiffs

Get Covariate Mean Differences
distributionBalancePlot

Plot randomization distributions of the Mahalanobis distance
ivmodel-bransonKeele-internal

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

Extract Model Fitted values in the ivmodel Object
permTest.absBias

Perform a permutation test using the sum of absolute biases
residuals.ivmodel

Residuals from the Fitted Model in the ivmodel Object
ivmodel-package

tools:::Rd_package_title("ivmodel")
para

Parameter Estimation from Ivmodel
model.matrix.ivmodel

Extract Design Matrix for ivmodel Object
vcovOther

Variance of Exogenous Coefficients of the Fitted Model in the ivmodel Object
permTest.md

Perform a permutation test using the Mahalanobis distance
icu.data

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

Fitting Instrumental Variables (IV) Models
ivmodel

Fitting Instrumental Variables (IV) Models
vcov.ivmodel

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

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

Anderson-Rubin (1949) Test
CLR

Conditional Likelihood Ratio Test
IVpower

Power calculation for IV models
AR.power

Power of the Anderson-Rubin (1949) Test
ARsens.test

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

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

Fuller-k Estimator
ARsens.power

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

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