Hi everyone, I need help. I want to have a "uniform" kind distribution. When I used sample function I got almost twice many zeros compared to other numbers. What's wrong with my command ? temp <-sample(0:12, 2000, replace=T,prob=(rep(1/13,13))) hist(temp) Thanks in advance, Taka,
"hist" is lumping things together. Try: sum(temp == 0) compare to the height of the left most bar. Is this a bug in hist? - Martin mirage sell wrote:> Hi everyone, I need help. > I want to have a "uniform" kind distribution. When I used sample > function I got almost twice many zeros compared to other numbers. What's > wrong with my command ? > > temp <-sample(0:12, 2000, replace=T,prob=(rep(1/13,13))) > hist(temp) > > Thanks in advance, > > Taka, > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! > http://www.R-project.org/posting-guide.html
It's not the simulated data, but how hist() handled it. If you use truehist() in the MASS package, you don't see the problem. Nor would you see it like this:> table(temp)/length(temp)temp 0 1 2 3 4 5 6 7 8 9 10 11 0.0745 0.0745 0.0830 0.0755 0.0760 0.0750 0.0700 0.0765 0.0775 0.0805 0.0830 0.0765 12 0.0775 Andy> From: mirage sell > > Hi everyone, I need help. > I want to have a "uniform" kind distribution. When I used > sample function I > got almost twice many zeros compared to other numbers. What's > wrong with my > command ? > > temp <-sample(0:12, 2000, replace=T,prob=(rep(1/13,13))) > hist(temp) > > Thanks in advance, > > Taka, > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! > http://www.R-project.org/posting-guide.html > > >
On Thu, 10 Mar 2005, mirage sell wrote:> Hi everyone, I need help. > I want to have a "uniform" kind distribution. When I used sample function I > got almost twice many zeros compared to other numbers. What's wrong with my > command ? >Nothing is wrong with your sampling, it is the display in the histogram. Try temp <-sample(0:12, 2000, replace=T,prob=(rep(1/13,13))) table(temp) David Scott _________________________________________________________________ David Scott Department of Statistics, Tamaki Campus The University of Auckland, PB 92019 Auckland NEW ZEALAND Phone: +64 9 373 7599 ext 86830 Fax: +64 9 373 7000 Email: d.scott at auckland.ac.nz Graduate Officer, Department of Statistics
On Thu, 10 Mar 2005, Martin C. Martin wrote:> "hist" is lumping things together. > > Try: > sum(temp == 0) > > compare to the height of the left most bar. > > Is this a bug in hist? >No, hist is the wrong thing to use to display this data. Try temp <-sample(0:12, 2000, replace=T,prob=(rep(1/13,13))) barplot(table(temp)) David Scott _________________________________________________________________ David Scott Department of Statistics, Tamaki Campus The University of Auckland, PB 92019 Auckland NEW ZEALAND Phone: +64 9 373 7599 ext 86830 Fax: +64 9 373 7000 Email: d.scott at auckland.ac.nz Graduate Officer, Department of Statistics
On Thu, 2005-03-10 at 20:54 -0600, mirage sell wrote:> Hi everyone, I need help. > I want to have a "uniform" kind distribution. When I used sample function I > got almost twice many zeros compared to other numbers. What's wrong with my > command ? > > temp <-sample(0:12, 2000, replace=T,prob=(rep(1/13,13))) > hist(temp) > > Thanks in advance,Hint: take note that there are only 12 cells in the plot, not 13... However, note that the frequency of the 13 elements are appropriate:> table(sample(0:12, 2000, replace=T))0 1 2 3 4 5 6 7 8 9 10 11 12 158 156 151 163 156 158 146 154 134 158 146 147 173 Review the details of how the breaks are selected in ?hist. BTW, you do not need to specify the 'prob' argument if you want equal probabilities as per my example above. HTH, Marc Schwartz