Skip to content

Plotting multiple confidence intervals in the same graph

4 messages · Preetam Pal, PIKAL Petr, Thomas Stewart +1 more

#
Hi
Hm, I do not understand well what procedure you want to repeat 50 times?
If you want to have 50 colours you will not be able to distinguish differences. How do you want to plot 50 confidence intervals?

Something like that comes to mind but you shall be more specific about what do you want

plot(1,1, type="n")
arrows(1,.8,1,1.2, angle=90, code=3)
abline(h=1.1, col=2)

Regards
Petr
#
Maybe something like this, assuming mean=0:

samsize <- 100 
replicates <- 50
pval <- .05

samples <- replicate(replicates, rnorm(samsize))
confint <- t(apply(samples, 2, function(x)
c(mean(x)-qt(1-pval/2, 
   df=samsize-1)*sd(x)/sqrt(samsize), 
   mean(x)+qt(1-pval/2, df=samsize-1)*sd(x)/sqrt(samsize))))

# Simple plot
plot(c(0, 0), c(1, replicates), col="black", typ="l",
ylab="Samples",
   xlab="Confidence Interval")
segments(confint[,1], 1:replicates, confint[,2], 1:replicates)

# Use red if mean outside interval
outside <- ifelse(confint[,1]>0 | confint[,2]<0, 2, 1)
plot(c(0, 0), c(1, replicates), col="black", typ="l",
ylab="Samples",
   xlab="Confidence Interval")
segments(confint[,1], 1:replicates, confint[,2], 1:replicates,
col=outside)

-------------------------------------
David L Carlson
Department of Anthropology
Texas A&M University
College Station, TX 77840-4352




-----Original Message-----
From: r-help-bounces at r-project.org
[mailto:r-help-bounces at r-project.org] On Behalf Of PIKAL Petr
Sent: Thursday, November 21, 2013 8:13 AM
To: Preetam Pal; r-help at r-project.org
Subject: Re: [R] Plotting multiple confidence intervals in the
same graph

Hi
same graph
interval
many times
Hm, I do not understand well what procedure you want to repeat
50 times?
the 50
vertical line
If you want to have 50 colours you will not be able to
distinguish differences. How do you want to plot 50 confidence
intervals?

Something like that comes to mind but you shall be more specific
about what do you want

plot(1,1, type="n")
arrows(1,.8,1,1.2, angle=90, code=3)
abline(h=1.1, col=2)

Regards
Petr
Room No.
B.H.O.S.
http://www.R-project.org/posting-
code.

______________________________________________
R-help at r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible
code.