1.
Sample Spaces and Events
Code:
o tosscoin(1) and tosscoin(3): Simulates tossing one or three coins. It provides the
sample space (e.g., Heads or Tails outcomes).
o rolldie(1) and rolldie(3): Simulates rolling one or three dice, providing all possible
outcomes.
o cards(): Generates the standard deck of cards' sample space.
Sampling from Urns:
o urnsamples(1:3, size=2, replace=TRUE): Sampling 2 items with replacement from
balls labeled 1, 2, 3.
o urnsamples(1:3, size=2, replace=FALSE): Sampling 2 items without replacement.
Events:
o subset func ons are used to filter specific outcomes based on condi ons (e.g., cards
of "Heart" suit or rolling a sum > 16 with 3 dice).
2. Set Opera ons
Code:
o Union: Combines two sets (e.g., all cards that are either "Hearts" or rank 7–9).
o Intersec on: Finds common elements between two sets.
o Set Difference: Elements in one set but not in the other.
Purpose: Helps analyze rela onships and probabili es between sets of outcomes.
3. Calcula ng Probabili es
Code:
o Prob(A) calculates the probability of an event AAA in the sample space.
o Prob(union(A, B)), Prob(intersect(A, B)): Probabili es of combined or overlapping
events.
o Condi onal Probability: Prob(A, given = B) calculates P(A∣B)P(A|B)P(A∣B).
Example:
o When rolling two dice:
AAA: Outcomes where the dice values match.
BBB: Sum of dice ≥ 8.
The code calculates P(A∣B)P(A|B)P(A∣B) and P(B∣A)P(B|A)P(B∣A).
4. Descrip ve Sta s cs
Code:
o Measures of Central Tendency:
mean, median, Mode: Describes the central value of the dataset.
mean(range()): Calculates the midrange value.
o Measures of Varia on:
range, var, sd: Computes variability in the dataset.
Coefficient of Varia on (CV): Expresses variability rela ve to the mean.
o Measures of Shape:
skewness, kurtosis: Measures asymmetry and the peakedness of the dataset
distribu on.
Dataset: UKDriverDeaths (pre-loaded R dataset).
o Shows monthly UK road accident deaths.
5. Exploratory Data Analysis
Code:
o Stem-and-leaf plots: Displays data distribu on.
o Boxplots: Visualizes data variability and poten al outliers.
6. Hypothesis Tes ng
Code:
o z.test: Performs hypothesis tes ng for popula on means.
Large-sample z-tests are used with specified sample means, popula on
means, standard devia ons, and confidence levels.
o Varia ons include one-sided and two-sided tests.
Example:
o Tes ng if a sample mean significantly differs from a hypothesized mean under
specified condi ons.