liveBook · Manning

Simulation

As explained in Grokking Statistics

A simulation is a computational procedure that generates artificial outcomes according to specified rules or probability models.

Simulation generates artificial outcomes by repeatedly applying specified rules or probability models. For a device expected to succeed 90% of the time, it can test whether observing 7 successes in 10 trials is unusual or merely random variation. section 3.7

from random import random

p = 0.9  #1

outcomes = {key: 0 for key in range(11)}  #2

for i in range(10000):  #3

  successes = 0
  for j in range(10):  #4
      if random() < p:  #5
          successes += 1  

  outcomes[successes] +=1

for k,v in outcomes.items():  #6
  print(f"Experiments with {k} successes: {v}")  #6

Run 10,000 experiments, each containing 10 simulated trials. Each trial draws a random number and counts success when it falls below p = 0.9; the resulting counts show the distribution of outcomes. section 3.7

Testing a 7-out-of-10 result

The simulation finds that 7 successes in 10 trials can occur under a 90% success probability, but represents only about 6.1% of simulated experiments. Repeating the run may produce slightly different proportions because the procedure is random. A bar chart makes the outcome distribution visible, while a binomial calculation gives a closely related probability of about 0.0574. section 3.7

How Grokking Statistics covers it

How deep it goes
Explains the simulation loop, outcome counting, visualization, and run-to-run variation, then compares results with binomial probabilities.
Examples
Demonstrates 10,000 experiments of 10 device trials with a 90% success threshold and charts the resulting success counts.
What it assumes
Starts with limited probability knowledge by using simulated coin-flip logic and a stated success probability.
What you can do after
Apply simulation in Python to estimate outcome frequencies and interpret whether an observed trial result is plausible.
How it connects
Connects simulation with probability, random variation, binomial distribution, and Python visualization.

Also explained in

Compare how 6 books explain simulation →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Grokking Statistics. The section links point to the parts of the book it draws on.