boostmed
packgeFirst, we will install from the .tar file and load the
package.
library(boostmed)
There are two data frames in the file for testing the functions. Let’s start with the sensitivity analysis.
data("AR_data")
head(AR_data)
The sensitivity analysis is done by the function
causal_med_sen. Please see the help file for more details.
It outputs three things:
causal_med_sen(AR_data,
x = "ar_condition",
m = "fit_uncertainty",
y = "return")
## $acme_no_bias
## acme_no_bias lb 95% CI ub 95% CI
## -1.1474140 -2.0204030 -0.4561891
##
## $critical_rho
## [1] 0.247
##
## $acme_critical_bias
## acme_critical_bias lb 95% CI ub 95% CI
## -0.555995543 -1.248215142 0.001679047
Next, let’s try the constructed IV estimation. The function to use is
causal_med_civ. We will use it with a simulated data.
data("civ_example_data")
head(civ_example_data)
The constructed IV estimation is done by the function
causal_med_civ. The flow of the function is like this:
causal_med_civ(civ_example_data,
x = "D",
m = "M",
y = "Y")
## $strength_of_constructed_IV
## Chi-square Stats P-value
## 432.7623 0.0000
##
## $exogeneity_of_constructed_IV
## Chi-square Stats P-value
## 0.03431541 0.98298865
##
## $acme_IV
## acme_constructed_IV lb 95% CI ub 95% CI
## 0.5271170 0.4604242 0.5972552
The results show that the constructed IV is strong and also we cannot reject the null of homoskedasticity which implies the exogneity of the IV. The final output shows the estimated ACME and bootstrapped 95% CI.
If we try this function on the AR_data, we get an error
message as the IV is too weak. Using a weak instrument may not correct
the bias but increase the variance of estimation.
causal_med_civ(AR_data,
x = "ar_condition",
m = "fit_uncertainty",
y = "return")
## [1] "Breusch-Pagan Test for M~D residuals:"
## Chi-square Stats P-value
## 0.6439754 0.4222749
## Error in causal_med_civ(AR_data, x = "ar_condition", m = "fit_uncertainty", : The constructed instrument is too weak!