0
0
R Programmingprogramming~20 mins

t-test in R Programming - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
t-test Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of a one-sample t-test in R
What is the output of this R code snippet?
R Programming
set.seed(123)
x <- rnorm(10, mean=5, sd=2)
t.test.result <- t.test(x, mu=5)
round(t.test.result$p.value, 3)
A0.564
B0.045
C0.123
D0.001
Attempts:
2 left
💡 Hint
Check the p-value from the t.test object and round it to 3 decimals.
🧠 Conceptual
intermediate
2:00remaining
Understanding paired t-test in R
Which option correctly describes what this R code does?
R Programming
before <- c(200, 195, 210, 190, 205)
after <- c(198, 192, 215, 188, 207)
t.test(before, after, paired=TRUE)
APerforms a paired t-test comparing means of before and after measurements on the same subjects.
BPerforms an independent two-sample t-test assuming equal variances.
CPerforms a one-sample t-test comparing before to zero.
DPerforms a paired t-test but ignores pairing and treats data as independent.
Attempts:
2 left
💡 Hint
Look at the paired=TRUE argument and the two vectors before and after.
🔧 Debug
advanced
2:00remaining
Identify the error in this two-sample t-test code
What error will this R code produce?
R Programming
group1 <- c(5, 7, 8, 6)
group2 <- c(6, 9, 7)
t.test(group1, group2, paired=TRUE)
AError: object 'paired' not found
BError: 'x' and 'y' must have the same length for paired t-test
CNo error, runs successfully and returns p-value
DError: cannot perform t-test on numeric vectors
Attempts:
2 left
💡 Hint
Check the lengths of group1 and group2 when paired=TRUE.
Predict Output
advanced
2:00remaining
Output of Welch Two Sample t-test in R
What is the output of this R code snippet?
R Programming
set.seed(42)
g1 <- rnorm(15, mean=10, sd=3)
g2 <- rnorm(20, mean=12, sd=5)
test <- t.test(g1, g2)
round(test$statistic, 2)
A-2.30
B1.45
C-1.45
D2.30
Attempts:
2 left
💡 Hint
Check the t-statistic value from the test object and round to 2 decimals.
📝 Syntax
expert
2:00remaining
Identify the syntax error in this t-test code
Which option contains the syntax error that will cause R to fail running the code?
At.test(x, mu=5, alternative='two.sided')
Bt.test(x, mu=5, alternative='greater')
Ct.test(x, mu=5, alternative='less')
Dt.test(x, mu=5 alternative='greater')
Attempts:
2 left
💡 Hint
Look for missing commas between arguments.