forked from alaghemandi/CS555_2020
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathModule-5-Example-5.R
60 lines (44 loc) · 1.64 KB
/
Module-5-Example-5.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
# setwd("SET THE Working Director to THE PATH TO THIS DIRECTORY")
# Load the smoker data set.
data<- read.csv("Datasets/smoking_SBP.csv")
attach(data)
data
is.factor(data$group)
# Fit an Analysis of Variance Model
m<- aov(data$SBP~data$group, data=data)
summary(m)
# The F Distribution
# a=0.05
# F Value for df1=3, df2=15
qf(.95, df1=3, df2=15)
# anova model
m1<- aov(formula = data$SBP ~ group, data = data)
# Calculating TukeyHSD
TukeyHSD(m1)
# Install package car "Companion to Applied Regression"
# one time installation needed only
# install.packages("car")
library(car)
Anova(lm(data$SBP~data$group+data$age), type=3)
# calculating the lsmeans
# lsmeans package is deprecated
# install.packages("lsmeans")
# one time installation needed only
# Least square means
# library(lsmeans)
# options(contrasts=c("contr.treatment", "contr.poly"))
# lsmeans(lm(data$SBP~data$group+data$age), pairwise~data$group, adjust="none")
# with none adjust=[method])
# Note: method = “tukey”, “scheffe”, “sidak", "bonferroni", “dunnettx", “mvt", "none")
# lsmeans(lm(data$SBP~data$group+data$age), pairwise~data$group, adjust="tukey")
# install.packages("emmeans")
library(emmeans)
my.model<-lm(SBP~group+age, data = data)
emm_options(contrasts=c("contr.treatment", "contr.poly"))
emmeans(my.model, specs = "group")
# no p value adjustment
emmeans(my.model, specs = "group" , contr = "pairwise", adjust="none")
# P value adjustment: tukey method
emmeans(my.model, specs = "group" , contr = "pairwise", adjust="tukey")
# P value adjustment: bonferroni method for 6 tests
emmeans(my.model, specs = "group" , contr = "pairwise", adjust="bonferroni")