Professional Documents
Culture Documents
Abstract
Simulation in Excel: Tricks, Trials & Trends
Excel is a general purpose spreadsheet which is widely used & understood, but rarely used by itself for
simulations. However, the Data Table function in MS Excel can be used to execute substantial
simulations, without requiring cumbersome programming "tricks" or VBA coding. The result is an
arbitrarily large results table in which each row is one iteration of the simulation, and each column is a
random variable generated in the simulation.
A small number of additional probability functions are easily programmed using VBA to make Excel a
general purpose simulation package. Because VBA is interpreted, use of VBA functions can greatly limit
the speed of a simulation. However, for simulations of small size and complexity, the ease and familiarity
of working in Excel, outweigh the disadvantages of speed. Examples from clinical trials will be used.
Finally, I discuss new methods to move simulations out of the black boxes and into the enterprise, based
on work by Sam Savage. Simulation results (a SIP, or Stochastic Information Packet) from multiple
platforms can be stored as XML strings(using the DIST standard) in a SLURP (Stochastic Library Unit
with Relationships Preserved), and from there used for reports, planning, etc, or incorporated into other
simulations.
Outline
How to do Simulation in Excel
Simulation Sample Spreadsheet
Some Macros and VBA Clinical Trial Examples
functions
Notes on using Inverse Probability Functions
Validation, Verification, Sensitivity
Probability Management
in SIPS, SLURPS, & DIST
Background
Occasional need for simulations
Excel is convenient, but
does not explicitly support simulations
Simulation usually requires VBA programming
(so why not use R or SAS instead)
Simulate what?
Stochastic Models
Unknown parameters? Guestimate a distribution
Optimizing choices? Test each with simulations
Sensitivity Analysis
Variations in Inputs
Variations in Outputs
2 parameters: use a table
>2 parameters: simulate & compare variation
Excel: Pros
Common Language / Common Tools
Most people understand Excel
MEGO
Many tools available in Excel
Transparency: Modeling assumptions can be:
Specified -- Graphed -- Debated
What you see is what you get!
More hands on deck, more eyes on the prize.:
Statistician
Team Member
Initial Model
Explores & breaks model
Repair & enhance
Repeat until satisfied
Excel Cons
Slower than in SAS, S+, R, etc
Lacks some statistical/probability functions
Latest versions are a little better
Still need to add some VBA code
Known bugs in statistical routines (often fixed)
Tradeoffs:
Quicker modifications
vs slower execution
1. Create Simulation
From toolbar:
Data>Data Table
5. Execute Simulation
Iterative development
Simulation can be changed
Add reporting variables
Recalculate to rerun
(no need to use Data Table
again, unless expanding)
Hint: debug with short table,
expand for final run
The End
(of the key concepts)
Spreadsheet limitations
Only simple data structures are available
Rows & columns, no lists & trees
Discrete event simulations
Speed: slow
Data Storage: what-you-see-is-all-you-get
Macro SimulateSampler
To start a new simulation when you don't
remember the names & parameters of
common random variables used in simulation:
Run the Macro SimulationSample
Copy, delete, and edit as needed.
Make sure all random values are referenced
in the first row of the data table at the
bottom.
Macro SimulationSampler
Creates a simulation with
each of common
simulation functions
Macro SimulationSampler
Sets up header
row for data
table
Sets up a place
for statistics
Macro Simulate
Highlight the row of random variables
(1st row of simulation table)
Macro Simulate
Erlang Distribution
Beta Distribution
Can use as
Distribution of a Binomial probability
Range = [0,1]
Generic bounded hump (vs Normal as generic unbounded hump)
Better behaved than a triangular distribution
Example#2, Problem
Example#3,
Patients to Screen
Expected Enrollment rate
= 75% 5%
~ Beta Distribution
# Screen Failures
~ Negative Binomial (Pascal)
Depends on Enrollment
Rate
For
Convenience
Beta distribution given Mean, SD
Beta distribution given Mean, SD, upper, lower bounds
Beta distribution given Mode, Upper, Lower bounds
Here:
Rows are quartiles of a random function
Left column is value of a parameter
A family of distributions which vary with the parameter
Planning
Expected Trial Performance
Usually not of interest -- already done w/o simulation
But should be
Variability of Trial Performance
Important for Risk Management: Whats the earliest,
the latest, the most, the least, etc
80% CIs
Structural Problems
Interactions of parameters may doom the trial before it
even starts! (eg, mean (max{ X, Y} ) vs max{ mean(X), mean(Y) } )
Prototyping
Prototyping:
Toy simulation with hands-on teamwork
Development model
Get team buy-in on assumptions
Processing speed not important
Rapid modifications are important
Ideal?
Develop a prototype in an 1 hour meeting
Check for errors later
Run large simulations later for precise estimates
Checking Assumptions
Example:
A trial is designed based on a non-trivial simulation.
The model predicts a completion rate of 65%
with 95% C.I.= (55%, 75%)
4 months into the trial, a 50% completion rate is observed.
How significant is this discrepancy?
Resimulate:
{xi} = simulated completion rates (1/iteration)
%tile Rank of observed 50% in simulated {xi} p-value
How likely is the observation, under the modeled
assumptions?
Code &
Assumptions for
Study
Compare vs.
Internal
Assumptions
Compare vs.
literature
Sensitivity Analysis
What-ifs
Interactions between parameters
Identify Key Control points!
Vary parameters between simulations
Compare simulation results
Eg, average, worst-case scenarios
Macro Management
VBA Editor:
Alt-F11 (or find the menu)
Copy Module between sheets
Copy code from .xls sheet &
insert into VBA editor
Open & save as new sheet
Further resources
Commercial and Free software packages
Provide:
More rigorous algorithms
More functions
Resampling, multivariate, etc
More support
Commercial Add-Ins
@RISK
www.palisade.com
Crystal Ball
www.decisioneering.com
Free Add-Ins
PopTools
(Windows only)
www.cse.csiro.au/poptools
SimTools.xla (Macintosh & Windows)
http://home.uchicago.edu/~rmyerson/addins.htm
Caveat: Licensing
Free for non-commercial (eg, education)
Not clear for other uses
(NB: vba code from my website is free for all use,
but not as useful)
Semi-Commercial
Low-cost Excel simulation add-in:
RiskSim by Michael Middleton
www.treeplan.com/
Also: Decision Trees, Sensitivity Analysis,
on-line text-book:
http://www.treeplan.com/chapters.htm
Additional Reading
INTRODUCTION TO MODELING AND GENERATING
PROBABILISTIC INPUT PROCESSES FOR SIMULATION
www.informs-sim.org/wsc07papers/008.pdf
Spreadsheet Simulation (Seila, 2006)
www.informs-sim.org/wsc06papers/002.pdf
Work Smarter, Not Harder: Guidelines for
Designing Simulation Experiments
www.informs-sim.org/wsc06papers/005.pdf
Tips for the Successful Practice of Simulation
www.informs-sim.org/wsc06papers/007.pdf
The End
(Actual not simulated)