Calculating mean of value across random trials/refreshes in Excel?

3

Say I have a 1000 cells filled with random values and a particular cell that computes a final answer based on those 1000 values. Now I wish to track the value of the answer over 1000 trials i.e., I wish to know over 1000 trials (e.g., pressing F9 1000 times to refresh the numbers) what is the range/mean/standard-deviation of the answer i.e., how much does it change from one trial to the other.

How can I store/capture results of intermediate simulation/trials and have a holistic measure of various statistics of the final answer? Is this even doable in Excel without any plugins per se?

PhD

Posted 2013-04-30T23:29:54.937

Reputation: 329

5Did you perhaps consider having 1000 columns, each with 1000 random values so that you can generate 1000 different "answers" at the same time? – barry houdini – 2013-05-01T00:25:30.063

@barryhoudini - That's A LOT of columns. But may just work for a quick little check. Good point. – PhD – 2013-05-01T02:34:53.480

1@phd Just by curiosity I've tried barry houdini solution, it took me 2 mns and 30 seconds to set-up a 1000x1000 array like that, with 3 added columns for 3 different stat functions calculating each line. It doesn't take more than a second to recalculate. I wonder why you insist on a vba solution ? – P. O. – 2013-05-02T15:25:43.190

@JoBedard - I don't think I insisted :) Houdini's idea didn't cross my mind. Thanks for the validation though. I was planning on going with that approach itself. – PhD – 2013-05-02T23:27:19.243

Answers

1

Excel's built-in functions aren't designed for this, because Excel is designed around the assumption that, given the same source data, a worksheet function is idempotent. Since your worksheet function itself seems to be generating random numbers, rather than having those numbers originate from cells elsewhere and populating those cells manually, you are violating this assumption.

"Hitting F9" (manual recalculation) is used very rarely, and there is no built-in formula that will take a procedural action when the user manually recalculates. Excel is supposed to work perfectly well with automatic calculation, which it does when your worksheet functions are idempotent, because you have to go in and change some of the source data (which eventually reduces down to literals, i.e., hard-coded numbers or strings) in order for a recalculation event to trigger.

You can, however, write a VBA macro and bind it to a hotkey, which will both manually recalculate and take the old value (prior to recalculating) and store it in an ever-growing list (a row or column) in another place in the worksheet/workbook. You can then perform your standard worksheet functions to calculate the descriptive statistics on the filled in array. We are not going to develop a pre-canned solution for you here, so if you have a specific problem with some code you are trying to get to work, you should probably post it on StackOverflow since programming questions are off-topic for SuperUser and on-topic for StackOverflow.

allquixotic

Posted 2013-04-30T23:29:54.937

Reputation: 32 256

Thanks for confirming that. I thought as much it just may not be doable! I guess VBA it is then :) – PhD – 2013-04-30T23:49:44.907