- 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
2026-04-12
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
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()
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()
#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