library(dplyr)
library(ggplot2)
# Distribution of responses based on question type
ask %>%
count(question_class, response)
# Visualize relative frequencies of responses based on question type
ggplot(ask, aes(x = question_class, fill = response)) +
geom_bar(position = "fill")
# Perform chi-square test
(test <- chisq.test(table(ask$question_class, ask$response)))
# Check the test's assumption around sufficient expected observations
# per table cell.
test$expected
Run the code above in your browser using DataLab