Message Boards Message Boards

repeated sampling from a list

Posted 10 years ago
POSTED BY: Philip Cooper
8 Replies

Even more efficient would be to use:

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

Thank you!

POSTED BY: Philip Cooper

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

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
Posted 10 years ago

Wow! Thank you! Cool code! I think you accidentally wrote it backwards? RandomChoice - samples "with replacement", meaning you can draw the same list item more than once in a sample, whereas RandomSample will not (let you). But for (my) statistical purposes, either is fine as the sample is less than 5% of the population (the data set,) and the data set is greater than 30 items.

POSTED BY: Philip Cooper
Posted 10 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
POSTED BY: David Reiss

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

ListPlot[f[100]]

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

Group Abstract Group Abstract