2025-06-03

What is Hypothesis Testing?

Hypothesis testing is a part of inferential statistics where an assumption regarding a population is validated through data from a sample of the population being studied.The test determines whether the pattern observed in the sample can be explained by coincidence or other variables. Based on the results of the testing, the hypothesis is either selected or rejected.

Null Hypothesis

Two different hypothesis are tested.The null hypothesis states that there is no effect or no difference between the control and the study group. Example of Null Hypothesis claiming that population mean is 10 : \[ H_0 : \mu = 10 \]

Alternative Hypothesis

The alternative hypothesis is the opposite of the null hypothesis, stating that there is an effect or a difference among the groups. Example of Alternate Hypothesis claiming that population mean is not 10 : \[ H_a : \mu \neq 10 \]

Rejecting or accepting hypothesis

Typically, if the p-value less than 0.05, it is considered to be statistically significant, hence the null hypothesis should be rejected. A p-value greater than 0.05 means that difference is not statistically significant, and the null hypothesis is not rejected.

Density Plot with Plotly using mtcars

Considering the p-value of this test (0.8019) is above 0.05, we are unable to reject the null hypothesis that the mean MPG of the two random samples are equal.

Boxplot with ggplot2

Boxplot with ggplot2

sample_data = data.frame(mpg = c(group1, group2), 
              sample_mean = factor(rep(c("Sample 1", "Sample 2"), 
                                       each = 10)))

plot_boxplot = ggplot(sample_data, 
                      aes(x = sample_mean, y = mpg, fill = sample_mean)) +
  geom_boxplot(fill = c("lightpink", "lavender")) +
  stat_summary(fun = mean, geom = "point", shape = 20, size = 3, 
               color = "darkred") +
  labs(
    title = paste("Boxplot of MPG for Two Random Samples\n t = ", 
                  t_stat, ", p = ", p_val),
    x = "Sample",
    y = "Miles Per Gallon (MPG)"
  ) +
  theme_minimal()

Histogram with ggplot2