Arandom experimentis a mechanism that produces a definite outcome that cannot be predicted with certainty. Thesample spaceassociated with a random experiment is the set of all possible outcomes. Aneventis a subset of the sample space.
An eventEis said tooccuron a particular trial of the experiment if the outcome observed is an element of the setE.
EXAMPLE 1. Construct a sample space for the experiment that consists of tossing a single coin.
EXAMPLE 2. Construct a sample space for the experiment that consists of rolling a single die. Find the events that correspond to the phrases “an even number is rolled” and “a number greater than two is rolled.”
library(prob)
## 1. Sample Space : rolling a single die
rolldie(1)
# 2. Event 1 : an even number is rolled
S <- rolldie(1)
E1 <- subset(S, X1 %% 2 ==0); E1
# 3. Event 2 : a number greater than two is rolled.
S <- rolldie(1)
E2 <- subset(S, X1 > 2); E2
> # 1. Sample Space : rolling a single die
> rolldie(1)
## X1
## 1 1
## 2 2
## 3 3
## 4 4
## 5 5
## 6 6
##
> # 2. Event1 : an even number is rolled
> S <- rolldie(1)
> E1 <- subset(S, X1 %% 2 ==0); E1
## X1
## 2 2
## 4 4
## 6 6
> # 3. Event 2 : a number greater than two is rolled.
> S <- rolldie(1)
> E2 <- subset(S, X1 > 2); E2
## X1
## 3 3
## 4 4
## 5 5
## 6 6
1-1. Venn Diagram
A graphical representation of a sample space and events is a Venn diagram
EXAMPLE 3. A random experiment consists of tossing two coins.
Construct a sample space for the situation that the coins are indistinguishable, such as two brand new pennies.
Construct a sample space for the situation that the coins are distinguishable, such as one a penny and the other a nickel.
[ Solution ]
two same coins : two head -> 2h, two tails -> 2t, 2 different faces : d =>S={2h,2t,d}
two different coins (penny, nickel) : S={hh,th,ht,tt}
1-2. Venn Diagram Plot in R
type of count data.
A 450
B 1800
A and B both 230
I want to develop a colorful (possibly semi-transparency at intersections) like the following Venn diagram.
require(venneuler)
v <- venneuler(c(A=450, B=1800, "A&B"=230))
plot(v)
A device that can be helpful in identifying all possible outcomes of a random experiment, particularly one that can be viewed as proceeding in stages, is what is called a tree diagram.
EXAMPLE 4. Construct a sample space that describes all three-child families according to the genders of the children with respect to birth order.
The line segments are called branches of the tree. The right ending point of each branch is called a node. The nodes on the extreme right are the final nodes; to each one there corresponds an outcome, as shown in the figure.
Theprobability of an outcomeein a sample spaceSis a numberpbetween 0 and 1 that measures the likelihood thatewill occur on a single trial of the corresponding random experiment. The valuep=0corresponds to the outcomeebeing impossible and the valuep=1corresponds to the outcomeebeing certain.
Theprobability of an eventAis the sum of the probabilities of the individual outcomes of which it is composed. It is denotedp(A).
If an event E is E={e1,e2,...,ek}, then
P(E)=P(e1)+P(e2)+⋅⋅⋅+P(ek)
EXAMPLE 5. A coin is called “balanced” or “fair” if each side is equally likely to land up. Assign a probability to each outcome in the sample space for the experiment that consists of tossing a single fair coin.
> tosscoin(1, makespace = TRUE)
## toss1 probs
## 1 H 0.5
## 2 T 0.5
EXAMPLE 6. A die is called “balanced” or “fair” if each side is equally likely to land on top. Assign a probability to each outcome in the sample space for the experiment that consists of tossing a single fair die. Find the probabilities of the events E : “an even number is rolled” and T : “a number greater than two is rolled.”
[ Solution ] S={1,2,3,4,5,6}
E={2,4,6} , P(E)=3/6=1/2
T={3,4,5,6} , P(T)=4/6=2/3
library(prob)
# 1. Sample Space
S <- rolldie(1, makespace = TRUE); S
# 2. P(E)
E <- subset(S, X1 %% 2 == 0); E
Prob(S, X1 %% 2 == 0) # or Prob(E)
# 3. P(T)
T <- subset(S, X1 > 2); T
Prob(S, X1 > 2) # or Prob(T)
two different coins : St={2h,ht,th,2t} , Et={2h,2t} => P(Et)=2/4=1/2
[ Solution 1 ]
library(prob)
a <- tosscoin(2, makespace = TRUE); a
S1 <- subset(a, toss1 == toss2); S1
S2 <- subset(a, toss1 != toss2); S2
S2[,1] <- "D" ; S2
S2[,2] <- "D" ; S2
# 1) Sample Space
S <- union(S1, S2)
S$probs <- 1/3; S
# 2) Probability that the coins match..
Prob(S, toss1 == "H" | toss2 =="T")
> a <- tosscoin(2, makespace = TRUE); a
## toss1 toss2 probs
## 1 H H 0.25
## 2 T H 0.25
## 3 H T 0.25
## 4 T T 0.25
>
> S1 <- subset(a, toss1 == toss2); S1
## toss1 toss2 probs
## 1 H H 0.25
## 4 T T 0.25
> S2 <- subset(a, toss1 != toss2); S2
## toss1 toss2 probs
## 2 T H 0.25
## 3 H T 0.25
>
> S2[,1] <- "D" ; S2
## toss1 toss2 probs
## 2 D H 0.25
## 3 D T 0.25
> S2[,2] <- "D" ; S2
## toss1 toss2 probs
## 2 D D 0.25
## 3 D D 0.25
> # 1) Sample Space
> S <- union(S1, S2); S
## toss1 toss2 probs
## 1 H H 0.25
## 2 D D 0.25
## 4 T T 0.25
>
> S$probs <- 1/3; S
## toss1 toss2 probs
## 1 H H 0.3333333
## 2 D D 0.3333333
## 4 T T 0.3333333
> Prob(S, toss1 == "H" | toss2 =="T")
## [1] 0.6666667
> # 2) Probability that the coins match..
> Prob(a, toss1 != toss2)
## [1] 0.5
[ Solution 2 ]
library(prob)
# 1. Sample Space
S <- tosscoin(2, makespace = TRUE); S
# 2. P(E)
Prob(S, toss1 == toss2)
> # 1. Sample Space
> S <- tosscoin(2, makespace = TRUE); S
## toss1 toss2 probs
## 1 H H 0.25
## 2 T H 0.25
## 3 H T 0.25
## 4 T T 0.25
> # 2. P(E)
> Prob(S, toss1 == toss2)
## [1] 0.5
EXAMPLE 8. The breakdown of the student body in a local high school according to race and ethnicity is 51% white, 27% black, 11% Hispanic, 6% Asian, and 5% for all others. A student is randomly selected from this high school. (To select “randomly” means that every student has the same chance of being selected.) Find the probabilities of the following events:
EXAMPLE 9. The student body in the high school considered in "Example 8" may be broken down into ten categories as follows: 25% white male, 26% white female, 12% black male, 15% black female, 6% Hispanic male, 5% Hispanic female, 3% Asian male, 3% Asian female, 1% male of other minorities combined, and 4% female of other minorities combined. A student is randomly selected from this high school. Find the probabilities of the following events:
> Prob <- as.table(prob); Prob
## w b h a o
## Male 0.25 0.12 0.06 0.03 0.01
## Female 0.26 0.15 0.05 0.03 0.04
>
> addmargins(Prob)
## w b h a o Sum
## Male 0.25 0.12 0.06 0.03 0.01 0.47
## Female 0.26 0.15 0.05 0.03 0.04 0.53
## Sum 0.51 0.27 0.11 0.06 0.05 1.00