Probability & Applied Statistics · Lab 01

Chapter 3: Probability Fundamentals

A computational manual bridging classical probability theory and Python implementation. Designed for precise study, rigorous computation, and step-by-step lecture review.

Before Lab 1 — Python from Zero

Students are not expected to know Python before using this manual. Only a few ideas are needed:

  • A variable stores a value: x = 5.
  • Use +, -, *, / for arithmetic.
  • Use ** for powers; ** 0.5 gives a square root.
  • Use parentheses to control the order of calculation.
  • Use print(...) to display a result.
  • Use round(value, digits) only to make displayed answers easier to read.
  • Graph examples use matplotlib because graphing requires plotting software.
Python
x = 5
y = 3

answer = (x + y) / 2

print("Answer:", answer)

Expected Output

Output
Answer: 4.0

3.1 Basic Concepts of Probability

Case 3.1.1 — Sample Space

When do we use this?

Use a sample space to list all possible outcomes of a probability experiment.

Mathematical Equations

P(E)=Number of favorable outcomesNumber of possible outcomesP(E) = \frac{\text{Number of favorable outcomes}}{\text{Number of possible outcomes}}

P(Ec)=1−P(E)P(E^{c}) = 1 - P(E)

Worked Lecture Example

A coin is tossed and then a die is rolled. There are 2×6=122 \times 6 = 12 equally likely outcomes.

Step 1 — Count the outcomes

The coin has 2 outcomes and the die has 6.

2 × 6 = 12

Step 2 — Define the event

Tail AND odd gives T1, T3, T5: three outcomes.

P(Tail and odd) = 3 / 12 = 0.25

Step 3 — Find the complement

Subtract from 1.

P(complement) = 1 - 0.25 = 0.75

Final Result

P(Tail and odd) = 0.25; complement = 0.75.

Simple Python Code

Python
probability = 3 / 12
complement = 1 - probability

print(probability)
print(complement)

Expected Output

Output
0.25
0.75

Case 3.1.2 — Empirical Probability

When do we use this?

Use empirical probability when probabilities are based on observed frequencies.

Mathematical Equation

P(E)=Frequency of eventTotal frequencyP(E) = \frac{\text{Frequency of event}}{\text{Total frequency}}

Worked Lecture Example

Lecture survey counts are serious 123, moderate 115, not a problem 82.

Response categoryFrequencyRelative probability
Serious123123/320=0.384375123 / 320 = 0.384375
Moderate115115/320=0.359375115 / 320 = 0.359375
Not a problem8282/320=0.25625082 / 320 = 0.256250
Total320∑P(E)=1.000000\sum P(E) = 1.000000

Step 1 — Find the total

Add all responses.

Total = 123 + 115 + 82 = 320

Step 2 — Find the probability of serious

Divide 123 by 320.

P(serious) = 123 / 320 = 0.384375

Final Result

P(serious) = 0.384375.

Simple Python Code

Python
probability = 123 / 320
print(probability)

Expected Output

Output
0.384375

Case 3.1.3 — Fundamental Counting Principle

When do we use this?

Use the counting principle when a process has several stages with a fixed number of choices at each stage.

Mathematical Equation

Total outcomes=n1×n2×⋯×nk\text{Total outcomes} = n_{1} \times n_{2} \times \cdots \times n_{k}

Worked Lecture Example

An eight-digit ID allows 10 digits in every position and repetition is allowed.

Step 1 — Count all IDs

Multiply 10 choices eight times.

10⁸ = 100,000,000

Step 2 — Find the probability of one specific ID

Only one outcome matches a specified ID.

P = 1 / 100,000,000 = 0.00000001

Final Result

There are 100,000,000 possible IDs; one specific ID has probability 0.00000001.

Simple Python Code

Python
total = 10 ** 8
probability = 1 / total

print("Total:", total)
print("Probability:", probability)

Expected Output

Output
Total: 100000000
Probability: 1e-08

