Group Abstract Group Abstract

Message Boards Message Boards

repeated sampling from a list

Posted 12 years ago
POSTED BY: Philip Cooper
8 Replies

Slightly more efficient, I suspect:

f[n_]:=Mean /@ Partition[RandomChoice[data, 7 n], 7]

Also note (!) the distinction that this needs to be RandomChoice rather than RandomSample. RandomChoice allows random selection from the list of data without using any of the data more than once. RandomSample allows for choosing a random datum more than once. I assume that this is actually what you want.

If you actually want RandomSample then the original approach posted above by Melvyn would be better, but the lenght of data must be greater than or equal to 7.

POSTED BY: David Reiss

Not sure if its the optimum method but ... f[n_] := Table[Mean[RandomSample[data, 7]], {n}];

ListPlot[f[100]]

Posted 12 years ago

Thank you!

POSTED BY: Philip Cooper

Even more efficient would be to use:

f[n_] := Mean /@ RandomChoice[data, {n , 7}]
POSTED BY: Sander Huisman

Right you are! I think the coffee hadn't kicked in yet. But the code is right ;-) (I an often code in Mathematica before I can speak sensibly....)

POSTED BY: David Reiss
Posted 12 years ago
POSTED BY: Philip Cooper

See my comment below about the difference between RandomSample and RandomChoice... it's an important distinction that you need to make to be sure you are calculating what you intend.

POSTED BY: David Reiss
Posted 12 years ago

I am extremely grateful, thank you! I changed ListPlot to Histogram. That's what I wanted. And your code looks pretty darn optimum to me! Thanks x 1e6!

Attachments:
POSTED BY: Philip Cooper
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard