Method · Statistics Library

Monte Carlo simulation

Monte Carlo simulation propagates uncertainty through a formula by giving each uncertain input its own probability distribution, drawing thousands of random trials from them, and reporting the resulting distribution of the output rather than a single falsely-precise number.

Topic indexA reference reading outside the guided chapter sequence

Understand the idea

Suppose you are estimating next month's profit from price, cost, and sales volume, and none of the three is known exactly: each is a range of plausible values. Plugging in one 'best guess' for each and computing a single profit number hides how much that answer could really vary. Monte Carlo simulation instead assigns each input its own spread of plausible values, draws a random value for every input at once (one 'trial'), computes the output, and repeats this thousands of times.

What comes out is not one number but a whole distribution of possible outputs: a histogram showing which outcomes are common and which are rare, plus the chance the output crosses some threshold you care about (like profit going negative). The middle 90% of trials (from the 5th to 95th percentile) is a natural range to quote: 'in 90% of plausible scenarios, profit falls between X and Y.'

The tornado chart gives a quick, rough ranking of which inputs move together most strongly with the output. It is a screening tool, not an exact split of the uncertainty: an input that affects the result in a curved or up-and-down way, or only in combination with another input, can score low and still matter. Use it to decide where to look harder, not to rule inputs out.

Monte Carlo simulation is a form of uncertainty propagation, also called risk simulation: it pushes the uncertainty you specify for each input through the formula to see the spread of possible results, so the answer is only as good as those input ranges. In a Monte Carlo study, a sensitivity analysis asks which inputs are most strongly linked to the spread in the results, as a guide to where better information might help.

Practitioner explanation

KernelStats offers five input distributions: Normal(mean, sd), Uniform(min, max), Triangular(min, mode, max), Lognormal(mean, sd, parameterized in the variable's own units and converted internally to the underlying normal's mu/sigma), and PERT(min, mode, max, lambda=4, a reparameterized Beta). It evaluates a user-written formula over the named inputs using the same whitelisted formula-column grammar used elsewhere in the product (arithmetic, IF, MIN/MAX, ROUND, logical AND/OR/NOT; no eval, and an unknown name or function is rejected before any trial runs). Trials default to 10,000, with a fixed random_seed making a run exactly reproducible and the Monte Carlo standard error of the simulated mean (SD/sqrt(N)) reported. This measures finite-simulation uncertainty in the mean under independent finite-variance trials, not uncertainty in the reported percentiles or the spread of possible outcomes.

The tornado chart ranks inputs by squared Spearman rank correlations with the simulated output, normalized to sum to 100% when their sum is nonzero. These are association-based screening scores, not generally fractions of output variance or causal contributions. Rank correlation detects monotone association but may miss nonmonotone effects and interactions; the scores do not establish how much uncertainty would disappear by fixing an input.

This simulation draws inputs independently; it cannot specify correlated inputs. Ignoring real dependence can either increase or decrease the output spread, depending on the formula and covariance. Check whether independence is plausible before using the simulated range. Even with independent inputs, the tornado scores need not decompose variance.

When to use it

Consider it when

Several inputs to a formula are themselves uncertain (a range or an expert estimate, not a known fixed value) and you want the resulting uncertainty in the output (not just a single best-guess number) plus which input's uncertainty matters most.

Use caution when

Your inputs are genuinely known with certainty (a single formula evaluation is enough), your inputs are strongly correlated with each other in the real world (this simulation draws them independently and can misrepresent the output spread in either direction), or you need to fit a distribution's parameters FROM data rather than specify them by judgment (use the distribution fit or the descriptive summary first, then feed the fitted parameters in here).

Formulas and symbols

Simulated output

Yi=f(X1,i,X2,i,…,Xk,i),i=1,…,NY_i = f(X_{1,i}, X_{2,i}, \dots, X_{k,i}), \qquad i = 1, \dots, N

f the user-written formula; X_k,i the i-th random draw of the k-th input from its assigned distribution; N the number of trials.

Monte Carlo standard error of the simulated mean

