On 29 Jun 2002 07:23:56 -0700
[EMAIL PROTECTED] (SR Millis) wrote:

> I'm graphically-challenged and need help on the simple graphing/plotting
> of confidence intervals.
> 
> Specifically: I have 4 studies that each involve binary outcome in a
> 2-group parallel design. I have calculated the differences in
> proportions and their associated 95% CIs. I now want to graphically
> display the point estimates and CIs together--like
>  
>          -----X-----
> 
>            --X--
>          
>           ------X------
> 
> I there a simple way to produce summary graphs like this with Stata,
> SAS, S-plus, SPSS, Excel, etc?
> 
> Thanks,
> SR Millis

See P. 14 of 
http://hesweb1.med.virginia.edu/biostat/teaching/clinicians/ci2.biostat1.pdf

The S-Plus/R code for producing this figure is below.  For R a slight change in the 
.Internal call is needed.  For your question you can ignore the bootstrapping part 
though.  The only reason the code is at all complex is because I wanted to show the 
individual CLs and the CL for the difference on the same graph, with two different 
x-axis scales.

bootmean <- function(x, conf.int = 0.95, B = 1000, na.rm = TRUE)
{
        if(na.rm)
                x <- x[!is.na(x)]
        n <- length(x)
        xbar <- mean(x)
        if(n < 2)
                return(Mean = xbar, Lower = NA, Upper = NA)
        z <- unlist(lapply(1:B, function(i, x, N)
        sum(x[.Internal(sample.index(N, N, TRUE), "S_sample", T, 0)]), x = x,
                N = n))/n
        quant <- quantile(z, c((1 - conf.int)/2, (1 + conf.int)/2))
        names(quant) <- NULL
        list(stats=c(Mean = xbar, Lower = quant[1], Upper = quant[2]), reps=z)
}

male   <- bootmean(glyhb[gender=='male'])
female <- bootmean(glyhb[gender=='female'])
dif <- c(mean=male$stats['Mean']-female$stats['Mean'],
         quantile(male$reps-female$reps, c(.025,.975)))
male <- male$stats
female <- female$stats

par(mar=c(4,6,4,1))
plot(0,0,xlab='Glycated Hemoglobin',ylab='',
     xlim=c(5,6.5),ylim=c(0,4), axes=F)
axis(1)
axis(2, at=c(1,2,4), labels=c('Female','Male','Difference'),
     las=1, adj=1, lwd=0)

points(c(male[1],female[1]), 2:1)
segments(female[2], 1, female[3], 1)
segments(male[2], 2,   male[3], 2)

offset <- mean(c(male[1],female[1])) - dif[1]
points(dif[1] + offset, 4)
segments(dif[2]+offset, 4, dif[3]+offset, 4)

at <- c(-.5,-.25,0,.25,.5,.75,1)
axis(3, at=at+offset, label=format(at))

-- 
Frank E Harrell Jr              Prof. of Biostatistics & Statistics
Div. of Biostatistics & Epidem. Dept. of Health Evaluation Sciences
U. Virginia School of Medicine  http://hesweb1.med.virginia.edu/biostat
.
.
=================================================================
Instructions for joining and leaving this list, remarks about the
problem of INAPPROPRIATE MESSAGES, and archives are available at:
.                  http://jse.stat.ncsu.edu/                    .
=================================================================

Reply via email to