This package provides inference with control function methods for nonlinear outcome models when the model is known and when unknwon but semiparametric, using the Control Function method and the SpotIV method.
The package can be installed from Github using the following code:
devtools::install_github("https://github.com/zijguo/controlfunctionIV")Before using the package, we can use the following code:
library(controlfunctionIV)We use pseudodata provided by Youjin Lee, which is generated mimicing the structure of Framingham Heart Study data.
In this section, we consider the following linear models.
Y = D\beta_1 + D^2\beta_2+ + X\phi +u
D = Z\gamma_1 + Z^2\gamma_2 + X\psi + v
We use the control function method in additive model with continuous outcome and valid IVs.
> data("nonlineardata")
> Y <- log(nonlineardata[,"insulin"])
> D <- nonlineardata[,"bmi"]
> Z <- as.matrix(nonlineardata[,c("Z.1","Z.2","Z.3","Z.4")])
> X <- as.matrix(nonlineardata[,c("age","sex")])
> cf.model <- cf(Y~D+I(D^2)+X|Z+I(Z^2)+X)
> summary(cf.model)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
Coefficients of Control Function Estimators:
Estimate Std.Err t value Pr(>|t|)
(Intercept) 2.6989725 0.4869839 5.542 1.60e-08 ***
D 0.0664743 0.0213217 3.118 0.000918 ***
I(D^2) -0.0008357 0.0001495 5.589 1.22e-08 ***
Xage 0.0057497 0.0019598 2.934 0.001684 **
Xsex -0.1149052 0.0366660 3.134 0.000869 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
The estimate causal effect when changing treatment from 25.98786 to 26.98786 : 0.02220005
Standard error of the estimate of the causal effect: 0.01955523
95% confidence interval for the causal effect: [-0.01612749,0.06052759]This function implements the pretest estimator by comparing the control function and the TSLS estimators via checking the extra IV generated by the control function is valid or not.
> pretest.model <- pretest(Y~D+I(D^2)+X|Z+I(Z^2)+X)
> summary(pretest.model)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
Hausman Statistic : 0.6714285
P value = 0.412554
H0 : Augmented instrumental variables from Control function are valid, is not rejected.
Level 0.05 Pretest estimator is Control function estimator.
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
Coefficients of Pretest Estimators:
Estimate Std.Err t value Pr(>|t|)
(Intercept) 2.6989725 0.4869839 5.542 1.60e-08 ***
D 0.0664743 0.0213217 3.118 0.000918 ***
I(D^2) -0.0008357 0.0001495 5.589 1.22e-08 ***
Xage 0.0057497 0.0019598 2.934 0.001684 **
Xsex -0.1149052 0.0366660 3.134 0.000869 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1Guo, Z. and D. S. Small (2016), Control function instrumental variable estimation of nonlinear causal effect models, The Journal of Machine Learning Research 17(1), 3448–3482.
SpotIV performs causal inference in the semi-parametric outcome model with possibly invalid IVs and Probitcontrol assumes the outcome model is a probit model.
> Y <- nonlineardata[,"CVD"]
> D <- nonlineardata[,"bmi"]
> Z <- as.matrix(nonlineardata[,c("Z.1","Z.2","Z.3","Z.4")])
> X <- as.matrix(nonlineardata[,c("age","sex")])
> d1 <- median(D)+1
> d2 <- median(D)
> w0 <- c(rep(0,4), 30, 1)
> SpotIV.model <- SpotIV(Y,D,Z,X,invalid = TRUE,d1 =d1, d2 = d2,w0 = w0)
> summary(SpotIV.model)
Relevant Instruments: Z.3
Valid Instruments: Z.3
Thus, Majority rule holds.
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
BetaHat: -0.6168097
CATEHat: -0.007856555
Standard error of CATEHat: 0.06534695
95% Confidence Interval for CATE: [-0.1359342,0.1202211]> Probit.model <- ProbitControl(Y,D,Z,X,invalid = TRUE,d1 =d1, d2 = d2,w0 = w0)
> summary(Probit.model)
Relevant Instruments: Z.3
Valid Instruments: Z.3
Thus, Majority rule holds.
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
BetaHat: -0.1948686
Standard error of BetaHat: 0.8833127
95% Confidence Interval for Beta: [-1.92613,1.536393]
CATEHat: -0.009956242
Standard error of CATEHat: 0.02975247
95% Confidence Interval for CATE: [-0.06827001,0.04835752]Li, S., Guo, Z. (2020), Causal Inference for Nonlinear Outcome Models with Possibly Invalid Instrumental Variables, Preprint arXiv:2010.09922.