3
$\begingroup$

I am new to simulation exercises in R. I want to create 1000 samples of size 25 from a t distribution with degrees of freedom 10.

Do I need to create a single vector of data from the rt generator, and then sample repeatedly from that? So, for example, I could create the vector:

singlevector <- rt(5000, 10) , which generates data from a t -distribution of size 5000 and df = 10. So, I would treat this as my population and then sample from it. I chose the population size of 5000 arbitrarily here.

OR, should I create my 1000 samples calling on this random t generator every time?

In other words, create a matrix with 25 rows and 1000 columns, each column containing vector corresponding to a new call of rt(25, 10).

Thank you.

$\endgroup$
5
  • $\begingroup$ I think you might be better on R-help or StackOverflow $\endgroup$
    – mdewey
    Commented Nov 23, 2016 at 18:32
  • 3
    $\begingroup$ @mdewey This looks like a purely statistical question to me, concerning how to use random number generators appropriately. $\endgroup$
    – whuber
    Commented Nov 23, 2016 at 18:56
  • 2
    $\begingroup$ I agree with whuber here -- while phrased as if it were a question about how to do something in R, the central issue here is about how to use random number generators. We should not regard a question as off topic merely because the poster doesn't yet understand enough to clearly disentangle their language issues from their statistical issues (that's why they're asking questions). To some extent it's our job as (hopefully) knowledgeable statisticians to spot the statistical questions lurking in these posts and help the OP to focus on them; remaining language issues may then be solved elsewhere. $\endgroup$
    – Glen_b
    Commented Nov 24, 2016 at 2:42
  • $\begingroup$ @Glen_b I see your point. I had interpreted it purely in terms of which method made more sense programmatically rather than the question of when is a sample from a random sample also a random sample. $\endgroup$
    – mdewey
    Commented Nov 24, 2016 at 11:59
  • $\begingroup$ @whuber I finally worked out how to retract my vote. See also my response to Glen_b above. $\endgroup$
    – mdewey
    Commented Nov 24, 2016 at 13:21

1 Answer 1

2
$\begingroup$

Your population is the (notionally) infinite population of values you might have got from a t-distribution with 10 df. (In practice a random number generator can only generate a finite number of distinct values, because precision is finite. However this doesn't change the way you should normally look at it.)

Any finite population can't literally be t-distributed (though it may have a distribution-function that's quite close to that of the $t$).

You should not generate fewer values than you will need and then sample those with replacement, as you seem to propose.

While there would be no harm in sampling some larger-than-needed set of t$_{10}$-distributed values (i.e. more than 25000) and then sampling without replacement from those, there's no point in doing so -- simply simulate all the values you need directly from the generator when you need them.

[Personally, if I were doing it, I'd probably simulate 25000 values and arrange them into an object in one go, such as by a call to rt inside a call to matrix, but there's a variety of ways to do it that would reasonable (it's such a small number of values it hardly matters how you do it as long as you don't grow any data structures as you go). If I only needed something computed from each sample I'd probably use replicate instead.]

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.