Hello,
I have a problem that I am trying to solve and I am not sure how to
do it in R.
Suppose, that 16 numbers are choosen at random from 0 to 9, what's
the probability that their average will be between 4 and 6. I typed
the following code:
set.seed(100)
sample(0:9, 16, replace =TRUE)
[1] 3 2 5 0 4 4 8 3 5 1 6 8 2 3 7 6
Is what I got, however I realize the set.seed function locks in the
number I get every time.
My question is in order to run a true random sample, wouldn't I have
to use the runif function? And then deliminate the sample to show the
numbers that lie between 4 and 6? If that's the case, how do I do that?
Davia S. Cox
517-575-8031 cell
davia.cox at gmail.com
"Human potential, though not always apparent, is there waiting to be
discovered and invited forth." -William W. Purkey
Question
7 messages · Davia Cox, Sean Davis, Uwe Ligges +2 more
Please disregard this message and don't post it to the web. I found the answer. Thanks Davia S. Cox 517-575-8031 cell davia.cox at gmail.com "Human potential, though not always apparent, is there waiting to be discovered and invited forth." -William W. Purkey
On Dec 13, 2005, at 6:20 AM, Davia Cox wrote:
Hello, I have a problem that I am trying to solve and I am not sure how to do it in R. Suppose, that 16 numbers are choosen at random from 0 to 9, what's the probability that their average will be between 4 and 6. I typed the following code: set.seed(100) sample(0:9, 16, replace =TRUE) [1] 3 2 5 0 4 4 8 3 5 1 6 8 2 3 7 6 Is what I got, however I realize the set.seed function locks in the number I get every time. My question is in order to run a true random sample, wouldn't I have to use the runif function? And then deliminate the sample to show the numbers that lie between 4 and 6? If that's the case, how do I do that? Davia S. Cox 517-575-8031 cell davia.cox at gmail.com "Human potential, though not always apparent, is there waiting to be discovered and invited forth." -William W. Purkey
On 12/13/05 6:20 AM, "Davia Cox" <davia.cox at gmail.com> wrote:
Hello,
I have a problem that I am trying to solve and I am not sure how to
do it in R.
Suppose, that 16 numbers are choosen at random from 0 to 9, what's
the probability that their average will be between 4 and 6. I typed
the following code:
set.seed(100)
sample(0:9, 16, replace =TRUE)
[1] 3 2 5 0 4 4 8 3 5 1 6 8 2 3 7 6
Is what I got, however I realize the set.seed function locks in the
number I get every time.
Just don't use set.seed() before every run (unless you want to always get the same answers). Set.seed() is available to allow you to generate reproducible results, so not using it means that you will get a different set of random numbers every time you run your "sample" from above. Sean
Davia Cox wrote:
Hello,
I have a problem that I am trying to solve and I am not sure how to
do it in R.
Suppose, that 16 numbers are choosen at random from 0 to 9, what's
the probability that their average will be between 4 and 6. I typed
the following code:
set.seed(100)
sample(0:9, 16, replace =TRUE)
[1] 3 2 5 0 4 4 8 3 5 1 6 8 2 3 7 6
Is what I got, however I realize the set.seed function locks in the
number I get every time.
Yes, that's what set.seed is intended to do... otherwise don't use set.seed (and make your work unreproducible).
My question is in order to run a true random sample,
We have to disappoint you: Your computer cannot generate "true random samples". > wouldn't I have
to use the runif function? And then deliminate the sample to show the
No, if you want integers, the sample above fits perfectly well.
numbers that lie between 4 and 6? If that's the case, how do I do that?
Is this a homework question? Uwe Ligges
Davia S. Cox 517-575-8031 cell davia.cox at gmail.com "Human potential, though not always apparent, is there waiting to be discovered and invited forth." -William W. Purkey
______________________________________________ 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 13-Dec-05 Uwe Ligges wrote:
Davia Cox wrote: [...]
My question is in order to run a true random sample,
We have to disappoint you: Your computer cannot generate "true random samples".
At least on Linux (and probably most Unix) systems, /dev/random must be a pretty good approximation (provided you don't over-work it ... ). Oh for the days of "shot noise"! Best wishes, Ted. -------------------------------------------------------------------- E-Mail: (Ted Harding) <Ted.Harding at nessie.mcc.ac.uk> Fax-to-email: +44 (0)870 094 0861 Date: 13-Dec-05 Time: 14:16:59 ------------------------------ XFMail ------------------------------
On Tue, 13 Dec 2005 Ted.Harding at nessie.mcc.ac.uk wrote:
On 13-Dec-05 Uwe Ligges wrote:
Davia Cox wrote: [...]
My question is in order to run a true random sample,
We have to disappoint you: Your computer cannot generate "true random samples".
At least on Linux (and probably most Unix) systems, /dev/random must be a pretty good approximation (provided you don't over-work it ... ).
See library(accuracy) ?trueRandom (for some definition of 'true').
Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595
On 13-Dec-05 Prof Brian Ripley wrote:
On Tue, 13 Dec 2005 Ted.Harding at nessie.mcc.ac.uk wrote:
On 13-Dec-05 Uwe Ligges wrote:
Davia Cox wrote: [...]
My question is in order to run a true random sample,
We have to disappoint you: Your computer cannot generate "true random samples".
At least on Linux (and probably most Unix) systems, /dev/random must be a pretty good approximation (provided you don't over-work it ... ).
See library(accuracy) ?trueRandom (for some definition of 'true').
Spot on! Thanks for this -- I wasn't aware of it previously. The URL to HotBits in ?trueRandom is worth following, and the descriptions in "How it Works": http://www.fourmilab.ch/hotbits/how.html are entertaining reading. Best wishes, Ted. -------------------------------------------------------------------- E-Mail: (Ted Harding) <Ted.Harding at nessie.mcc.ac.uk> Fax-to-email: +44 (0)870 094 0861 Date: 13-Dec-05 Time: 16:47:37 ------------------------------ XFMail ------------------------------