MCSE=SDN\mathrm{MCSE} = \dfrac{SD}{\sqrt{N}}

SD is the sample standard deviation of the simulated outputs and N the number of independent finite-variance trials. This estimates Monte Carlo uncertainty in the simulated mean, not percentile-estimation error and not the output distribution's spread.

Normalized squared rank-correlation sensitivity

Scorek=ρs,k2∑jρs,j2×100\mathrm{Score}_k=\frac{\rho_{s,k}^2}{\sum_j\rho_{s,j}^2}\times100

rho_s,k is the Spearman correlation between input k and output. The normalization requires a positive sum of squared correlations. Scores are association-based screening measures, not generally variance shares; nonmonotone effects and interactions can be missed.

Assumptions and checks

  • Independence of observations. If real inputs are dependent, independently simulated draws can misrepresent output spread in either direction. The direction and size depend on the formula and joint distribution; the simulation does not check or estimate that joint distribution.

    In KernelStats: Not checked by KernelStats: every input is drawn independently by construction; there is no option to specify a correlation structure between inputs.

  • Too few trials give noisy, unstable estimates of the output's tails (P5/P95), even though the mean and center may already look stable.

    In KernelStats: Checked directly: the card flags fewer than 1,000 trials as inadequate and reports the Monte Carlo standard error of the mean regardless of the trial count.

  • If the formula frequently produces a non-finite result across the simulated draws (division by zero, the log of a non-positive value), the reported summary statistics are computed from an incomplete, possibly biased subset of the requested trials.

    In KernelStats: Checked directly: the card reports the fraction of trials that produced a non-finite result and fails the check outright once that fraction exceeds 50%.

Alternatives

  • Bootstrap Confidence Interval. You have actual observed data for the quantity of interest and want a confidence interval on a statistic computed from it, rather than propagating judgment-based input distributions through a formula.
  • Power & Sample Size. The uncertainty you care about is about a FUTURE STUDY's ability to detect an effect, not about propagating uncertain business or engineering inputs through a formula.

Worked example

Scenario

Monthly profit = (price - cost) * volume, where price ~ Normal(mean=40, sd=3), cost ~ Triangular(min=22, mode=25, max=31), and volume ~ PERT(min=800, mode=1200, max=2000), simulated with 10,000 trials (seed 42) and a threshold of profit > 0.

Result

Illustrative values: median simulated profit about $17,200 (mean $17,650, Monte Carlo SE of the mean $55), 90% simulation interval about $9,300 to $27,400, and 99.99% positive trials. Normalized squared rank-correlation scores are 49% for price, 33% for volume and 18% for cost; these are not variance shares.

Interpretation

Under the stated input model the illustrated profit distribution is mostly positive. Price has the largest rank-association screening score, followed by volume. This does not establish which intervention or additional measurement would reduce uncertainty most. The simulation depends on judgment-based input distributions drawn independently.

Common misconceptions

Misconception

The P90 value from a Monte Carlo simulation means there is a 90% chance the true output equals that exact number.

Correction

P90 means 90% of the simulated trials landed AT OR BELOW that value: it is a point on the output's cumulative distribution, not a probability that a single specific value is correct. Read percentiles as boundaries of a range, not as probability statements about one number.

Misconception

Plugging each input's average value into the formula gives the average of the output.

Correction

For a nonlinear formula this is false in general (Jensen's gap): the expected value of a nonlinear function of a random variable is not the function evaluated at the expected value of that variable. A single 'best guess' calculation using average inputs can be systematically biased relative to the true expected output; simulation captures this automatically because it evaluates the actual formula on every trial rather than once on averaged inputs.

References

  1. Risk Analysis: A Quantitative Guide, Vose, D. (2008).
  2. The Monte Carlo method, Metropolis, N. and Ulam, S. (1949), Journal of the American Statistical Association, 44(247), 335-341.
  3. posterior: Monte Carlo standard error for the mean, Stan development team.
  4. posterior: Monte Carlo standard error for quantiles, Stan development team.