Coin Toss Pattern
How many coin tosses on an average are needed to get to a head? That answer should be intuitive and the answer is 2.
Lets try something more challenging. How many tosses to get two consecutive heads (hh)? What about a head followed by a tail (ht)? Feels like two heads should be the same as heads followed by tails right? Or is it?
What about head-tails-head (hth) versus head-head-head (hhh) versus head-tail-tail (htt)? How many tosses do you think you need to get to the first of those patterns?
You can try running simulations to find out all the above answers. The error_average is the +/- error estimate on the average tosses required at 95% confidence (under some assumptions).
Sample an outcome from the outcomes array based on the corresponding probabilities in the probabilities array.
Returns the average of the values in the array. It can be handy to store the values of metrics from each simulation run and average it across all runs to obtain an estimate of the metric.
Returns the estimated error (1.96 x standard error) of the average of the values at 95% confidence. In simple terms, you can assume that the estimate average(values) has error bounds +/- error_average(values). It can be handy to store the values of metrics from each simulation run and estimate both the average and the error of the average across all runs.
Returns the standard deviation of the values in the passed in array.
Creates a radio button parameter with name and have each option in the options array selectable. Returns the selected option.
Create a textbox parameter with name and a required default value. Returns the value of the textbox.
scatter_graph(data, xlabel, ylabel)
Create a graph based on a data array and plot (data.xlabel, data.ylabel) on it. Can also pass xmin=null, xmax=null, ymin=null, ymax=null as added arguments.
Calling this function, stops the simulation.