-
Notifications
You must be signed in to change notification settings - Fork 0
/
R_TTEST.R
60 lines (29 loc) · 1 KB
/
R_TTEST.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# R Hypothesis Tests
install.packages("dplyr")
tScore_before <- c(40, 62, 74, 22, 64, 65, 49, 49, 49)
tScore_after <- c(68, 61, 64, 76, 90, 75, 66, 60, 63)
# Create a data frame
my_data <- data.frame(
group = rep(c("Score Before", "Score After"), each = 9),
scores = c(tScore_before, tScore_after)
)
# Print all data
print(my_data)
#Compute summary statistics by groups
library(dplyr)
group_by(my_data, group) %>%
summarise(
count = n(),
mean = mean(scores, na.rm = TRUE),
sd = sd(scores, na.rm = TRUE)
)
# Compute Unpaired Two Sample t-test
res <- t.test(tScore_before, tScore_after, var.equal = TRUE)
res
# Compute independent t-test
res <- t.test(scores ~ group, data = my_data, var.equal = TRUE)
res
#test whether the average score before score
#is less than the average after score, type this:
t.test(scores ~ group, data = my_data,
var.equal = TRUE, alternative = "less")