-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathANOVA.R
More file actions
162 lines (112 loc) · 4.5 KB
/
ANOVA.R
File metadata and controls
162 lines (112 loc) · 4.5 KB
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
## Read the data Medical1
library(psych)
library(car)
setwd("C:/Users/stelidevara/Downloads")
## Summary Statistics
####Coupon and Instore Promotion Data
datasales<-read.csv("couponsales.csv",header=TRUE)
#Step 2: Clearly identify the factors in the data
datasales$promotion<-factor(datasales$promotion, labels=c("1","2","3"))
datasales$coupon<-factor(datasales$coupon, labels=c("1","2"))
describe(datasales$sales)
describeBy(datasales$sales, group=datasales$promotion)
## Test for normality based on promotion
shapiro.test(datasales$sales)
cat("Normality p-values by Factor Place: ")
cat("Normality p-values by Factor Place: ")
for (i in unique(factor(datasales$promotion))){
cat(shapiro.test(datasales[datasales$promotion==i, ]$sales)$p.value," ")
}
## Test for normality based on coupon
cat("Normality p-values by Factor Place: ")
cat("Normality p-values by Factor Place: ")
for (i in unique(factor(datasales$coupon))){
cat(shapiro.test(datasales[datasales$coupon==i, ]$sales)$p.value," ")
}
qqnorm(datasales$sales, pch=19, cex=0.6)
qqline(datasales$sales, col = 'red')
######## Levene's test for variance
## Test for homogeneity of variance
boxplot(datasales$sales~datasales$promotion)
leveneTest(datasales@sales~datasales$promotion)
##################################################################################
####ANOVA based on promotion
aov1 <- aov(datasales$sales~datasales$promotion)
summary(aov1)
TukeyHSD(aov1)
plot(TukeyHSD(aov1))
##################################################################################
##################################################################################
####ANOVA based on coupon
aov1 <- aov(datasales$sales~datasales$coupon)
summary(aov1)
TukeyHSD(aov1)
plot(TukeyHSD(aov1))
##################################################################################
##################################################################################
##################################################################################
####ANOVA based on promotion and coupon
aov3 <- aov(datasales$sales~datasales$promotion+datasales$coupon+datasales$promotion*datasales$coupon)
summary(aov3)
TukeyHSD(aov3)
plot(TukeyHSD(aov3,ordered = T))
##################################################################################
##### Depression Scores Data
##################################################################################
## Summary Statistics
Medical1<-read.csv("Medical1.csv", header=TRUE)
#Step 2: Clearly identify the factors in the data
df$levels<-factor(Medical1$Place, labels=c("New York","North Carolina","Florida"))
describe(Medical1$DepressionScore)
describeBy(Medical1$DepressionScore, group=Medical1$Place)
## Test for normality
shapiro.test(Medical1$DepressionScore)
qqnorm(Medical1$DepressionScore, pch=19, cex=0.6)
qqline(Medical1$DepressionScore, col = 'red')
qqnorm(Medical1$DepressionScore, pch=19, cex=0.6)
qqline(Medical1$DepressionScore, col = 'red')
## Test for homogeneity of variance
boxplot(Medical1$DepressionScore~Medical1$Place)
leveneTest(Medical1$DepressionScore~Medical1$Place)
## ANOVA
aov1 <- aov(Medical1$DepressionScore~Medical1$Place)
summary(aov1)
TukeyHSD(aov1)
plot(TukeyHSD(aov1))
## Read the data Medical2
## Summary Statistics
describe(Medical2$`DepressionScore`)
describeBy(Medical2$DepressionScore, group=Medical2$Place)
## ANOVA
aov2 <- aov(Medical2$`Depression Score`~Medical2$'Place')
summary(aov2)
TukeyHSD(aov2)
plot(TukeyHSD(aov2))
## Read the data SalesSalary
## Summary Statistics
describe(SalesSalary$`Salary`)
describeBy(SalesSalary$`Salary`, group=SalesSalary$'Position')
describeBy(SalesSalary$`Salary`, group=SalesSalary$'Experience')
## Test for normality
shapiro.test(SalesSalary$`Salary`)
qqnorm(SalesSalary$`Salary`, pch=19, cex=0.6)
qqline(SalesSalary$`Salary`, col = 'red')
## Test for homogeneity of variance
boxplot(SalesSalary$`Salary`~SalesSalary$'Position'*SalesSalary$'Experience')
leveneTest(SalesSalary$`Salary`~SalesSalary$'Position'*SalesSalary$'Experience')
## ANOVA
aov3 <- aov(SalesSalary$`Salary`~SalesSalary$'Position')
summary(aov3)
# TukeyHSD(aov3)
# plot(TukeyHSD(aov3))
aov4 <- aov(SalesSalary$`Salary`~SalesSalary$'Experience')
summary(aov4)
TukeyHSD(aov4)
plot(TukeyHSD(aov4, ordered = T))
aov5 <- aov(SalesSalary$`Salary`~SalesSalary$'Experience'*SalesSalary$'Position')
summary(aov5)
TukeyHSD(aov5)
plot(TukeyHSD(aov5, ordered = T))
interaction.plot(SalesSalary$'Position',SalesSalary$'Experience',SalesSalary$`Salary`,
fixed=T, col=c('red', 'blue', 'green'))
#####################