I have the 'breaks' for the histogram ('hist') but I want 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 ------------------------------------- "Forecasting is like trying to drive a car blindfolded and following directions given by a person who is looking out of the back window"
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
"hist" returns a list, to which you can apply your weights. Alternatively, in R 1.7.1, typing "hist" [without the quotes (")] at a commands prompt reveals a call to UseMethod. 'methods("hist")' identifies functions "hist.default" and "hist.POSIXt". Typing "hist.default" prodused the R code, which you can then customize any way you want. The protocol in R 1.8 for this is different, but the same concepts should apply, I believe. hope this helps. spencer graves M?rten Bjellerup wrote:>I have the 'breaks' for the histogram ('hist') but I want 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 >------------------------------------- >"Forecasting is like trying to >drive a car blindfolded and >following directions given >by a person who is looking >out of the back window" > >______________________________________________ >R-help at stat.math.ethz.ch mailing list >https://www.stat.math.ethz.ch/mailman/listinfo/r-help > >
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