[R] Query: weighting cells in histogram

Thomas W Blackwell tblackw at umich.edu
Fri Oct 3 15:10:02 CEST 2003


Marten  -

The context of the example makes your question much clearer.
You want to display an empirical distribution for which you
have only selected quantiles.  For quick, I would display it
as the empirical cdf:

plot(c(0,breaks), c(0:10) / 10, type="s", xlab="income",
   ylab="cumulative fraction")  #  I'm just making up the labels !

However, your question asks to display this as a histogram.
For that, I would use the function  barplot(), and tinker
with the options until you get the display that you want.
The function  hist()  mainly deals with reducing a sample
(the actual data) to a structure that can be displayed as
a barplot.  In earlier versions of R and Splus,  hist()
actually called  barplot()  rather than  plot()  to display
its result.

The question you will need to ask yourself, as you display
the empirical distribution in histogram fashion, is:
should the *height* of each bar or the *area* of each bar
be proportional to fraction of the total mass which it
represents ?

The convention is to make the area of each bar proportional
to the mass, since most people want to interpret a histogram
as an empirical density estimate.  Accommodating this convention
is what the  hist()  argument "freq" is all about.

-  tom blackwell  -  u michigan medical school  -  ann arbor  -

On Fri, 3 Oct 2003, [iso-8859-1] Mårten Bjellerup wrote:

> Thank you for your help bu I'm not sure what you mean.
> I have a cumulative distribution in the form:
>
> cum.freq.         'breaks'
> -> 10%                5
> -> 20%                15
> -> 30%                50
> -> 40%                150
> etc
>
> I want to assign the weight 10% to each cell (0-5, 5-15, 15-50 etc)
> and not the actual observataions (which I don't have).  However, that's
> not how 'x' is specified.
>
> Thank you again,
>
> Mårten
>
> ----- Original Message -----
> From: "Thomas W Blackwell" <tblackw at umich.edu>
> To: "Mårten Bjellerup" <marten.bjellerup at ehv.vxu.se>
> Cc: <r-help at stat.math.ethz.ch>
> Sent: Thursday, October 02, 2003 5:13 PM
> Subject: Re: [R] Query: weighting cells in histogram
>
> Marten  -
>
> I don't know exactly what interpretation you have in mind
> for weights, but if you assign the value of  hist()  to a
> variable tmp, you can then assign the component  tmp$counts
> any value you like, and plot the result as a histogram
> using  plot(tmp).  See the section "Value:" in  help("hist").
>
> -  tom blackwell  -  u michigan medical school  -  ann arbor  -
>
> On Thu, 2 Oct 2003, [iso-8859-1] Mårten Bjellerup wrote:
>
> > I have the 'breaks' for the histogram ('hist') but I want
> > to weight the cells instead of using actual observations.
> > I thought that using freq=FALSE implied that the numbers
> > in 'x' were weights but this turned out to be wrong.
> > Any help and/or comment is very much appreciated.
> >
> > Regards,
> >
> > Mårten
> >
> > Mårten Bjellerup
> > Doctoral Student in Economics
> > School of Management and Economics
> > Växjö University
> > SE-351 95  Växjö
> > Sweden
> >
> > Tel: +46 470 708410
> > Fax: +46 470 82478
> > Mobile: +46 70 969 88 88
> > Mail: marten.bjellerup at ehv.vxu.se
> > Web: http://www.ehv.vxu.se




More information about the R-help mailing list