Sample size is the number of observations or trials included in a sample, simulation, or sampling period. It is commonly denoted by n and influences the precision and reliability of statistical results. section 14.1.5 section 9.4
Sample size affects analysis in several practical ways:
- In Monte Carlo simulation, increasing the number of trials smooths small-sample anomalies and produces more stable estimates of outcome frequencies. section 9.4
- In quality-control charts, larger samples generally narrow control limits and improve sensitivity to small process shifts. section 14.1.5
- Larger samples improve estimates of process parameters and increase the ability to detect genuine process variation. section 14.1.5
- For p-charts, increasing n reduces the standard deviation of the observed proportion because variability decreases with sample size. section 14.1.3
Monte Carlo trials
A simulation can set num_trials = 500, draw outcomes from normalized probabilities, and calculate observed frequencies and percentages. Increasing the parameter to 1,000 or 10,000 trials can stabilize results, although gains eventually diminish. section 9.4
>>> np.random.seed(1) #1
>>> num_trials = 500 #2
>>> normalized_probabilities = \
>>> probabilities / probabilities.sum() #3
>>> simulated_values = np.random.choice(k_values, #4
>>> size = num_trials, #5
>>> p = normalized_probabilities) #6
>>> unique, counts = \
>>> np.unique(simulated_values, #7
>>> return_counts = True) #8
>>> simulated_counts = \
>>> dict(zip(unique, counts)) #9
>>> simulated_percentages = \
>>> {k: (v / num_trials) * 100 for k, \
>>> v in simulated_counts.items()} #10
Shows how NumPy uses the sample size to generate repeated outcomes and summarize their frequencies. section 9.4


