install.packages(“rmarkdown”)
# sets wd to the path on my computer;
setwd("C:\\Users\\hmon1\\Desktop\\10B+Homework\\") #this is where you downloaded the HW1.csv file
# loads in data for the full population
pop<-read.csv("HW12.csv")
# sets the seed for the random number generator
set.seed(48183130) #use your student ID instead of 12345678
# assigns a "random" sample of 100 from the population to 'data'
sample<-pop[sample(1:nrow(pop), 100, replace=FALSE),]
# produces a cross tabulation table. Use this to fill in your table
crosstab <-table(sample$X,sample$G)
crosstab
##
## F M
## A 18 10
## B 18 27
## C 16 11
# chi-squared test
chisq.test(crosstab)
##
## Pearson's Chi-squared test
##
## data: crosstab
## X-squared = 4.8594, df = 2, p-value = 0.08806
# Cramer's V
p <- ncol(crosstab)
q <- nrow(crosstab)
n <- sum(crosstab)
chi2 <- unname(chisq.test(crosstab, correct = FALSE)$statistic)
CV <- sqrt(chi2/(n*(min(p | q))-1))
CV
## [1] 0.2215514