Challenge - 5 Problems
Correlation Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Calculate Pearson correlation coefficient
What is the output of this R code snippet that calculates the Pearson correlation between two numeric vectors?
R Programming
x <- c(1, 2, 3, 4, 5) y <- c(2, 4, 6, 8, 10) correlation <- cor(x, y, method = "pearson") print(round(correlation, 2))
Attempts:
2 left
💡 Hint
Pearson correlation measures linear relationship strength between two variables.
✗ Incorrect
The vectors x and y have a perfect positive linear relationship (y is exactly 2 times x), so the Pearson correlation is 1.
❓ Predict Output
intermediate2:00remaining
Spearman correlation with tied ranks
What is the output of this R code that calculates Spearman correlation for vectors with tied values?
R Programming
a <- c(1, 2, 2, 3, 4) b <- c(5, 6, 6, 7, 8) result <- cor(a, b, method = "spearman") print(round(result, 2))
Attempts:
2 left
💡 Hint
Spearman correlation uses ranks and handles ties by averaging ranks.
✗ Incorrect
Despite ties, the ranks of a and b perfectly correspond, so Spearman correlation is 1.
❓ Predict Output
advanced2:00remaining
Correlation matrix with NA values
What is the output of this R code that computes correlation matrix with missing values?
R Programming
data <- data.frame( v1 = c(1, 2, NA, 4), v2 = c(2, NA, 6, 8), v3 = c(5, 6, 7, 8) ) result <- cor(data, use = "complete.obs") print(round(result, 2))
Attempts:
2 left
💡 Hint
Using 'complete.obs' excludes rows with any NA in any variable pair.
✗ Incorrect
Only rows without any NA in the pair are used for each correlation. The resulting matrix has values close to 1 but less than 1 due to fewer data points.
❓ Predict Output
advanced2:00remaining
Partial correlation calculation
What is the output of this R code that calculates the partial correlation between x and y controlling for z?
R Programming
library(ppcor) x <- c(1, 2, 3, 4, 5) y <- c(2, 1, 4, 3, 5) z <- c(5, 4, 3, 2, 1) result <- pcor.test(x, y, z) print(round(result$estimate, 2))
Attempts:
2 left
💡 Hint
Partial correlation measures relationship between x and y after removing effect of z.
✗ Incorrect
The partial correlation is negative because controlling for z reverses the apparent positive association between x and y.
🧠 Conceptual
expert3:00remaining
Interpreting correlation significance test output
Given this R output from cor.test(x, y), which statement correctly interprets the p-value and correlation estimate?
R Programming
x <- c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10) y <- c(2, 1, 4, 3, 5, 7, 6, 8, 9, 10) test <- cor.test(x, y) print(test$p.value) print(round(test$estimate, 2))
Attempts:
2 left
💡 Hint
Check both the correlation estimate and the p-value to interpret significance.
✗ Incorrect
The correlation estimate is close to 0.97, indicating strong positive correlation, and the p-value is very small, so it is statistically significant.