3.2 Conditional Probability and the Multiplication Rule

Case 3.2.1 — Conditional Probability

When do we use this?

Use conditional probability when the probability of one event is calculated under the condition that another event has already occurred.

Mathematical Equation

P(A∣B)=P(A∩B)P(B)P(A \mid B) = \frac{P(A \cap B)}{P(B)}

Worked Lecture Example

In the lecture table, 72 children are in the gene group and 33 of them have high IQ.

Group partitionCountConditional ratio
High IQ and gene3333/72≈0.458333 / 72 \approx 0.4583
Normal IQ and gene3939/72≈0.541739 / 72 \approx 0.5417
Total gene group721.00001.0000

Step 1 — Identify the conditioned group

The denominator is the 72 children with the gene.

Step 2 — Calculate the conditional probability

33 of those 72 have high IQ.

P(high IQ | gene) = 33 / 72 = 0.4583

Final Result

Conditional probability ≈ 0.4583.

Simple Python Code

Python
probability = 33 / 72
print(round(probability, 4))

Expected Output

Output
0.4583

Case 3.2.2 — Multiplication Rule

When do we use this?

Use the multiplication rule for probabilities of events occurring together or in sequence.

Mathematical Equation

P(A and B)=P(A)×P(B∣A)P(A \text{ and } B) = P(A) \times P(B \mid A)

Worked Lecture Example

Find the probability of drawing a king and then a queen without replacement.

Step 1 — First draw

There are 4 kings among 52 cards.

P(K) = 4 / 52

Step 2 — Second draw

After one card is removed, 51 remain and all 4 queens remain.

P(Q | K) = 4 / 51

Step 3 — Multiply

Multiply the two probabilities.

P(K then Q) = (4/52)(4/51) = 0.006033

Final Result

P(king then queen) ≈ 0.006033.

Simple Python Code

Python
probability = (4/52) * (4/51)
print(round(probability, 6))

Expected Output

Output
0.006033

Case 3.2.3 — At Least One Success

When do we use this?

For independent repeated trials, use the complement when 'at least one' is easier to calculate through 'none'.

Mathematical Equation

P(at least one)=1−P(none)P(\text{at least one}) = 1 - P(\text{none})

Worked Lecture Example

Three independent procedures each have success probability 0.85.

Step 1 — Find failure probability

Subtract success probability from 1.

q = 1 - 0.85 = 0.15

Step 2 — Find all-success probability

Multiply 0.85 three times.

P(all success) = 0.85³ = 0.614125

Step 3 — Find no-success probability

Multiply 0.15 three times.

P(none) = 0.15³ = 0.003375

Step 4 — Find at least one

Use the complement.

P(at least one) = 1 - 0.003375 = 0.996625

Final Result

P(at least one success) = 0.996625.

Simple Python Code

Python
p = 0.85
q = 1 - p

all_success = p ** 3
none = q ** 3
at_least_one = 1 - none

print(all_success)
print(none)
print(at_least_one)

Expected Output

Output
0.6141249999999999
0.003375000000000001
0.996625

Formula Reference

ConceptFormulaApplication
ClassicalP(E)=n(E)/n(S)P(E) = n(E) / n(S)Equally likely sample space
ComplementP(Ec)=1−P(E)P(E^{c}) = 1 - P(E)Negation of event
EmpiricalP(E)=f/∑fP(E) = f / \sum fObserved sample tallies
Counting ruleN=n1×n2×⋯×nkN = n_{1} \times n_{2} \times \cdots \times n_{k}Multi-stage combinations
ConditionalP(A∣B)=P(A∩B)/P(B)P(A \mid B) = P(A \cap B) / P(B)Conditioned outcome space
MultiplicationP(A∩B)=P(A)⋅P(B∣A)P(A \cap B) = P(A) \cdot P(B \mid A)Joint / sequential draws
At least oneP(≥1)=1−(1−p)nP(\ge 1) = 1 - (1 - p)^{n}Repeated independent trials