0
0
R Programmingprogramming~20 mins

Correlation analysis in R Programming - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Correlation Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2: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))
A0.5
B0
C-1
D1
Attempts:
2 left
💡 Hint
Pearson correlation measures linear relationship strength between two variables.
Predict Output
intermediate
2: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))
A1
B0.9
C0.7
D0.5
Attempts:
2 left
💡 Hint
Spearman correlation uses ranks and handles ties by averaging ranks.
Predict Output
advanced
2: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))
A
[[1,1]] 1, [[1,2]] 0.98, [[1,3]] 0.99
[[2,1]] 0.98, [[2,2]] 1, [[2,3]] 0.98
[[3,1]] 0.99, [[3,2]] 0.98, [[3,3]] 1
B
[[1,1]] 1, [[1,2]] 0.99, [[1,3]] 1
[[2,1]] 0.99, [[2,2]] 1, [[2,3]] 0.99
[[3,1]] 1, [[3,2]] 0.99, [[3,3]] 1
C
[[1,1]] 1, [[1,2]] NA, [[1,3]] 1
[[2,1]] NA, [[2,2]] 1, [[2,3]] NA
[[3,1]] 1, [[3,2]] NA, [[3,3]] 1
D
[[1,1]] 1, [[1,2]] 1, [[1,3]] 1
[[2,1]] 1, [[2,2]] 1, [[2,3]] 1
[[3,1]] 1, [[3,2]] 1, [[3,3]] 1
Attempts:
2 left
💡 Hint
Using 'complete.obs' excludes rows with any NA in any variable pair.
Predict Output
advanced
2: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))
A-0.9
B-0.4
C0.0
D0.8
Attempts:
2 left
💡 Hint
Partial correlation measures relationship between x and y after removing effect of z.
🧠 Conceptual
expert
3: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))
AThe correlation is about 0.03 and is statistically significant at 0.05 level.
BThe correlation is about 0.97 but not statistically significant at 0.05 level.
CThe correlation is about 0.97 and is statistically significant at 0.05 level.
DThe correlation is about 0.03 and not statistically significant at 0.05 level.
Attempts:
2 left
💡 Hint
Check both the correlation estimate and the p-value to interpret significance.