đ Introduction
Statistical tests are mathematical procedures used to determine whether observed data supports a particular hypothesis. They help researchers and analysts decide whether differences, relationships, or patterns found in a dataset are statistically significant or simply due to random chance. R provides a wide range of built-in functions for performing statistical tests efficiently.
Information
đ¯ Why Learn Statistical Tests?
- Test research hypotheses.
- Compare groups and populations.
- Identify significant relationships.
- Support data-driven decision-making.
- Validate analytical results.
đ Types of Statistical Tests
đ Common Statistical Tests in R
| Test | Purpose | Function |
|---|---|---|
| One-Sample t-Test | Compare sample mean with a known value. | t.test() |
| Two-Sample t-Test | Compare means of two independent groups. | t.test() |
| Paired t-Test | Compare paired observations. | t.test() |
| Chi-Square Test | Test association between categorical variables. | chisq.test() |
| ANOVA | Compare means of multiple groups. | aov() |
| Correlation Test | Measure linear relationship. | cor.test() |
| Wilcoxon Test | Non-parametric alternative to the t-test. | wilcox.test() |
| Shapiro-Wilk Test | Check data normality. | shapiro.test() |
đ Sample Dataset
Student Marks
marks <- c(
78, 82, 85, 90,
88, 92, 79, 84,
87, 91
)
print(marks)đ One-Sample t-Test
A one-sample t-test compares the sample mean against a known or hypothesized population mean.
One-Sample t-Test
t.test(
marks,
mu = 80
)đĨ Two-Sample t-Test
A two-sample t-test compares the means of two independent groups.
Independent Samples t-Test
groupA <- c(
82,85,88,90,91
)
groupB <- c(
75,78,80,81,79
)
t.test(
groupA,
groupB
)đ Paired t-Test
A paired t-test compares measurements taken from the same subjects before and after an intervention.
Paired t-Test
before <- c(
65,70,72,75,80
)
after <- c(
70,75,76,80,85
)
t.test(
before,
after,
paired = TRUE
)đ Chi-Square Test
The chi-square test evaluates whether two categorical variables are associated.
Chi-Square Test
survey <- matrix(
c(
30,20,
25,35
),
nrow = 2,
byrow = TRUE
)
chisq.test(survey)đ Analysis of Variance (ANOVA)
ANOVA compares the means of three or more groups.
One-Way ANOVA
scores <- data.frame(
Marks = c(
78,82,85,
88,90,91,
72,75,77
),
Group = factor(
c(
"A","A","A",
"B","B","B",
"C","C","C"
)
)
)
model <- aov(
Marks ~ Group,
data = scores
)
summary(model)đ Correlation Test
The correlation test measures the strength and direction of a relationship between two numerical variables.
Pearson Correlation Test
hours <- c(
2,3,4,5,6
)
marks <- c(
60,68,75,82,90
)
cor.test(
hours,
marks
)đ Wilcoxon Rank-Sum Test
The Wilcoxon test is a non-parametric alternative to the t-test when normality assumptions are not met.
Wilcoxon Test
groupA <- c(
82,85,88,90,91
)
groupB <- c(
75,78,80,81,79
)
wilcox.test(
groupA,
groupB
)đ Shapiro-Wilk Normality Test
The Shapiro-Wilk test checks whether data follows a normal distribution.
Normality Test
shapiro.test(
marks
)đ Understanding p-Values
| p-Value | Interpretation |
|---|---|
| p < 0.05 | Reject the null hypothesis. |
| p âĨ 0.05 | Fail to reject the null hypothesis. |
Tip
đ Confidence Intervals
Most statistical test functions in R also return confidence intervals that estimate the range within which the true population parameter is likely to fall.
Confidence Interval Example
result <- t.test(
marks,
mu = 80
)
result$conf.intđ Choosing the Right Statistical Test
| Scenario | Recommended Test |
|---|---|
| Compare one sample with a known mean. | One-Sample t-Test. |
| Compare two independent groups. | Independent Two-Sample t-Test. |
| Compare before-and-after measurements. | Paired t-Test. |
| Compare three or more group means. | ANOVA. |
| Analyze categorical data. | Chi-Square Test. |
| Measure relationship between numeric variables. | Correlation Test. |
| Data is not normally distributed. | Wilcoxon Test. |
đ Real-World Example
A teacher wants to determine whether a new teaching method improves student performance by comparing marks before and after the course.
Teaching Method Evaluation
before <- c(
68,72,75,70,74,
71,73,69
)
after <- c(
75,79,81,77,80,
76,82,74
)
result <- t.test(
before,
after,
paired = TRUE
)
print(result)đ Statistical Testing Workflow
đ Common Statistical Test Functions
| Function | Description |
|---|---|
| t.test() | Performs one-sample, two-sample, and paired t-tests. |
| chisq.test() | Performs the chi-square test. |
| aov() | Performs analysis of variance. |
| cor.test() | Performs a correlation test. |
| wilcox.test() | Performs the Wilcoxon test. |
| shapiro.test() | Tests normality. |
â ī¸ Common Mistakes
| Mistake | Explanation | Solution |
|---|---|---|
| Choosing the wrong statistical test | May produce misleading conclusions. | Select a test based on the data type, study design, and assumptions. |
| Ignoring test assumptions | Violations can invalidate results. | Check assumptions such as normality and independence before testing. |
| Misinterpreting the p-value | A small p-value does not measure the size or importance of an effect. | Interpret the p-value alongside effect size and confidence intervals. |
| Using multiple tests without adjustment | Increases the risk of false-positive results. | Apply appropriate corrections when performing multiple comparisons. |
đĄ Best Practices
- Clearly define the null and alternative hypotheses before analysis.
- Verify assumptions before choosing a statistical test.
- Report the test statistic, p-value, and confidence interval.
- Interpret statistical significance together with practical significance.
- Document all analysis steps for reproducibility.
Best Practice
đ Summary
Statistical tests are essential tools for hypothesis testing and data analysis. In this chapter, you learned how to perform one-sample, two-sample, and paired t-tests, chi-square tests, ANOVA, correlation tests, Wilcoxon tests, and Shapiro-Wilk normality tests using R. You also explored p-values, confidence intervals, selecting appropriate tests, and interpreting results. Mastering statistical tests enables you to make informed, evidence-based decisions from data and forms the foundation for advanced statistical modeling and research.