| Term | English | Somalia |
|---|---|---|
| Population | The entire group of people, objects, or measurements you want to study. | Waa kooxda oo dhan ee dadka, walxaha, ama cabbirrada aad rabto inaad barato. |
| Sample | A smaller group selected from the population that you actually study. | Waa qayb yar oo bulshada ka mid ah oo loo doorto in si dhab ah loo daraaseeyo. |
| Parameter | A numerical value that describes a population. | Waa qiime tiro ah oo tilmaamaya ama sharxaya bulshada oo dhan. |
| Statistic | A numerical value calculated from a sample. | Waa qiime tiro ah oo laga xisaabiyo muunad. |
| Data | The information or measurements collected in a study. | Waa xogta ama cabbirrada la ururiyo inta lagu jiro daraasad. |
| Variable | A characteristic or measurement that can change from one individual or object to another. | Waa sifo ama cabbir isbeddeli kara qof ilaa qof ama shay ilaa shay. |
| Causation | When a change in one variable directly produces a change in another variable. | Waa marka isbeddel ku yimaadda hal doorsoome uu si toos ah u keeno isbeddel ku yimaadda doorsoome kale. |
| Confidence interval | A range of values used to estimate an unknown population parameter. | Waa xad qiimayaal ah oo loo isticmaalo qiyaasidda qiime aan la garanayn oo ka tirsan bulshada. |
| Confidence level | The percentage associated with a confidence interval, such as 95%. | Waa heerka kalsoonida ee la xiriira confidence interval, tusaale ahaan 95%. |
| Correlation. | A measure of how two variables are related. | Waa cabbir muujinaya sida laba doorsoome isugu xiran yihiin. |
| Hypothesis | A statement or claim about a population that can be tested using data. | Waa sheegasho ama mala-awaal ku saabsan bulshada oo lagu tijaabin karo xog. |
| Hypothesis test | A statistical method used to determine whether sample data provides enough evidence against the null hypothesis. | Waa hab tirakoob lagu go’aamiyo in xogta muunaddu bixisay caddayn ku filan oo ka dhan ah mala-awaalka eberka ah. |
| Mean | The average of a set of numbers. | Waa celceliska tirooyin la isku daray kadibna tiradooda lagu qaybiyey. |
| Median | The middle value when data is arranged from smallest to largest. | Waa qiimaha dhexe marka xogta loo kala habeeyo tan ugu yar ilaa tan ugu weyn. |
| Mode | The value that occurs most often. | Waa qiimaha ugu badan ee soo noqnoqda xogta. |
| Null hypothesis (H₀) | The assumption that there is no effect, difference, or relationship. | Waa mala-awaalka sheegaya in aanay jirin saameyn, farqi, ama xiriir. |
| Alternative hypothesis (H₁) | The statement that there is an effect, difference, or relationship. | Waa sheegashada tilmaamaysa in uu jiro saameyn, farqi, ama xiriir. |
| Reject H₀ | There is enough evidence from the sample to reject the null hypothesis. | Waxaa jira caddayn ku filan oo muunaddu bixisay si loo diido mala-awaalka eberka ah. |
| Fail to reject H₀ | There is not enough evidence from the sample to reject the null hypothesis. | Waxaa loola jeedaa in aanay jirin caddayn ku filan oo muunaddu bixisay si loo diido mala-awaalka eberka ah. |
| p-value | The probability of getting results at least as extreme as the observed results, assuming the null hypothesis is true. | Waa suurtagalnimada in la helo natiijo la mid ah ama ka sii daran natiijada la arkay, iyadoo loo malaynayo in H₀ run tahay. |
| Random sample | A sample selected so that members of the population have a known and appropriate chance of being selected. | Waa muunad aan eex lahayn oo xubnaha bulshada ay leeyihiin fursad la yaqaan oo ku habboon in la doorto. |
| Sampling error | The difference between a sample result and the true population value caused by using a sample rather than the entire population. | Waa farqiga u dhexeeya natiijada muunadda iyo qiimaha dhabta ah ee bulshada, kaas oo ka dhasha isticmaalka muunad halkii bulshada oo dhan laga baran lahaa. |
| Significance level (α) | The cutoff used to decide whether a result is statistically significant. Acommon value is 0.05. | Waa heerka go’aaminta in natiijadu tahay mid muhiim ah tirakoob ahaan. Qiime caadi ah waa 0.05. |
| Variance | A measure of data spread calculated using squared differences from the mean. | Waa cabbirka kala firdhinta xogta, kaas oo lagu xisaabiyo farqiyada labajibbaaran ee u dhexeeya xogta iyo celceliska. |
| Standard deviation | A measure of how spread out the data is around the mean. | Waa cabbir muujinaya sida xogtu ugu kala firdhisan tahay celceliska. |
| Statistically significant | A result is statistically significant when the p-value is smaller than the chosen significance level. | Natiijo ayaa tirakoob ahaan muhiim ah marka p-value-gu ka yar yahay heerka muhiimadda la doortay. |
| Type I error | Rejecting the null hypothesis when it is actually true. | Waa diididda H₀ iyadoo dhab ahaantii uu run yahay. |
| Type II error | Failing to reject the null hypothesis when it is actually false. | Waa in aan la diidin H₀ iyadoo dhab ahaantii uu been yahay. |
That’s all the vocabulary you need. Let’s get started.
Parametric means that a statistical test makes certain assumptions about the data. For example, a parametric test often assumes that the data follow a normal distribution, which has a bell-shaped pattern. It alsouses important values called parameters, such as the mean and standard deviation. The mean tells us the average value, while the standard deviation tells us how spread out the data are. In simple terms, parametric tests use specific assumptions and parameters to analyze and understand data.
x <- seq(-4, 4, length.out = 400)
y <- dnorm(x)
plot(x, y, type = "l", lwd = 3, col = "steelblue",
main = "The Normal Distribution (Bell Curve)",
xlab = "Standard Deviations from the Mean",
ylab = "Probability Density")
abline(v = 0, col = "red", lty = 2)
text(0, 0.42, "mean", col = "red")
Most real-world measurements — heights, blood pressure, exam scores — roughly form this shape: lots of values near the middle, fewer near the edges, evenly balanced on both sides. When your data looks like this, parametric tests work best — they’re better at catching a real effect than the non-parametric tests you’ll see in Lesson 2.
| Assumption | What it means | How to check in R |
|---|---|---|
| Normality | Data roughly follows the bell curve | Histogram, Q-Q plot, shapiro.test() |
| Equal spread | Groups being compared vary by a similar amount | bartlett.test() |
| Independence | One measurement doesn’t affect another | Comes from your study design |
| Numeric scale | Data is measured in real numbers, not just categories or ranks | Know your data |
data(iris)
setosa_length <- iris$Sepal.Length[iris$Species == "setosa"]
# 1. Look at it
par(mfrow = c(1, 2))
hist(setosa_length, col = "steelblue", border = "white",
main = "Histogram", xlab = "Sepal Length (cm)")
qqnorm(setosa_length, main = "Q-Q Plot")
qqline(setosa_length, col = "red")
par(mfrow = c(1, 1))
# 2. Test it formally
shapiro.test(setosa_length)
##
## Shapiro-Wilk normality test
##
## data: setosa_length
## W = 0.9777, p-value = 0.4595
How to read this: in the histogram, the bars roughly
form a hump in the middle — good sign. In the Q-Q plot, points close to
the red line mean “close to normal”; points that curve away from the
line mean “not normal.” The shapiro.test() p-value here is
well above 0.05, so we have no evidence against normality — a parametric
test is safe to use.
Before working through each test one by one, here’s a map of how they relate. Once your data has passed the normality check above, the question becomes purely: what shape is my comparison?
If your data is not normally distributed, use non-parametric tests instead. See the next lesson for the appropriate tests.
When to use it: you have one group of numbers and want to know if their average is different from some specific target value.
Example: Iris flowers are commonly said to average about 5.8 cm in sepal length. Does our sample support that?
t.test(iris$Sepal.Length, mu = 5.8)
##
## One Sample t-test
##
## data: iris$Sepal.Length
## t = 0.64092, df = 149, p-value = 0.5226
## alternative hypothesis: true mean is not equal to 5.8
## 95 percent confidence interval:
## 5.709732 5.976934
## sample estimates:
## mean of x
## 5.843333
hist(iris$Sepal.Length, col = "#a8dadc", border = "white",
main = "Sepal Length, with Hypothesized Mean",
xlab = "Sepal Length (cm)")
abline(v = 5.8, col = "red", lwd = 2, lty = 2)
abline(v = mean(iris$Sepal.Length), col = "darkgreen", lwd = 2)
legend("topright", legend = c("Hypothesized mean (5.8)", "Sample mean"),
col = c("red", "darkgreen"), lty = c(2, 1), lwd = 2, bty = "n")
Reading the output: the p-value tells you whether the sample mean (green line) is far enough from the hypothesized value (red dashed line) to be surprising. Here p > 0.05, so this sample is consistent with a true average of 5.8 cm.
When to use it: you have two separate, unrelated groups and want to compare their averages.
Example: Do versicolor and virginica iris flowers differ in sepal length?
iris2 <- subset(iris, Species %in% c("versicolor", "virginica"))
t.test(Sepal.Length ~ Species, data = iris2)
##
## Welch Two Sample t-test
##
## data: Sepal.Length by Species
## t = -5.6292, df = 94.025, p-value = 1.866e-07
## alternative hypothesis: true difference in means between group versicolor and group virginica is not equal to 0
## 95 percent confidence interval:
## -0.8819731 -0.4220269
## sample estimates:
## mean in group versicolor mean in group virginica
## 5.936 6.588
boxplot(Sepal.Length ~ Species, data = iris2,
col = c("#e76f51", "#2a9d8f"),
main = "Sepal Length by Species", xlab = "Species",
ylab = "Sepal Length (cm)")
Reading the output: the box in a boxplot shows where the middle 50% of the data sits, and the thick line inside is the median. Here the boxes barely overlap, and the p-value is tiny (far below 0.05) — strong evidence that virginica really does have longer sepals, on average, than versicolor.
When to use it: you have two measurements on the same subjects — before/after, left/right, drug A vs. drug B on the same people. “Paired” means each pair of numbers belongs together.
Example: The built-in sleep dataset
recorded extra hours of sleep for 10 patients, once under Drug 1 and
once under Drug 2.
data(sleep)
# t.test()'s formula method (like wilcox.test()'s) doesn't accept
# paired = TRUE, so we reshape to two lined-up vectors first
sleep_wide <- reshape(sleep, idvar = "ID", timevar = "group",
direction = "wide")
t.test(sleep_wide$extra.1, sleep_wide$extra.2, paired = TRUE)
##
## Paired t-test
##
## data: sleep_wide$extra.1 and sleep_wide$extra.2
## t = -4.0621, df = 9, p-value = 0.002833
## alternative hypothesis: true mean difference is not equal to 0
## 95 percent confidence interval:
## -2.4598858 -0.7001142
## sample estimates:
## mean difference
## -1.58
pair_mat <- rbind(sleep_wide$extra.1, sleep_wide$extra.2)
matplot(pair_mat, type = "b", pch = 19, lty = 1, col = "grey40",
xaxt = "n", xlim = c(0.8, 2.2), xlab = "Drug",
ylab = "Extra Hours of Sleep",
main = "Same Patient, Two Drugs (each line = one patient)")
axis(1, at = 1:2, labels = c("Drug 1", "Drug 2"))
Reading the output: each grey line is one patient’s own before/after change — pairing removes the natural differences between people, so we can focus purely on the drug effect. Most lines slope upward, matching a p-value under 0.05: Drug 2 genuinely tends to give more extra sleep.
When to use it: you have three or more independent groups and want to know if any of their averages differ. (“ANOVA” stands for “Analysis of Variance,” but what it produces is a single p-value telling you whether group averages differ.)
Example: Do all three iris species differ in sepal length?
anova_fit <- aov(Sepal.Length ~ Species, data = iris)
summary(anova_fit)
## Df Sum Sq Mean Sq F value Pr(>F)
## Species 2 63.21 31.606 119.3 <2e-16 ***
## Residuals 147 38.96 0.265
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
boxplot(Sepal.Length ~ Species, data = iris,
col = c("#f4a261", "#2a9d8f", "#264653"),
main = "Sepal Length by Species (All 3)", xlab = "Species",
ylab = "Sepal Length (cm)")
Reading the output: find the row
Species and the column Pr(>F) — that’s your
p-value. It’s far below 0.05, so at least one species differs from the
others. (ANOVA only tells you that a difference exists
somewhere, not exactly which pairs — you’d follow up with a “post-hoc”
test to pinpoint that, which is beyond this beginner lesson.)
When to use it: you have two numeric variables and want to know if they move together in a straight-line (“linear”) way.
Example: Do heavier cars get worse gas mileage?
cor.test(mtcars$mpg, mtcars$wt, method = "pearson")
##
## Pearson's product-moment correlation
##
## data: mtcars$mpg and mtcars$wt
## t = -9.559, df = 30, p-value = 1.294e-10
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
## -0.9338264 -0.7440872
## sample estimates:
## cor
## -0.8676594
plot(mtcars$wt, mtcars$mpg, pch = 19, col = "steelblue",
xlab = "Weight (1000 lbs)", ylab = "Miles per Gallon",
main = "MPG vs. Weight")
abline(lm(mpg ~ wt, data = mtcars), col = "red", lwd = 2)
Reading the output: the correlation cor
value ranges from -1 (perfect downhill relationship) to +1 (perfect
uphill relationship); 0 means no straight-line relationship at all. Here
it’s strongly negative, and the red trend line in the plot shows it
visually: heavier cars get noticeably worse mileage. The p-value
confirms this relationship is very unlikely to be due to chance.
Real datasets are great, but they’re sometimes messy — a p-value that lands right on the 0.05 line (like the tooth-growth example in Lesson 2) can be confusing when you’re still learning to read the output. It helps to also see generated data, built by hand so the answer is textbook- clear.
The key tool is set.seed(). R’s “random” numbers are
actually generated by a formula that needs a starting point;
set.seed(123) fixes that starting point, so
rnorm() produces the exact same numbers every time
you (or anyone else) run this code. That’s what makes generated data
stable and reproducible — unlike real-world data, it
won’t change between runs, and you can dial in exactly how strong an
effect to show.
set.seed(123)
group_a <- rnorm(30, mean = 50, sd = 5) # 30 values, centered at 50
group_b <- rnorm(30, mean = 58, sd = 5) # 30 values, centered at 58
t.test(group_a, group_b)
##
## Welch Two Sample t-test
##
## data: group_a and group_b
## t = -7.7606, df = 56.559, p-value = 1.803e-10
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
## -11.482713 -6.771708
## sample estimates:
## mean of x mean of y
## 49.76448 58.89169
par(mfrow = c(1, 2))
hist(group_a, col = rgb(0.2, 0.5, 0.8, 0.6), xlim = c(30, 75),
main = "Group A vs. Group B", xlab = "Value", breaks = 10)
hist(group_b, col = rgb(0.9, 0.4, 0.2, 0.6), add = TRUE, breaks = 10)
legend("topright", legend = c("Group A", "Group B"),
fill = c(rgb(0.2, 0.5, 0.8, 0.6), rgb(0.9, 0.4, 0.2, 0.6)), bty = "n")
boxplot(group_a, group_b, names = c("A", "B"), col = c("#457b9d", "#e76f51"),
main = "Same Data as Boxplots", ylab = "Value")
par(mfrow = c(1, 1))
Because we built these groups 8 units apart with
rnorm(), the p-value comes out extremely small every single
time this code runs — a clean, unambiguous “yes, these differ” result to
contrast with real data’s occasional borderline cases.
set.seed(42)
before <- rnorm(20, mean = 100, sd = 10)
after <- before + rnorm(20, mean = 6, sd = 3) # each subject improves by ~6, plus noise
t.test(before, after, paired = TRUE)
##
## Paired t-test
##
## data: before and after
## t = -6.9683, df = 19, p-value = 1.222e-06
## alternative hypothesis: true mean difference is not equal to 0
## 95 percent confidence interval:
## -6.745027 -3.629023
## sample estimates:
## mean difference
## -5.187025
matplot(rbind(before, after), type = "b", pch = 19, lty = 1, col = "grey40",
xaxt = "n", xlim = c(0.8, 2.2), xlab = "Time", ylab = "Value",
main = "Simulated Before/After (each line = one subject)")
axis(1, at = 1:2, labels = c("Before", "After"))
Building after as before plus a fixed
improvement is what guarantees almost every line slopes upward — a
clean, reliable illustration of what a real paired effect looks
like.
set.seed(7)
sim_data <- data.frame(
value = c(rnorm(20, 40, 6), rnorm(20, 45, 6), rnorm(20, 55, 6)),
group = factor(rep(c("Low", "Medium", "High"), each = 20))
)
summary(aov(value ~ group, data = sim_data))
## Df Sum Sq Mean Sq F value Pr(>F)
## group 2 1853 926.7 26.35 7.87e-09 ***
## Residuals 57 2004 35.2
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
boxplot(value ~ group, data = sim_data, col = c("#a8dadc", "#457b9d", "#1d3557"),
main = "Simulated Three-Group Comparison", xlab = "Group", ylab = "Value")
| I want to… | Use | R function |
|---|---|---|
| Compare one group’s average to a target number | One-sample t-test | t.test(x, mu = ...) |
| Compare two separate groups | Independent t-test | t.test(y ~ group) |
| Compare before/after on the same subjects | Paired t-test | t.test(x, y, paired = TRUE) |
| Compare 3+ separate groups | One-way ANOVA | aov(y ~ group) |
| See if two numeric variables move together | Pearson correlation | cor.test(x, y) |
Golden rule: always check normality first (histogram
+ Q-Q plot + shapiro.test()). If your data clearly fails
that check — very skewed, small sample, obvious outliers — head to
Lesson 2: Non-Parametric Statistics, which covers the
rank-based alternative to every test above.
Try this yourself: Using the built-in
PlantGrowth dataset (weight by
group, three groups: ctrl, trt1,
trt2), check whether the data looks normal, then run the
appropriate test from this lesson to see if plant weight differs by
treatment group.
# Hints:
data(PlantGrowth)
shapiro.test(PlantGrowth$weight[PlantGrowth$group == "ctrl"])
boxplot(weight ~ group, data = PlantGrowth)
# Three groups, comparing averages -> which test from this lesson fits?
aov(weight ~ group, data = PlantGrowth)
Next: Lesson 2 covers what to do when your data does not meet these assumptions — the non-parametric statistics.