-
Notifications
You must be signed in to change notification settings - Fork 48
/
Module-5-Example-1.R
45 lines (27 loc) · 1.18 KB
/
Module-5-Example-1.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
# setwd("SET THE Working Director to THE PATH TO THIS DIRECTORY")
# Load the smoker data set.
data<- read.csv("Datasets/smoker.csv")
attach(data)
data
# The function factor is used to encode a vector as a factor (the terms ‘category’ and ‘enumerated type’
# are also used for factors).
is.factor(data$group)
# Calculate mean, SD of SBP by groups
aggregate(data$SBP, by=list(data$group), summary)
aggregate(data$SBP, by=list(data$group), sd)
# Boxplot data
boxplot(data$SBP~data$group, data=data, main="SBP by smoking status", xlab="group", ylab="SBP", ylim=c(100, 160))
# aov
m <- aov(data$SBP~data$group, data=data)
summary(m)
# pairwise t test
pairwise.t.test(data$SBP, data$group, p.adj="none")
# pairwise t test with bonferroni adjustment
pairwise.t.test(data$SBP, data$group, p.adj="bonferroni")
# Compute Tukey Honest Significant Differences
?TukeyHSD
# Create a set of confidence intervals on the differences between the means of the levels of a factor
# with the specified family-wise probability of coverage.
# The intervals are based on the Studentized range statistic, Tukey's ‘Honest Significant Difference’ method.
# pairwise test with TukeyHSD
TukeyHSD(m)