library(readxl)
## Warning: package 'readxl' was built under R version 4.0.5
myData <- read_excel("Ch3_Q23_Data_File.xlsx")
myData
## # A tibble: 186 x 3
## Student Sex Feasible
## <dbl> <chr> <chr>
## 1 1 female yes
## 2 2 female yes
## 3 3 female yes
## 4 4 female yes
## 5 5 female yes
## 6 6 female yes
## 7 7 female yes
## 8 8 female yes
## 9 9 female yes
## 10 10 female yes
## # ... with 176 more rows
n =table(myData$Sex, myData$Feasible)
n
##
## no yes
## female 32 68
## male 37 49
na2 = n[1, 1]+n[1,2]
sprintf("%s students are female.", na2)
## [1] "100 students are female."
na3 = n[1,2] + n[2,2]
sprintf("%s students felt that men and women can be just friends", na3)
## [1] "117 students felt that men and women can be just friends"
###b-1. What is the likelihood that a male student feels that men and women can be just friends? (Report the proportion rounded to 2 decimal places.)
###b-2. What is the likelihood that a female student feels that men and women can be just friends? (Report the proportion rounded to 2 decimal places.)
total = n[1, 1]+ n[1,2]
p = round(n[1, 2]/total, 2)
p
## [1] 0.68
###c.ย The figure below shows the stacked column chart for the data.
barplot(n, main="Sex and Friendship",
col = c('pink', 'blue'), legend = rownames(n), xlab='Can be friends',
ylab = 'Count', ylim = c(0, 125))