Learn/R Programming/Statistical Analysis

Hypothesis Testing

Topic: Hypothesis Testing

Advertisement

Introduction

Hypothesis testing is a statistical method for making decisions about populations based on sample data.

T-Test

# One-sample t-test
t.test(x, mu = 0)

# Two-sample t-test
t.test(group1, group2)

# Paired t-test
t.test(before, after, paired = TRUE)

# With confidence interval
t.test(x, mu = 0, conf.level = 0.95)

Chi-Square Test

# Chi-square test of independence
chisq.test(matrix(c(10, 20, 30, 40), nrow = 2))

# Chi-square goodness of fit
chisq.test(c(10, 20, 30), p = c(1/3, 1/3, 1/3))

ANOVA

# One-way ANOVA
anova(lm(value ~ group, data = df))

# Or using aov
aov(value ~ group, data = df)

# Two-way ANOVA
aov(value ~ factor1 + factor2, data = df)

Interpretation

# Extract results
result <- t.test(x, mu = 0)
result$statistic    # t-value
result$p.value      # p-value
result$conf.int     # Confidence interval
result$estimate     # Sample mean

Summary

Hypothesis testing determines if results are statistically significant. Interpret p-values carefully.

Advertisement

Advertisement

Need More Practice?

Get personalized R programming help from ChatWhole's AI-powered platform.

Get Expert Help →