-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmodule_six.R
274 lines (210 loc) · 10.1 KB
/
module_six.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
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
# Including the core functionality
source("module_six_core.R")
## ======================= UTILITY LIST ==========================
module_six_list<-c("Z-test",
"Student t-test",
"F-test",
"Chi-Square",
"Shapiro Wilk test"
)
## ================================= I/O FUNCTIONS ==================================
## ==================================== Z Test =======================================
my_z_test_input<-function(){
tagList(
textInput('my_z_test_input_dataOne', 'Enter Sample size (n)', "20"),
textInput('my_z_test_input_dataTwo', 'Enter average (x bar)', "5"),
textInput('my_z_test_input_dataThree', 'Enter Mean for hypothesis testing (Mu)', "5.5"),
textInput('my_z_test_input_dataFour', 'Enter Standard Deviation (sigma)', "2"),
textInput('my_z_test_input_dataFive', 'Enter level of significance (alpha) ', "0.05"),
selectInput("my_z_test_input_dataSix", "Choose Tail :", c("Two Tailed" = 0 , "One Tailed" = 1))
)
}
my_z_test_output<-function(){
tagList(
renderPrint({
# Preparing data
n <- as.numeric(unlist(strsplit(input$my_z_test_input_dataOne,",")))
avg<-as.numeric(unlist(strsplit(input$my_z_test_input_dataTwo,",")))
meu <- as.numeric(unlist(strsplit(input$my_z_test_input_dataThree,",")))
mySD <- as.numeric(unlist(strsplit(input$my_z_test_input_dataFour,",")))
myalpha <- as.numeric(unlist(strsplit(input$my_z_test_input_dataFive,",")))
flag <- as.numeric(unlist(strsplit(input$my_z_test_input_dataSix,",")))
# ---------------- Display data set as well smoothly ---------------------- #
# Nicely Display the source data
cat(sprintf("For Hypothesis Testing - Z test :\n\n"))
cat(sprintf("\nSample size ( n ) : %s",n))
cat(sprintf("\nAverage ( x bar ) : %s",avg))
cat(sprintf("\nStandard Deviation ( sigma ) : %s",mySD))
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"))
pvalue<- my_z_test(avg,meu,mySD,n,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"))
}
})
)
}
## ==================================== T Test =======================================
my_t_test_input<-function(){
tagList(
textInput('my_t_test_input_dataOne', 'Enter Data', "1,2,3,4,5,6,7,8,9,10,11,12"),
textInput('my_t_test_input_dataTwo', 'Enter Mean for hypothesis testing (Mu)', "2"),
textInput('my_t_test_input_dataThree', 'Enter level of significance (alpha) ', "0.05"),
selectInput("my_t_test_input_dataFour", "Choose Tail :", c("Two Tailed" = 0 , "One Tailed" = 1))
)
}
my_t_test_output<-function(){
tagList(
renderPrint({
# Preparing data
data <- as.numeric(unlist(strsplit(input$my_t_test_input_dataOne,",")))
meu <- as.numeric(unlist(strsplit(input$my_t_test_input_dataTwo,",")))
myalpha <- as.numeric(unlist(strsplit(input$my_t_test_input_dataThree,",")))
flag <- as.numeric(unlist(strsplit(input$my_t_test_input_dataFour,",")))
# ---------------- Display data set as well smoothly ---------------------- #
# Nicely Display the source data
cat(sprintf("For Hypothesis Testing - T test :\n\n"))
cat(sprintf("\nSample size ( n ) : %s",length(data)))
cat(sprintf("\nAverage ( x bar ) : %s",my_mean(data)))
cat(sprintf("\nStandard Deviation ( sigma ) : %s",my_sample_SD(data)))
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 is a Normal Distribution"))
cat(sprintf("\nCalling Z-test "))
}
cat(sprintf("\n\nTest Results : \n"))
pvalue<- my_t_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"))
}
})
)
}
## =========================== F test ======================================
my_f_test_input<-function(){
tagList(
textInput('my_f_test_input_dataOne', 'Enter Data', "1,2,3,4,5,6,7,8,9,10,11,12"),
textInput('my_f_test_input_dataTwo', 'Enter Data', "9,11,3,7,8"),
textInput('my_f_test_input_dataThree', 'Enter level of significance (alpha) ', "0.05")
)
}
my_f_test_output<-function(){
tagList(
renderPrint({
# Preparing data
data1 <- as.numeric(unlist(strsplit(input$my_f_test_input_dataOne,",")))
data2 <- as.numeric(unlist(strsplit(input$my_f_test_input_dataTwo,",")))
myalpha <- as.numeric(unlist(strsplit(input$my_f_test_input_dataThree,",")))
# ---------------- Display data set as well smoothly ---------------------- #
# Nicely Display the source data
cat(sprintf("For Hypothesis Testing - F test :\n\n"))
cat(sprintf("Data Set 1\n"))
cat(sprintf("\nSample size ( n1 ) : %s",length(data1)))
cat(sprintf("\nAverage ( x bar1 ) : %s",my_mean(data1)))
cat(sprintf("\nVariance ( s1 sq ) : %s",my_sample_variance(data1)))
cat(sprintf("\n\nData Set 2\n"))
cat(sprintf("\nSample size ( n2 ) : %s",length(data2)))
cat(sprintf("\nAverage ( x bar2 ) : %s",my_mean(data2)))
cat(sprintf("\nVariance ( s2 sq ) : %s",my_sample_variance(data2)))
cat(sprintf("\n\nlevel of significance ( alpha ) : %s",myalpha))
cat(sprintf("\n\nNULL Hypothesis : \nBoth Data sets have approximately equal variances"))
cat(sprintf("\n\nTest Result : \n"))
decision<- my_f_test(data1,data2,myalpha)
cat(sprintf("\n%s",decision))
})
)
}
## =========================== Chi square Test ======================================
my_chi_square_test_input<-function(){
tagList(
textInput('my_chi_square_test_input_dataOne', 'Enter Data', "1,2,2"),
textInput('my_chi_square_test_input_dataTwo', 'Enter Test Hypothesis (Sigma square)', "1.2"),
textInput('my_chi_square_test_input_dataThree', 'Enter level of significance (alpha) ', "0.05"),
selectInput("my_chi_square_test_input_dataFour", "Choose Tail :", c("Two Tailed" = 0 , "One Tailed" = 1))
)
}
my_chi_square_test_output<-function(){
tagList(
renderPrint({
# Preparing data
data <- as.numeric(unlist(strsplit(input$my_chi_square_test_input_dataOne,",")))
sigmasq <- as.numeric(unlist(strsplit(input$my_chi_square_test_input_dataTwo,",")))
myalpha <- as.numeric(unlist(strsplit(input$my_chi_square_test_input_dataThree,",")))
flag <- as.numeric(unlist(strsplit(input$my_chi_square_test_input_dataFour,",")))
# ---------------- Display data set as well smoothly ---------------------- #
# Nicely Display the source data
cat(sprintf("For Hypothesis Testing - Chi Square test :\n\n"))
cat(sprintf("\nSample size ( n ) : %s",length(data)))
cat(sprintf("\nAverage ( x bar ) : %s",my_mean(data)))
cat(sprintf("\nSample Variance ( s sq. ) : %s",my_sample_variance(data)))
cat(sprintf("\n\nTesting at l.o.s ( alpha ) : %s",myalpha))
cat(sprintf("\n\nNULL Hypothesis : \nsigma square = %s",sigmasq))
cat(sprintf("\n\nTest Results : \n"))
pvalue<- my_chi_square_test(data,sigmasq,alpha,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"))
}
})
)
}
## =========================== Shapiro Wilk test ======================================
my_shapiro_test_input<-function(){
tagList(
textInput('my_shapiro_test_input_dataOne', 'Enter Data', "1,2,3,4,5,6,7,8,9,10"),
textInput('my_shapiro_test_input_dataTwo', 'Enter level of significance (alpha) ', "0.05")
)
}
my_shapiro_test_output<-function(){
tagList(
renderPrint({
# Preparing data
data <- as.numeric(unlist(strsplit(input$my_shapiro_test_input_dataOne,",")))
myalpha <- as.numeric(unlist(strsplit(input$my_shapiro_test_input_dataTwo,",")))
# ---------------- Display data set as well smoothly ---------------------- #
# Nicely Display the source data
cat(sprintf("Shapiro Wilk Normality test :\n\n"))
cat(sprintf("\nSample size ( n ) : %s",length(data)))
cat(sprintf("\nAverage ( x bar ) : %s",my_mean(data)))
cat(sprintf("\n\nTesting at l.o.s ( alpha ) : %s",myalpha))
cat(sprintf("\n\nNULL Hypothesis : \nThe population is normally distributed."))
cat(sprintf("\n\nTest Results : \n"))
pvalue<- my_shapiro_test(data,alpha)
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"))
}
})
)
}
# ========================= END ==================================