Independent samples t - test using R

Data

purchases.A = c(2233, 2327, 1280, 1477, 1461, 1495, 1950, 1857, 1471, 1567, 1627)
purchases.B = c(1404, 1514, 1730, 1610, 1854, 1107, 2145, 784, 1410, 2226)

1. Descriptive statistics
round(mean(purchases.A), 1)
round(mean(purchases.B), 1)
mean(purchases.A)- mean(purchases.B)

2. Normality assumption
Option 1: Kolmogorov - Smirnov (most of the times not appropriate since the normal parameters are computed from the sample)
ks.test(purchases.A, "pnorm", mean(purchases.A), sd(purchases.A))
ks.test(purchases.B, "pnorm", mean(purchases.B), sd(purchases.B))

Option 2: Shapiro - Wilk
shapiro.test(purchases.A)
shapiro.test(purchases.B)

3. Homogeneity test
3.1 Reformation of the data
group = c(rep(1, 11), rep(2, 10))
group = factor(group, levels = c(1, 2), labels = c("Α", "Β"))
purchases = c(purchases.A, purchases.B)
data = data.frame(group, purchases)

3.2 Levene homogeneity test
library(car)
leveneTest(data$purchases, data$group, center = mean)

4. Independent samples t - test
t.test(purchases.A, purchases.B, var.equal = TRUE)

5. Welch test (apply when homogeneity is not assumed)
t.test(purchases.A, purchases.B, var.equal = FALSE)

6. Wilcoxon test (apply when normality nor homogeneity are assumed)
wilcox.test(purchases.A, purchases.B)

The above example is contained in the paragraph 3.5 of the book "Στατιστική ανάλυση με τη γλώσσα R" (in Greek, ISBN: 978-960-93-9445-1) published in Thessaloniki, 2017.

Comments