[R] Lattice barchart with error bars

Shaun Jackman sjackman at gmail.com
Fri Jul 5 21:15:13 CEST 2013


Hmm. Interesting point, Bert. I don't know whether the notches show
the 95% confidence interval or the median, or the 95% confidence
interval that two non-overlapping notches have different medians.
You're saying it's the latter? Anyone know what the 95% confidence
interval of the median would be?

Cheers,
Shaun

> The notches (if requested) extend to +/-1.58 IQR/sqrt(n). This seems to be based on the same calculations as the formula with 1.57 in Chambers et al. (1983, p. 62), given in McGill et al. (1978, p. 16). They are based on asymptotic normality of the median and roughly equal sample sizes for the two medians being compared, and are said to be rather insensitive to the underlying distributions of the samples. The idea appears to be to give roughly a 95% confidence interval for the difference in two medians.


On 5 July 2013 11:48, Bert Gunter <gunter.berton at gene.com> wrote:
> Be careful!
>
> You are talking about 2 different varieties of apples here. As I read
> it, the CI's in the  cancer data, which I know is just for example
> purposes, are CI's for the **individual means**; the notches in
> boxplots are nonparametric and for 2 groups with roughly equal sample
> sizes, "The idea appears to be to give roughly a 95% confidence
> interval for the **difference** in two medians." (from
> ?boxplot.stats). So I'm not sure which you want, but they are
> certainly different (by a factor of around sqrt(2),right?), even if
> both are for the mean or both are for the median.
>
> Cheers,
> Bert
>
> On Fri, Jul 5, 2013 at 11:28 AM, David Winsemius <dwinsemius at comcast.net> wrote:
>>
>> On Jul 5, 2013, at 11:15 AM, Shaun Jackman wrote:
>>
>>> Hi Bert, Dennis,
>>>
>>> I'll agree that using a barchart was a poor choice. I was in fact using a
>>> notched bwplot to show the median and confidence interval of the median. In
>>> this case it's the median and confidence interval that I want to highlight,
>>> and I find that the visual noise of the box and whiskers is detracting from
>>> the focus, and those wee notches are not much to focus on. So, I'd like to
>>> draw a stripplot with error bars, preferably in Lattice. Let's call this a
>>> TIE fighter plot. Any suggestions?
>>>
>>
>> I like the TIE fighter label. Try this:
>>
>> library(latticeExtra)
>> data(USCancerRates)
>> segplot(reorder(factor(county), rate.male) ~ LCL95.male + UCL95.male,
>>         data = subset(USCancerRates, state == "Washington"),
>>         draw.bands = FALSE, centers = rate.male,
>>         segments.fun = panel.arrows, ends = "both",
>>         angle = 90, length = 1, unit = "mm")
>>
>> It's what Sarkar has recommended in the past when this request has been posted.
>>
>> --
>> David
>>
>>
>>> Cheers,
>>> Shaun
>>>
>>> On 4 July 2013 18:00, Dennis Murphy <djmuser at gmail.com> wrote:
>>>
>>>> If you consult the lattice package help, you'll discover there is no
>>>> panel_errorbar() function, which would imply the package developers
>>>> have a distaste for that type of graphic. If you fish around the
>>>> R-help archives, though, you might be able to find someone who wrote a
>>>> function to do error bars in lattice. (Use a searchable archive such
>>>> as Nabble to hunt for it.)
>>>>
>>>> Error bar plots are easier to do in the ggplot2 package, since there
>>>> is a specific function to generate the error bar 'geometry'
>>>> (geom_errorbar). See http://docs.ggplot2.org/current/ for an expanded
>>>> version of the package help pages, which include the graphs generated
>>>> by the code. I believe there's also a base graphics version that you
>>>> can get from the gplots package, but I don't know a lot about it.
>>>>
>>>> Dennis
>>>>
>>>> On Thu, Jul 4, 2013 at 2:53 PM, Shaun Jackman <sjackman at gmail.com> wrote:
>>>>> Hi,
>>>>>
>>>>> I'd like to draw a lattice barchart of means with error bars to show
>>>>> the standard deviation. I have the barchart, how do I add the error
>>>>> bars?
>>>>>
>>>>> require(datasets)
>>>>> require(lattice)
>>>>> x <- aggregate(weight ~ Diet, ChickWeight, function(x) c(mean=mean(x),
>>>>> sd=sd(x)))
>>>>> barchart(weight[,'mean'] ~ Diet, x)
>>>>>
>>>>> Thanks,
>>>>> Shaun
>>>>>
>>>>> ______________________________________________
>>>>> 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.
>>>>
>>>
>>>       [[alternative HTML version deleted]]
>>>
>>> ______________________________________________
>>> 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.
>>
>> David Winsemius
>> Alameda, CA, USA
>>
>
>
>
> --
>
> Bert Gunter
> Genentech Nonclinical Biostatistics
>
> Internal Contact Info:
> Phone: 467-7374
> Website:
> http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm



More information about the R-help mailing list