📖 Scenario: You are a scientist studying the effect of a new fertilizer on plant growth. You have measured the heights of plants with and without the fertilizer. You want to check if the fertilizer makes a significant difference in plant height.
🎯 Goal: Learn how to perform a t-test in R to compare two groups of data and interpret the result.
📋 What You'll Learn
Create two numeric vectors with exact plant height values
Create a variable to hold the significance level
Use the t.test() function to compare the two groups
Print the p-value from the t-test result
💡 Why This Matters
🌍 Real World
Scientists and researchers use t-tests to check if two groups have different averages, like testing new medicines or fertilizers.
💼 Career
Data analysts and scientists often perform t-tests to make decisions based on data and prove if changes have real effects.
Progress0 / 4 steps
1
Create the plant height data
Create two numeric vectors called control and fertilized with these exact values: control = c(15, 16, 14, 15, 16), fertilized = c(18, 19, 17, 20, 18).
R Programming
Hint
Use the c() function to create numeric vectors with the exact values given.
2
Set the significance level
Create a numeric variable called alpha and set it to 0.05 to represent the significance level.
R Programming
Hint
Just assign the value 0.05 to a variable named alpha.
3
Perform the t-test
Use the t.test() function with control and fertilized as inputs and save the result in a variable called test_result.
R Programming
Hint
Use t.test(control, fertilized) and assign it to test_result.
4
Print the p-value
Print the p-value from test_result using print() and accessing the $p.value element.
R Programming
Hint
Use print(test_result$p.value) to show the p-value.
Practice
(1/5)
1.
What does a t-test primarily compare in two groups?
easy
A. The difference between their medians
B. The difference between their averages
C. The total number of observations
D. The variance of each group
Solution
Step 1: Understand the purpose of a t-test
A t-test is used to compare the means (averages) of two groups to see if they are different.
Step 2: Identify what is compared
The test focuses on the average values, not medians, counts, or variances.
Final Answer:
The difference between their averages -> Option B
Quick Check:
t-test compares means = A [OK]
Hint: Remember: t-test checks averages, not medians or counts [OK]
Common Mistakes:
Confusing mean with median
Thinking it compares counts
Assuming it compares variances
2.
Which of the following is the correct way to run a t-test in R comparing two numeric vectors x and y?
easy
A. t_test(x, y)
B. ttest(x, y)
C. t.test(x, y)
D. test.t(x, y)
Solution
Step 1: Recall the correct function name in R
The built-in function for t-test in R is t.test().
Step 2: Check the syntax for comparing two vectors
Using t.test(x, y) compares the two numeric vectors correctly.
Final Answer:
t.test(x, y) -> Option C
Quick Check:
Correct function is t.test() = A [OK]
Hint: Use exact function name t.test() with dot [OK]