









Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!










Jomo Kenyatta University of Agriculture and Technology Department of Computing
Q1 — Discrete-Event Simulation (Drive-in Restaurant) Q2 — Poisson Distribution (Photocopier Breakdowns) Q3 — Normal Distribution (Car Speeds) Q4 — Runs Test for Independence Q5 — Inverse Transform Method (Exponential Distribution) Q6 — Hypothesis Testing & Confidence Intervals
Question 1: Drive-In Restaurant — Discrete-Event Simulation What is Discrete-Event Simulation? Discrete-Event Simulation (DES) models a system as a sequence of events occurring at distinct points in time. Here we simulate a drive-in restaurant queue where cars arrive and are served by one of two carhops (Able or Baker). Because actual data is unavailable, we use probability tables and random numbers to mimic the randomness of real arrivals and service. Step 1 — Build Random Number (RN) Mapping Tables Before we can simulate, we must convert each probability into a range of two-digit random numbers (00–99). The idea is simple: if an event has probability 0.25, it should be selected 25% of the time, so we assign it 25 out of 100 possible numbers (00–24). Rule: Cumulative probability up to (but not including) the current row gives the start of the range; the end is one less than the next cumulative probability × 100. Arrivals Table (Time Between Arrivals): Inter-arrival (min) P Cumulative P RN Range 1 0.25 0.25 00 – 24 2 0.40 0.65 25 – 64 3 0.20 0.85 65 – 84 4 0.15 1.00 85 – 99 Explanation: The first row (1 min) gets 25 numbers: 00 – 24. The second row (2 min) gets 40 numbers: 25 – 64 (because 0.25 × 100 = 25 starts, and 0.65 × 100 − 1 = 64 ends). And so on. Able Service Time Table: Service Time (min) P Cumulative P RN Range 2 0.30 0.30 00 – 29 3 0.28 0.58 30 – 57 4 0.25 0.83 58 – 82 5 0.15 1.00 83 – 99 Baker Service Time Table:
Detailed Example: Customer 4 RN = 17 → inter-arrival = 1 min → Arrival time = 3 + 1 = 4 min. Able free at 3 (from C3 end) — but C3 started at 3, so Able free at 3+2 = 5. Baker free at 5 (from C2). Both are busy at t=4. Customer must wait. Able becomes free at 5, Baker also at 5 — tie, so Able is assigned. Wait = Service start − Arrival = 5 − 4 = 1 min. RN for service = 63 → falls in 58 – 82 → Service time = 4 min. Service end = 5 + 4 = 9 min. Able free at 9. Step 5 — Compute Summary Statistics (a) Proportion of time Able was busy: Count the total minutes Able spent serving customers: Able served: C1(3min) + C3(2) + C4(4) + C6(4) + C8(3) + C10(3) + C11(2) + C13(4) + C14(3) + C16(5) + C19(2) + C20(3) + C22(3) + C24(5) + C26(3) + C28(2) + C29(4) + C31(2) + C33(3) + C34(2) + C36(4) + C38(3) + C40(3) + C42(3) + C43(2) + C45(3) + C46(4) + C48(3) = 72 min Proportion Able busy = 72 / 90 = 0.80 = 80% Answer (a): Able was busy 80% of the 90-minute simulation period. (b) Proportion of time Baker was busy: Baker served: C2(4) + C5(3) + C7(5) + C9(6) + C12(5) + C15(3) + C17(4) + C18(5) + C21(3) + C23(3) + C25(5) + C27(4) + C30(4) + C32(5) + C35(4) + C37(4) + C39(3) + C41(5) + C44(5) + C47(3) = 65 min Proportion Baker busy = 65 / 90 = 0.722 = 72.2% Answer (b): Baker was busy 72.2% of the 90-minute simulation period. (c) Average number of customers in queue: This uses Little's Law: Lq = (Total customer-minutes spent waiting) / (Simulation time) Sum all waiting times from the Wait column: 0+0+0+1+0+0+0+0+0+0+2+1+1+3+2+3+1+3+3+4+4+3+3+2+3+4+4+1+1+0+2+0+0+2+0+1+1+1+ +0+1+0+2+1+1+3+2+4 = 69 minutes total wait Lq = Total wait-minutes / Simulation time = 69 / 90 = 0.767 customers Answer (c): On average, approximately 0.767 customers were waiting in queue at any given moment. (d) Average waiting time per customer: This is simply the total waiting time divided by the number of customers who went through the system. W = Total wait / Number of customers = 69 / 48 = 1.4375 ≈ 1.44 minutes
Question 2: Poisson Distribution — Photocopier Breakdowns What is the Poisson Distribution? The Poisson distribution models the number of times a random event occurs in a fixed interval of time or space, where events happen independently at a constant average rate λ (lambda). The formula is: P(X = k) = (e^(-λ) × λ^k) / k! where k is the number of events and e ≈ 2.71828. Given: Average breakdowns per week (Mon–Fri, 5 days) = λ = 8 Part (i) — P(X = 5) in a given week Step 1: Identify parameters We want the probability of exactly 5 breakdowns in a week. λ = 8 (average per week), k = 5 (we want exactly 5) Step 2: Apply the Poisson formula P(X = 5) = (e^(-8) × 8^5) / 5! e^(-8) = 0.000335 8^5 = 8 × 8 × 8 × 8 × 8 = 32,768 5! = 5 × 4 × 3 × 2 × 1 = 120 P(X = 5) = (0.000335 × 32,768) / 120 = 10.977 / 120 ≈ 0. Answer (i): P(X = 5) ≈ 0.0916. There is a 9.16% chance of exactly 5 breakdowns in a given week. Part (ii) — P(X = 1) on a Monday Step 1: Find λ for a single day The weekly average is 8 breakdowns over 5 days. Per day average: λ_day = 8 / 5 = 1. breakdowns per day Step 2: Apply the Poisson formula with λ = 1.6, k = 1 P(X = 1) = (e^(-1.6) × 1.6^1) / 1! e^(-1.6) = 0.2019 1.6^1 = 1.6 1! = 1 P(X = 1) = (0.2019 × 1.6) / 1 = 0. Answer (ii): P(X = 1 on Monday) ≈ 0.3230. There is a 32.3% chance of exactly one breakdown on any given Monday.
Step 2: Find P(Z < 0.181) from the Z-table P(Z < 0.181) ≈ 0.5719 (from standard normal tables, interpolating between z=0.18 and z=0.19) Step 3: Find P(X > 70) = 1 − P(X < 70) P(X > 70) = 1 − 0.5719 = 0. Answer (b): Approximately 42.81% of cars travel at more than 70 km/h.
Question 4: Runs Test for Independence (Up and Down) What is the Runs Test (Up/Down)? The Runs Test checks whether a sequence of numbers is truly random/independent. We look at consecutive pairs: if x(i+1) > x(i), record '+' (up); if x(i+1) < x(i), record '−' (down). A 'run' is a consecutive sequence of the same sign. Too few or too many runs suggest the numbers are not independent. Step 1 — Convert the Sequence to +/− Signs Compare each consecutive pair in the 60 numbers. With 60 numbers, we get 59 sign comparisons. Sign sequence (59 signs): + − − − + + − + + − + − + + − + + − + − + − − + − + − − + − − + + + − − − + + − − − + − + − − − + − + − − − + − + − − Step 2 — Count the Runs A run ends whenever the sign changes. Count each group of consecutive identical signs as one run: Run # Signs Length 1 + 1 2 −−− 3 3 ++ 2 4 − 1 5 ++ 2 6 − 1 7 + 1 8 − 1 9 ++ 2 10 − 1 11 ++ 2 12 − 1 13 + 1 14 − 1 15 + 1 16 −− 2
Z = (R − E(R)) / σ(R) = (38 − 39.67) / 3.216 = −1.67 / 3.216 = −0. The Z-statistic follows a standard normal distribution under H₀ (independence). A value far from zero (positive or negative) would indicate non-independence. Step 5 — Compare to Critical Value and Conclude Critical value at α = 0.01 (two-tailed test): H₀: The numbers are independent (random) H₁: The numbers are not independent For two-tailed test, α/2 = 0.005 → Z_critical = ±2. |Z_calculated| = 0.519 < Z_critical = 2. Answer: Since |−0.519| < 2.576, we FAIL TO REJECT H₀. There is insufficient evidence at α = 0.01 to conclude that the sequence is non-random. The numbers appear to be independent.
Question 5: Random Variate Generation — Exponential Distribution What is the Inverse Transform Method? The Inverse Transform Method generates random variates from any distribution by inverting its Cumulative Distribution Function (CDF). If U is a uniform random number on [0,1], then X = F⁻¹(U) has the desired distribution. This works because F(X) is itself uniformly distributed. Given PDF: f(x) = λe^(−λx) for x ≥ 0 (Exponential distribution) Part (a) — Derive the Random Variate Generator Step 1: Find the CDF by integrating f(x) from 0 to x F(x) = ∫₀ˣ λe^(−λt) dt = λ × [−(1/λ)e^(−λt)]₀ˣ = [−e^(−λt)]₀ˣ = −e^(−λx) − (−e^0) = 1 − e^(−λx) Step 2: Set F(x) = r (random number) and solve for x r = 1 − e^(−λx) e^(−λx) = 1 − r Taking natural log of both sides: −λx = ln(1 − r) x = −(1/λ) × ln(1 − r) Generator: X = −(1/λ) × ln(1 − r) Since (1 − r) is also uniform on [0,1] when r is uniform on [0,1], we can equivalently write: X = −(1/λ) × ln(r). Both forms are correct. Answer (a): The variate generator is X = −(1/λ)·ln(1 − r), or equivalently X = −(1/λ)·ln(r). Part (b) — Generate Variates for Given Random Numbers (λ = 1 assumed) Using X = −ln(1 − r) with λ = 1 for each random number: r 1 − r ln(1 − r) X = −ln(1 − r) 0.2345 0.7655 −0.2674 0. 0.00667 0.99333 −0.00669 0. 0.7895 0.2105 −1.5578 1. 0.4356 0.5644 −0.5715 0.
Question 6: Hypothesis Testing & Confidence Intervals — Defective Rate Setup Sample size: n = 100 Defective units found: x = 22 Sample proportion: p̂ = 22/100 = 0. Claimed population defective rate (null): p₀ = 0.10 We test whether the true defective rate EXCEEDS 10%. Part (a) — Hypothesis Test at α = 0. Step 1: State the hypotheses H₀: p = 0.10 (defective rate is 10% — no problem) H₁: p > 0.10 (defective rate exceeds 10% — right-tailed test) Step 2: Check conditions for the Z-test for proportions np₀ = 100 × 0.10 = 10 ≥ 5 ✓ n(1−p₀) = 100 × 0.90 = 90 ≥ 5 ✓ Conditions met — we can use the normal approximation. Step 3: Compute the test statistic The standard error under H₀ uses p₀ (not p̂): SE = √(p₀(1−p₀)/n) = √(0.10 × 0.90 / 100) = √(0.0009) = 0.03 Z = (p̂ − p₀) / SE = (0.22 − 0.10) / 0.03 = 0.12 / 0.03 = 4. Step 4: Find critical value at α = 0.10, right-tailed From the Z-table: Z_α = Z₀.₁₀ = 1.282 Reject H₀ if Z_calculated > 1. Z_calculated = 4.0 > Z_critical = 1. Answer (a): REJECT H₀. At the 10% significance level, there is sufficient evidence to conclude that the true defective rate exceeds 10%. The production line has a statistically significant quality problem. Part (b) — The p-value What is the p-value? The p-value is the probability of observing a test statistic as extreme as (or more extreme than) what we observed, assuming H₀ is true. A very small p-value provides strong
evidence against H₀. Compute p-value for right-tailed test with Z = 4. p-value = P(Z > 4.0) where Z ~ N(0,1) From standard normal tables: P(Z < 4.0) = 0. p-value = 1 − 0.99997 = 0. Answer (b): p-value ≈ 0.00003 (0.003%). This is far below α = 0.10 — confirming extremely strong evidence against H₀. The result is highly statistically significant. Part (c) — 99% Confidence Interval for p What is a Confidence Interval? A confidence interval (CI) gives a range of plausible values for the true population parameter. A 99% CI means that if we repeated the sampling many times, 99% of the constructed intervals would contain the true parameter. Step 1: For CI we use p̂ (not p₀) in the standard error SE_CI = √(p̂(1−p̂)/n) = √(0.22 × 0.78 / 100) = √(0.1716 / 100) = √0.001716 = 0. Step 2: Find the critical Z value for 99% CI For 99% CI: α = 0.01, α/2 = 0.005 Z_{α/2} = Z_{0.005} = 2.576 (from Z-table) Step 3: Construct the interval CI = p̂ ± Z_{α/2} × SE_CI = 0.22 ± 2.576 × 0.04143 = 0.22 ± 0.1067 Lower bound: 0. − 0.1067 = 0.1133 Upper bound: 0.22 + 0.1067 = 0. Answer (c): 99% CI = (0.1133, 0.3267). We are 99% confident the true defective rate lies between 11.33% and 32.67%. Note that 10% is NOT in this interval, consistent with our rejection of H₀.