I am not sure here if I am doing something wrong or this is a bug in confint
function in R
itself but I am getting confidence intervals for regression estimate which don't contain the estimate.
Here is reprex
:
# model (converting all numeric columns in data to z-scores)
mod <-
stats::lm(
formula = cbind(mpg, disp) ~ wt,
data = purrr::modify_if(.x = mtcars, .p = is.numeric, .f = scale)
)
# tidy dataframe
broom::tidy(mod, conf.int = TRUE)
#> # A tibble: 4 x 8
#> response term estimate std.error statistic p.value conf.low conf.high
#> <chr> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
#> 1 mpg (Intercept) 8.05e-17 0.0893 9.01e-16 1.00e+ 0 -0.182 0.182
#> 2 mpg wt -8.68e- 1 0.0908 -9.56e+ 0 1.29e-10 -1.05 -0.682
#> 3 disp (Intercept) -1.70e-16 0.0826 -2.06e-15 1.00e+ 0 -0.182 0.182
#> 4 disp wt 8.88e- 1 0.0840 1.06e+ 1 1.22e-11 -1.05 -0.682
confint(mod)
#> 2.5 % 97.5 %
#> :(Intercept) -0.1824544 0.1824544
#> :wt -1.0530332 -0.6822855
#> :(Intercept) -0.1824544 0.1824544
#> :wt -1.0530332 -0.6822855
This becomes more conspicuous if you plot the estimates:
Am I doing something wrong here? Or this is expected behavior?