-2

I have three variables and each one has a confidence interval, as follow

variable lowerci beta upperci
a 0.86471152    0.87615515 0.88759878
b 0.966626566 0.970159119 0.973691671
c 0.94946211 0.955502661 0.961543211

I want to see if they overlap (clearly they don't, but I want the graph).

How can I do this in R?

Rui Barradas
  • 70,273
  • 8
  • 34
  • 66
  • 4
    What have you tried so far? You say you "want the graph," but we don't know what this graph is. – camille Mar 03 '19 at 19:23
  • 5
    Side note: I'm guessing you want to see if they overlap to determine something about what a significance test might look like? That's not really appropriate to do - intervals can overlap and the test for a difference could still be significant. – Dason Mar 03 '19 at 19:34
  • The question is still unclear? Do you want to check for overlapping of confidence intervals values for each variable or across variables? – Lunalo John Mar 03 '19 at 19:36
  • Maybe [this](https://stackoverflow.com/questions/19599957/plotting-confidence-intervals-in-ggplot) is what you want. – Rui Barradas Mar 03 '19 at 19:39
  • @Dason Actually yes, I'd like to see if the difference between each variable is significant. Can you please recommend something else? –  Mar 03 '19 at 19:48
  • @RuiBarradas It is, sort of. Thanks for the reference –  Mar 03 '19 at 19:51
  • 2
    @NewToR - Just do the test of if the difference is significant directly. Or make confidence intervals for the difference directly. You could use those CIs and compare and see if 0 is in the bounds of the CI to determine if the difference is significant. But comparing endpoints of different confidence intervals is not an appropriate method to determine if a difference is significant. – Dason Mar 03 '19 at 19:53

2 Answers2

1

If all you want is a graph of the confidence intervals, try the following.

library(ggplot2)

ggplot(df1, aes(x = variable, y = beta, ymin = lowerci, ymax = upperci)) +
  geom_pointrange()

enter image description here

Data.

df1 <- read.table(text = "
variable lowerci beta upperci
a 0.86471152    0.87615515 0.88759878
b 0.966626566 0.970159119 0.973691671
c 0.94946211 0.955502661 0.961543211                  
", header = TRUE)
Rui Barradas
  • 70,273
  • 8
  • 34
  • 66
1

In addition to @Rui Barradas answer, here is a code to make it with base graphics:

df <- read.table(text = "variable lowerci beta upperci
a 0.86471152    0.87615515 0.88759878
b 0.966626566 0.970159119 0.973691671
c 0.94946211 0.955502661 0.961543211                  
", header = TRUE, as.is = TRUE)

plot(df[, 3], pch = 19, cex = 2, ylim = range(df[, -1]))
for (i in c(1:nrow(df))) {
    lines(c(i, i), c(df[i, 2], df[i, 4]))
}
Istrel
  • 2,508
  • 16
  • 22
  • +1 since the answer *does* show how to plot it using base graphics (not everything needs to be `ggplot`...). I would say, though, that `cex = 2` makes it hard to see the confidence intervals, especially with `pch = 19`. I think it looks better with `plot(df[, 3], pch = 20, ylim = range(df[, -1]))` personally. – duckmayr Mar 03 '19 at 21:30