2026-04-12

What are we testing

  • Goal: to determine if an observe effect is statistically significant
  • Example: New company claims their battery last 1000 hours* Lets test 30 to see if they actually last less than that

define the hypothesis

  1. The Null Hypothesis (\(H_0\)): The status quo or “no effect” statement. \[H_0: \mu < 1000\]
  2. The Alternative Hypothesis (\(H_a\)): What are we trying to prove. \[H_a: \mu < 1000\] Significan Level (\(\alpha\)), 0.05

Test Statistic

To make a decision, calculate t-statistic. Errors our sample mean (\(\bar{x}\)) is away from hypothesized mean (\(\mu_0\)).

Formula written as:

\[t = \frac{\bar{x} - \mu_0}{s / \sqrt{n}}\] - \(\bar{x}\) = Sample Mean - \(s\) = Sample Standard Deviation - \(n\) = Sample Size

Visualizing Our Sample (ggplot1)

Time to test 30 batteries

library (ggplot2)
set.seed(123)
data = data.frame(hours = rnorm(30, mean=980, sd=50))

ggplot(data, aes(y=hours)) + geom_boxplot(fill="#8C1D40", alpha=0.7) + 
  labs(title="Distribution of Battery Life", y="Hours") + 
  theme_minimal()

Normal Curve to check if our results fall on the bell curve

library(ggplot2)
ggplot(data.frame(x = c(-4, 4)), aes(x = x)) + 
  stat_function(fun = dt, args = list(df = 29), color = "black") +
  stat_function(fun = dt, args = list(df = 29), color = "red",
                xlim = c(-4, -2.04), geom = "area", fill = "red", alpha=0.5) +
  labs(title="T-Distribution and Refection Region", x="T-score", y="Density") +
  theme_minimal()

3D Analysis

T-Test

#sample of 30 batteries
battery_data = c(980, 1010, 950, 990, 920, 1005, 970, 985, 940, 960)

#Run sample t-test
t_test_results = t.test(battery_data, mu = 1000, alternative = "less")

#P-Value
t_test_results$p.value
## [1] 0.005507045