Mathematica 9 is now available
Student Support Forum
-----
Student Support Forum: 'How do I calculate the mean from 1000 replicate...' topicStudent Support Forum > General > Archives > "How do I calculate the mean from 1000 replicate..."

Next Comment >Help | Reply To Topic
Author Comment/Response
Ray
08/28/08 6:30pm

I have had a little trouble with what would seem a simple problem. This code provides the correct output that i'm looking for, however i'm not sure how to find an average from 1000 iterations? I have tried placing the Mean function prior to the list and sample[pop,1,20] commands. The only response renders Mean[null,{1000}]. Any suggestions would be greatfully accepted.

<< Statistics`DescriptiveStatistics`
pop = {1, 1, 1, 2, 2, 3, 3, 3, 4, 4, 4, 2, 2, 3, 3, 3, 1, 1, 4, 4};

sample[pop, start_, end_]
:= Module[{len = Length[pop], rand}, Do[rand = Random[Integer, {j, len}];
pop[[{j, rand}]] = pop[[{rand, j}]], {j, start, end}];
Take [pop, {start, end}]]

sample[pop, 1, 20];
one = Union[Extract[pop, {{1}, {2}, {3}, {4}}]];
two = Union[Extract[pop, {{5}, {6}, {7}, {8}}]];
three = Union[Extract[pop, {{9}, {10}, {11}, {12}}]];
four = Union[Extract[pop, {{13}, {14}, {15}, {16}}]];
five = Union[Extract[pop, {{17}, {18}, {19}, {20}}]];

Apply[Plus, {Count[{one}, {1, 2, 3, 4}], Count[{two}, {1, 2, 3, 4}],
Count[{three}, {1, 2, 3, 4}], Count[{four}, {1, 2, 3, 4}],
Count[{five}, {1, 2, 3, 4}]}]


URL: ,

Subject (listing for 'How do I calculate the mean from 1000 replicate...')
Author Date Posted
How do I calculate the mean from 1000 replicate... Ray 08/28/08 6:30pm
Re: How do I calculate the mean from 1000 repli... Jean-Marc Gu... 09/02/08 00:58am
Re: Re: How do I calculate the mean from 1000 r... Ray 09/03/08 7:42pm
Next Comment >Help | Reply To Topic