Challenge - 5 Problems
Chi-squared Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of a basic Chi-squared test in R
What is the output of this R code performing a Chi-squared test on a 2x2 table?
R Programming
data <- matrix(c(10, 20, 20, 40), nrow = 2) result <- chisq.test(data) result$p.value
Attempts:
2 left
💡 Hint
Check the p-value returned by chisq.test for the given matrix.
✗ Incorrect
The chisq.test function calculates the Chi-squared test and returns a p-value. For this data, the observed frequencies do not exactly match the expected frequencies under independence, so the p-value is approximately 0.0455, indicating borderline evidence against independence.
🧠 Conceptual
intermediate1:30remaining
Understanding Chi-squared test assumptions
Which of the following is NOT an assumption of the Chi-squared test in R?
Attempts:
2 left
💡 Hint
Think about the type of data Chi-squared test is designed for.
✗ Incorrect
The Chi-squared test does not require data to be normally distributed. It is used for categorical data and assumes independence and sufficient expected frequencies.
🔧 Debug
advanced2:00remaining
Identify the error in Chi-squared test code
What error will this R code produce?
R Programming
data <- matrix(c(5, 3, 2), nrow = 3) chisq.test(data)
Attempts:
2 left
💡 Hint
Check the shape of the matrix and requirements for chisq.test.
✗ Incorrect
chisq.test requires a matrix with at least 2 rows and 2 columns. The given matrix has 3 rows but only 1 column, causing an error.
🚀 Application
advanced3:00remaining
Calculate Chi-squared statistic manually
Given the observed counts matrix in R:
obs <- matrix(c(30, 10, 20, 40), nrow=2)
Which code correctly calculates the Chi-squared test statistic manually (without using chisq.test)?
Attempts:
2 left
💡 Hint
Expected counts are calculated by multiplying row and column sums divided by total sum.
✗ Incorrect
The expected counts are calculated as the outer product of row sums and column sums divided by total sum. The Chi-squared statistic sums the squared differences divided by expected counts.
❓ Predict Output
expert2:30remaining
Output of Chi-squared test with simulated data
What is the output of this R code snippet?
R Programming
set.seed(123) data <- matrix(sample(1:100, 9), nrow=3) result <- chisq.test(data) round(result$statistic, 2)
Attempts:
2 left
💡 Hint
Run the code with the given seed to get the Chi-squared statistic.
✗ Incorrect
Using set.seed(123) ensures reproducible random data. The Chi-squared statistic calculated by chisq.test on this matrix is approximately 5.12.