Independent samples t-test
setwd("/Volumes/EDMS451/Software Instructions")
group1_dat <- data.frame(X = c(4.1, 5.2, 7.5, 8.2, 9.3, 3.1, 1.6,
6.0, 7.4, 6.5, 5.1, 9.6, 2.8, 5.9),
group = rep(1, 14))
group2_dat <- data.frame(X = c(5.1, 1.2, 2.5, 5.4,
7.7, 2.9, 3.0, 2.3),
group = rep(2, 8))
dat <- rbind(group1_dat, group2_dat)
colnames(dat) <- c("June1234", "group") # change the variable name
dat # view the data
June1234 group
1 4.1 1
2 5.2 1
3 7.5 1
4 8.2 1
5 9.3 1
6 3.1 1
7 1.6 1
8 6.0 1
9 7.4 1
10 6.5 1
11 5.1 1
12 9.6 1
13 2.8 1
14 5.9 1
15 5.1 2
16 1.2 2
17 2.5 2
18 5.4 2
19 7.7 2
20 2.9 2
21 3.0 2
22 2.3 2
aggregate(June1234 ~ group, data = dat, mean)
group June1234
1 1 5.878571
2 2 3.762500
aggregate(June1234 ~ group, data = dat, sd)
group June1234
1 1 2.418257
2 2 2.124643
alternative = "two.sided"
conf.level = 0.99
June1234 ~ group
t.test(June1234 ~ group, data = dat, alternative = "two.sided", conf.level = 0.99)
Welch Two Sample t-test
data: June1234 by group
t = 2.1354, df = 16.37, p-value = 0.04817
alternative hypothesis: true difference in means between group 1 and group 2 is not equal to 0
99 percent confidence interval:
-0.7696543 5.0017972
sample estimates:
mean in group 1 mean in group 2
5.878571 3.762500
# alternative code, yielding the same results
# supply the outcomes in each separate groups
with(dat, t.test(June1234[group == 1], June1234[group == 2], alternative = "two.sided", conf.level = 0.99))
Welch Two Sample t-test
data: June1234[group == 1] and June1234[group == 2]
t = 2.1354, df = 16.37, p-value = 0.04817
alternative hypothesis: true difference in means is not equal to 0
99 percent confidence interval:
-0.7696543 5.0017972
sample estimates:
mean of x mean of y
5.878571 3.762500