模擬學
Simulation
Test of Randomness
Prof. Sheng-I Chen
March 27, 2025
Objectives of Goodness-of-fit Test
• The frequency of random numbers occurred in the each interval looks
uniformly:
0.14
0.12
Probability 0.1
0.08
0.06
0.04
0.02
0
Un
• , and the expected value is close to U(0,1)
0.496667561 ≈ 0.5
• Well, how good are these samplings fitting to U(0,1)?
2
Goodness-of-Fit Tests
• Since these random numbers are obtained from a certain distribution, we may
want to use sample information to drawn certain conclusions about the
population. This technique is so call inferential statistics
• Goodness-of-Fit tests: The test statistic will be a measure of the discrepancy
between the observed frequency of random numbers and the expected
frequency occurred in each category when H0 is true
• An example of using chi-square test to check whether the generated random
numbers are drawn from a given probability distribution
• The decision will be reached by comparing the computed value of the test
statistic to a critical value of the chi-squared distributions
3
Goodness-of-Fit Test
• Example: We may want to check whether the distribution of observed
inter-arrival time following the exponential distribution with mean value
10
• The hypotheses are:
H0: Xn ~ Exp(1/10)
H1: Xn Exp(1/10)
• Null hypothesis H0 claims that the generated random numbers are
distributed exponentially with mean equal to 10
• How to test the hypotheses?
4
Goodness-of-Fit Test for Inter-arrival Time (1/8)
• Step 1. Run the M/M/1 simulation model
• Step 2. After the run completed, select “Tools -> Global tables ->
Time”, and then copy “Inter-Arrival Time” values
5
Goodness-of-Fit Test for Inter-arrival Time (2/8)
• Step 3. Paste the inter-arrival time values to Excel temperately
• Step 4. Go to “Statistics -> Expertfit”, then click “New”
• Step 5. Enter Project-Element Name, select “Fit distributions to data”,
then click “OK”
6
Goodness-of-Fit Test for Inter-arrival Time(3/8)
• Step 6. Double click the project you just saved, then click “Enter Data”
• Step 7. Select “Enter/Edit Data Values” , then click “Apply”
7
Goodness-of-Fit Test for Inter-arrival Time (4/8)
• Step 8. Copy the inter-arrival time data from Excel, and then click
“Paste at End from Clipboard”, and then click “OK”
8
Goodness-of-Fit Test for Inter-arrival Time (5/8)
• Step 9. Now, we are ready to perform the hypothesis test. Before
doing that, we may plot the histogram by the procedure of
“Histogram... -> Histogram Plot -> Apply”:
Exponential
Distribution P.D.F.
6
f(0.5) f(1) f(2) f(4)
4
Are they alike?
f(x)
2
0
0 0.4 0.8 1.2 1.6 2 2.4 2.8 3.2 3.6 4 4.4
x
9
Goodness-of-Fit Test for Inter-arrival Time (6/8)
• Step 10. Next, we may want to know which distributions fit the data
well. This can be done by selecting “Models” tab, then click
“Automated Fitting...”
10
Goodness-of-Fit Test for Inter-arrival Time (7/8)
• Step 11. To perform Chi-square test, we may select “Comparisons”
tab, check “Chi-Square Test”, and then select “5-Exponential”, and
then click “Apply”
11
Goodness-of-Fit Test for Inter-arrival Time (8/8)
• Conclusion:
The null hypothesis is not rejected across various levels of significance (α)
• Note: (Rejection criteria)
X2 ≥ X2α, k-1
or p-value ≤ α 12
Exercise
• Test the random numbers generated by the LCG algorithm that you
implemented previously
• The hypothesis of the Goodness-of-fit test is
H0: Xn ~ Uniform[0,1]
H1: Xn Uniform[0,1]
• Perform the Chi-square test and obtain the p value
• If p > α (not reject the null hypothesis), then your LCG algorithm should be
randomness
13