Reputation: 89
I am using package marginaleffects
in R to get confidence intervals for my predictions of a marginal effect. However, I did some calculations by hand and some of the confidence intervals I am getting with marginaleffects::predictions
seem too large. Am I missing something on how these confidence intervals are calculated or is there something weird going on?
I have the following regression model: Y = b_1 endogenous + b_2 endogenous^2 + b_3 controls + error
Because I have endogenous variables, I employ instrument. In terms of code, I use package fixest
to estimate the model below:
model <- feols(outcome ~ control1 + control2 + control3 + control4 |
fixed_effect1 + fixed_effect2 |
endogenous + I(endogenous^2) ~ instrument + I(instrument^2) ,
data = dataset, se = "cluster", cluster = "cluster_id")
Variable | Estimate | Std. Error |
---|---|---|
fit_endogenous | -0.041626570 | 0.156600333 |
fit_I(endogenous^2) | 0.037313536 | 0.264656733 |
control1 | 0.003302789 | 0.001053634 |
control2 | -0.004176099 | 0.003436881 |
control3 | 0.000320232 | 0.000164557 |
control4 | -0.000000270 | 0.000000127 |
Since I am interested in the marginal effect of endogenous, I think I can calculate it by (referring to endogenous by X now): Var(b_1+2Xb_2|X) = Var(b_1) + 4X^2 Var(b_2) + 4X Cov(b_1,b_2|X), which simplifies to Var(b_1+2Xb_2|X) = Var(b_1) when X=0.
Given the values above and taking advantage of the fact that Cov(b_1,b_2|X) <= se_b_1 * se_b_2 , where se_b_1 and se_b_2 are the standard deviations of b_1 and b_2, respectively; I can bound the maximum value of Var(b_1+2Xb_2|X). In particular, for X=0, Var(b_1+2Xb_2|X) = Var(b_1) = 0.156600333^2, which implies that a 95% confidence interval around the marginal effect at 0 should have width 21.960.156600333 = 0.6138733.
When I run marginaleffects::predictions(model, newdata = datagrid(endogenous = c(0, 1)))
I get the following output.
radius_500m | Estimate | Std. Error | CI 2.5 % | CI 97.5 % |
---|---|---|---|---|
0 | 9.04 | 0.165 | 8.71 | 9.36 |
1 | 9.03 | 0.203 | 8.64 | 9.43 |
which implies that the width of the 95% confidence interval at X=0 is 9.36-8.71=0.65, which is larger than the 0.6138733 I calculated previously.
What could be causing this? Thanks for your help!
Upvotes: 0
Views: 41