-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmodule_eight.R
216 lines (168 loc) · 8.41 KB
/
module_eight.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
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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
# Including the core functionality
source("module_eight_core.R")
## ======================= UTILITY LIST ==========================
module_eight_list<-c( "Sign Test",
"Wilcoxon Signed-Rank test",
"Mann-Whitney Test",
"Kruskal-Wallis Test"
)
## ========================= I/O FUNCTIONS ==============================
## =========================== sign Test ======================================
my_sign_test_input<-function(){
tagList(
textInput('my_sign_test_input_dataOne', 'Enter Data', "1,2,3,4,5,6,7,8,9,10,11,12"),
textInput('my_sign_test_input_dataTwo', 'Enter Mean for hypothesis testing (Mu)', "2"),
textInput('my_sign_test_input_dataThree', 'Enter level of significance (alpha) ', "0.05"),
selectInput("my_sign_test_input_dataFour", "Choose Tail :", c("Two Tailed" = 0 , "One Tailed" = 1))
)
}
my_sign_test_output<-function(){
tagList(
renderPrint({
# Preparing data
data <- as.numeric(unlist(strsplit(input$my_sign_test_input_dataOne,",")))
meu <- as.numeric(unlist(strsplit(input$my_sign_test_input_dataTwo,",")))
myalpha <- as.numeric(unlist(strsplit(input$my_sign_test_input_dataThree,",")))
flag <- as.numeric(unlist(strsplit(input$my_sign_test_input_dataFour,",")))
# ---------------- Display data set as well smoothly ---------------------- #
# Nicely Display the source data
cat(sprintf("Non Parametric - Sign Test \n"))
cat(sprintf("\n\nTesting Hypothesis ( Mu ) : %s",meu))
cat(sprintf("\nlevel of significance ( alpha ) : %s",myalpha))
cat(sprintf("\n\nNULL Hypothesis : \nX bar is equal to Mu"))
if(length(data)>30 ){
cat(sprintf("\n\nSample size > 30\nSo it follows Normal Distribution"))
}
else if(length(data)<=30){
cat(sprintf("\n\nSample size <= 30\nSo it follows Binomial Distribution"))
}
cat(sprintf("\n\nTest Results : \n"))
pvalue<- my_sign_test(data,meu,myalpha,flag)
if( pvalue < myalpha ) {
cat(sprintf("\nP value is less than alpha"))
cat(sprintf("\n%s < %s",pvalue,myalpha))
cat(sprintf("\n\nReject NULL Hypothesis"))
}
else{
cat(sprintf("\nP value is greater than alpha"))
cat(sprintf("\n%s > %s",pvalue,myalpha))
cat(sprintf("\n\nDo not Reject NULL Hypothesis"))
}
})
)
}
## =========================== signed Rank Test ======================================
my_signed_rank_test_input<-function(){
tagList(
textInput('my_signed_rank_test_input_dataOne', 'Enter Data', "1,2,3,4,5,6,7,8,9,10,11,12"),
textInput('my_signed_rank_test_input_dataTwo', 'Enter Mean for hypothesis testing (Mu)', "2"),
textInput('my_signed_rank_test_input_dataThree', 'Enter level of significance (alpha) ', "0.05"),
selectInput("my_signed_rank_test_input_dataFour", "Choose H1 :", c("Mu1 != Mu2" = 0 , "Mu1 < Mu2" = 1, "Mu1 > Mu2" = 2))
)
}
my_signed_rank_test_output<-function(){
tagList(
renderPrint({
# Preparing data
data <- as.numeric(unlist(strsplit(input$my_signed_rank_test_input_dataOne,",")))
meu <- as.numeric(unlist(strsplit(input$my_signed_rank_test_input_dataTwo,",")))
myalpha <- as.numeric(unlist(strsplit(input$my_signed_rank_test_input_dataThree,",")))
flag <- as.numeric(unlist(strsplit(input$my_signed_rank_test_input_dataFour,",")))
# ---------------- Display data set as well smoothly ---------------------- #
# Nicely Display the source data
cat(sprintf("Non Parametric - Signed Rank Test \n"))
cat(sprintf("\n\nTesting Hypothesis ( Mu ) : %s",meu))
cat(sprintf("\nlevel of significance ( alpha ) : %s",myalpha))
cat(sprintf("\n\nNULL Hypothesis : \nX bar is equal to Mu"))
cat(sprintf("\n\nTest Results : \n"))
result<- my_signed_rank_test(data,meu,myalpha,flag)
if( result[1] <= result[2] ) {
cat(sprintf("\nCalculated value is less than equal to tabulated value"))
cat(sprintf("\n%s <= %s",result[1],result[2]))
cat(sprintf("\n\nReject NULL Hypothesis"))
}
else{
cat(sprintf("\nCalculated value is greater than tabulated value"))
cat(sprintf("\n%s > %s",result[1],result[2]))
cat(sprintf("\n\nDo not Reject NULL Hypothesis"))
}
})
)
}
## =========================== Mann whitney Test ======================================
my_mann_whitney_test_input<-function(){
tagList(
textInput('my_mann_whitney_test_input_dataOne', 'Enter Data set 1', "1,2,3,4,5,6,7,8,9,10,11,12"),
textInput('my_mann_whitney_test_input_dataTwo', 'Enter Data set 2', "5,6,7,8,9,10,11,12,1,43,1,4"),
textInput('my_mann_whitney_test_input_dataThree', 'Enter level of significance (alpha) ', "0.05"),
selectInput("my_mann_whitney_test_input_dataFour", "Choose H1 :", c("Mu1 != Mu2" = 0 , "Mu1 < Mu2" = 1, "Mu1 > Mu2" = 2))
)
}
my_mann_whitney_test_output<-function(){
tagList(
renderPrint({
# Preparing data
data1 <- as.numeric(unlist(strsplit(input$my_mann_whitney_test_input_dataOne,",")))
data2 <- as.numeric(unlist(strsplit(input$my_mann_whitney_test_input_dataTwo,",")))
myalpha <- as.numeric(unlist(strsplit(input$my_mann_whitney_test_input_dataThree,",")))
flag <- as.numeric(unlist(strsplit(input$my_mann_whitney_test_input_dataFour,",")))
# ---------------- Display data set as well smoothly ---------------------- #
# Nicely Display the source data
cat(sprintf("Non Parametric - Mann Whitney Test \n"))
cat(sprintf("\nlevel of significance ( alpha ) : %s",myalpha))
cat(sprintf("\n\nNULL Hypothesis : \nBoth Data Sets have approximately equal means."))
cat(sprintf("\n\nTest Results : \n"))
result<- my_mann_whitney_test(data1,data2,myalpha,flag)
if( result[1] <= result[2] ) {
cat(sprintf("\nCalculated value is less than equal to tabulated value"))
cat(sprintf("\n%s <= %s",result[1],result[2]))
cat(sprintf("\n\nReject NULL Hypothesis"))
}
else{
cat(sprintf("\nCalculated value is greater than tabulated value"))
cat(sprintf("\n%s > %s",result[1],result[2]))
cat(sprintf("\n\nDo not Reject NULL Hypothesis"))
}
})
)
}
## =========================== Krushkal Wallis Test ======================================
my_kruskal_wallis_input<-function(){
tagList(
textInput('my_kruskal_wallis_input_dataOne', 'Enter Data set 1', "1,2,3,4"),
textInput('my_kruskal_wallis_input_dataTwo', 'Enter Data set 2', "20,21,22"),
textInput('my_kruskal_wallis_input_dataThree', 'Enter Data set 2', "9,10,11,12"),
textInput('my_kruskal_wallis_input_dataFour', 'Enter level of significance (alpha) ', "0.05")
)
}
my_kruskal_wallis_output<-function(){
tagList(
renderPrint({
# Preparing data
data1 <- as.numeric(unlist(strsplit(input$my_kruskal_wallis_input_dataOne,",")))
data2 <- as.numeric(unlist(strsplit(input$my_kruskal_wallis_input_dataTwo,",")))
data3 <- as.numeric(unlist(strsplit(input$my_kruskal_wallis_input_dataThree,",")))
myalpha <- as.numeric(unlist(strsplit(input$my_kruskal_wallis_input_dataFour,",")))
# ---------------- Display data set as well smoothly ---------------------- #
# Nicely Display the source data
cat(sprintf("Non Parametric - Kurskal Wallis Test \n"))
cat(sprintf("\nSample Variance of data set 1 : %s",my_sample_variance(data1)))
cat(sprintf("\nSample Variance of data set 2 : %s",my_sample_variance(data2)))
cat(sprintf("\nSample Variance of data set 3 : %s",my_sample_variance(data3)))
cat(sprintf("\n\nlevel of significance ( alpha ) : %s",myalpha))
cat(sprintf("\n\nNULL Hypothesis : \nAll Data Sets have approximately equal means."))
cat(sprintf("\n\nTest Results : \n"))
result<- my_kruskal_wallis(data1,data2,data3,myalpha)
if( result[1] <= result[2] ) {
cat(sprintf("\nCalculated value is less than equal to tabulated value"))
cat(sprintf("\n%s <= %s",result[1],result[2]))
cat(sprintf("\n\nReject NULL Hypothesis"))
}
else{
cat(sprintf("\nCalculated value is greater than tabulated value"))
cat(sprintf("\n%s > %s",result[1],result[2]))
cat(sprintf("\n\nDo not Reject NULL Hypothesis"))
}
})
)
}