coefplot: confidence interval doesn't overlap with 0, but it should!?

Hello! This is my first post. I have a question about coefplot. I was doing something for fun, for a fantasy league I'm doing with some friends, and I noticed an odd behavior in coefplot, which concerns me also (especially!) for more serious applications.

I showing all my code below:

# Create data 
df <- data.frame(team = c("team_1", "team_2", "team_3", "team_4",
                          "team_5", "team_6", "team_7", "team_8"),
                 goals_scored = c(29, 26, 23, 20, 24, 24, 20, 16),
                 goals_conceded = c(17, 18, 16, 23, 22, 27, 26, 33),
                 points = c(18, 17, 17, 11, 10, 10, 7, 7)
                 )
print(df)

# Estimate model
mymodel <- lm(points ~ goals_scored + goals_conceded, data = df)

# Model summary
summary(mymodel)
# Coefficients:
#               Estimate   Std. Error t value  Pr(>|t|)  
# (Intercept)     20.3709    12.1361   1.679   0.1541  
# goals_scored     0.2242     0.3324   0.675   0.5299  
# goals_conceded  -0.5867     0.2308  -2.542   0.0517 .
# ---
#   Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

# Compute confidence intervals
confint(mymodel)
#                      2.5 %         97.5 %
# goals_conceded  -1.1798760    0.006525498

# Import ggplot2 and coefplot libraries
library(ggplot2)
library(coefplot)

# Create coefplot 
coefplot(mymodel, 
         intercept = FALSE, # hide intercept 
         innerCI = 1.645, # SD = 1.645 for inner CI = 90% sig 
         outerCI = 1.96) # SD = 1.96 for outer CI = 95% sig

# Default coefplot: inner CI = 1 SD; outer CI = 2 SD
coefplot(mymodel, 
         intercept = FALSE) # hide intercept 

Basically, I'm predicting points using goals scored and conceded. As you see, goals_conceded is marginally significant (p=0.0517). Thus, I would expect its confidence interval to overlap with 0 both in the first plot and in the second (default) one. But that's not the case!? I'm attaching one plot as an example.

Am I missing something?

Thanks!

Here are some calculations that show where various numbers come from and why the results from lm() and confint() are different than the result from coefplot()

df <- data.frame(team = c("team_1", "team_2", "team_3", "team_4",
                          "team_5", "team_6", "team_7", "team_8"),
                 goals_scored = c(29, 26, 23, 20, 24, 24, 20, 16),
                 goals_conceded = c(17, 18, 16, 23, 22, 27, 26, 33),
                 points = c(18, 17, 17, 11, 10, 10, 7, 7)
)

# Estimate model
mymodel <- lm(points ~ goals_scored + goals_conceded, data = df)
summary(mymodel)
#> 
#> Call:
#> lm(formula = points ~ goals_scored + goals_conceded, data = df)
#> 
#> Residuals:
#>       1       2       3       4       5       6       7       8 
#>  1.1002  1.3596  0.8589 -0.3617 -2.8453  0.0881 -2.6017  2.4019 
#> 
#> Coefficients:
#>                Estimate Std. Error t value Pr(>|t|)  
#> (Intercept)     20.3709    12.1361   1.679   0.1541  
#> goals_scored     0.2242     0.3324   0.675   0.5299  
#> goals_conceded  -0.5867     0.2308  -2.542   0.0517 .
#> ---
#> Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#> 
#> Residual standard error: 2.217 on 5 degrees of freedom
#> Multiple R-squared:  0.8304, Adjusted R-squared:  0.7626 
#> F-statistic: 12.24 on 2 and 5 DF,  p-value: 0.01184

#p value of goals_conceded from t distribution
(1 - pt(q = 0.5867/0.2308, df = 5)) * 2
#> [1] 0.05176584

confint(mymodel) #notice goals_conceded includes zero within CI
#>                      2.5 %       97.5 %
#> (Intercept)    -10.8260050 51.567745690
#> goals_scored    -0.6302553  1.078694149
#> goals_conceded  -1.1798760  0.006525498

#Why is the 97.5% confint 0.0065 in the above output?
(0.0065 - (-0.5867) )/0.2308 #distance from Est value to 0.0065 scaled by Std Err
#> [1] 2.570191
pt(q = 2.5702, df = 5) #2.57 std errors is the 0.975 point of the t dist
#> [1] 0.9749884

#Your coefplot calculation uses a normal distribution, lighter tails than t dist.
pnorm(q = 1.96)
#> [1] 0.9750021

Created on 2023-11-13 with reprex v2.0.2

This topic was automatically closed 42 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.