-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmodule_seven.R
403 lines (295 loc) · 16.1 KB
/
module_seven.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
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
# Including the core functionality
source("module_seven_core.R")
## ======================= UTILITY LIST ==========================
module_seven_list<-c( "Estimation of Means | Variance known",
"Estimation of Means | Variance Unknown",
"Estimation of Differences in Means | Variance Known",
"Estimation of Differences in Means | Variance Unknown",
"Estimation of Proportions",
"Estimation of Differences in Proportions",
"Estimation of Variances",
"Estimation of Ratio of Two Variances"
)
## ========================= I/O FUNCTIONS ==============================
## ====================== Estimation of Means ============================
my_est_mean_var_known_input<-function(){
tagList(
textInput('my_est_mean_var_known_input_dataOne', 'Enter Sample size (n)', "20"),
textInput('my_est_mean_var_known_input_dataTwo', 'Enter average (x bar)', "5"),
textInput('my_est_mean_var_known_input_dataThree', 'Enter Standard Deviation (sigma)', "2"),
textInput('my_est_mean_var_known_input_dataFour', 'Enter level of significance (alpha) ', "0.05")
)
}
my_est_mean_var_known_output<-function(){
tagList(
renderPrint({
# Preparing data
n <- as.numeric(unlist(strsplit(input$my_est_mean_var_known_input_dataOne,",")))
avg<-as.numeric(unlist(strsplit(input$my_est_mean_var_known_input_dataTwo,",")))
mySD <- as.numeric(unlist(strsplit(input$my_est_mean_var_known_input_dataThree,",")))
myalpha <- as.numeric(unlist(strsplit(input$my_est_mean_var_known_input_dataFour,",")))
# ---------------- Display data set as well smoothly ---------------------- #
# Nicely Display the source data
cat(sprintf("Estimation of Mean ( Variance known )\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("\nlevel of significance ( alpha ) : %s",myalpha))
cat(sprintf("\n\nEstimation : \n"))
interval<-my_est_mean_var_known(avg,mySD,n,myalpha)
cat(sprintf("\nMu lies in the interval :\n%s\nto\n%s",interval[1],interval[2]))
cat(sprintf("\nat (1-alpha)*100 confidence interval"))
# meu lies between interval[1] and interval[2]
# at (1-alpha) * 100 confidence interval
})
)
}
my_est_mean_var_unknown_input<-function(){
tagList(
textInput('my_est_mean_var_unknown_input_dataOne', 'Enter Data', "1,2,3,4,5,6,7,8,9,10,11,12"),
textInput('my_est_mean_var_unknown_input_dataTwo', 'Enter level of significance (alpha) ', "0.05")
)
}
my_est_mean_var_unknown_output<-function(){
tagList(
renderPrint({
# Preparing data
data <- as.numeric(unlist(strsplit(input$my_est_mean_var_unknown_input_dataOne,",")))
myalpha <- as.numeric(unlist(strsplit(input$my_est_mean_var_unknown_input_dataTwo,",")))
# ---------------- Display data set as well smoothly ---------------------- #
# Nicely Display the source data
cat(sprintf("Estimation of Mean ( Variance UNknown )\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("\nlevel of significance ( alpha ) : %s",myalpha))
if(length(data)>30){
cat(sprintf("\n\nSample size > 30\nSo it is a Normal Distribution"))
cat(sprintf("\nCalling Estimation of mean | Known Variance"))
}
cat(sprintf("\n\nEstimation : \n"))
interval<-my_est_mean_var_unknown(data,myalpha)
cat(sprintf("\nMu lies in the interval :\n%s\nto\n%s",interval[1],interval[2]))
cat(sprintf("\nat (1-alpha)*100 confidence interval"))
# meu lies between interval[1] and interval[2]
# at (1-alpha) * 100 confidence interval
})
)
}
## ====================== Estimation of Difference of Means ============================
my_est_diff_mean_var_known_input<-function(){
tagList(
textInput('my_est_diff_mean_var_known_input_dataOne', 'Enter Sample size ( n1 )', "20"),
textInput('my_est_diff_mean_var_known_input_dataTwo', 'Enter average (x bar1)', "5"),
textInput('my_est_diff_mean_var_known_input_dataThree', 'Enter Population variance (sigma sq 1)', "2"),
textInput('my_est_diff_mean_var_known_input_dataFour', 'Enter Sample size ( n2 )', "20"),
textInput('my_est_diff_mean_var_known_input_dataFive', 'Enter average (x bar2)', "5"),
textInput('my_est_diff_mean_var_known_input_dataSix', 'Enter Population variance (sigma sq 2)', "2"),
textInput('my_est_diff_mean_var_known_input_dataSeven', 'Enter level of significance (alpha) ', "0.05")
)
}
my_est_diff_mean_var_known_output<-function(){
tagList(
renderPrint({
# Preparing data
n1 <- as.numeric(unlist(strsplit(input$my_est_diff_mean_var_known_input_dataOne,",")))
n2 <- as.numeric(unlist(strsplit(input$my_est_diff_mean_var_known_input_dataFour,",")))
avg1<-as.numeric(unlist(strsplit(input$my_est_diff_mean_var_known_input_dataTwo,",")))
avg2<-as.numeric(unlist(strsplit(input$my_est_diff_mean_var_known_input_dataFive,",")))
var1 <- as.numeric(unlist(strsplit(input$my_est_diff_mean_var_known_input_dataThree,",")))
var2 <- as.numeric(unlist(strsplit(input$my_est_diff_mean_var_known_input_dataSix,",")))
myalpha <- as.numeric(unlist(strsplit(input$my_est_diff_mean_var_known_input_dataSeven,",")))
# ---------------- Display data set as well smoothly ---------------------- #
# Nicely Display the source data
cat(sprintf("Estimation of Difference of Means ( Variance known )\n\n"))
cat(sprintf("Data Set 1"))
cat(sprintf("\nSample size ( n1 ) : %s",n1))
cat(sprintf("\nAverage ( x bar 1 ) : %s",avg1))
cat(sprintf("\nPopulation Variance ( sigmasq 1 ) : %s",var1))
cat(sprintf("\n\nData Set 2"))
cat(sprintf("\nSample size ( n2 ) : %s",n2))
cat(sprintf("\nAverage ( x bar 2 ) : %s",avg2))
cat(sprintf("\nPopulation Variance ( sigmasq 2 ) : %s",var2))
cat(sprintf("\n\nlevel of significance ( alpha ) : %s",myalpha))
cat(sprintf("\n\nEstimation : \n"))
interval<-my_est_diff_mean_var_known(avg1,avg2,var1,var2,n1,n2,myalpha)
cat(sprintf("\nMu lies in the interval :\n%s\nto\n%s",interval[1],interval[2]))
cat(sprintf("\nat (1-alpha)*100 confidence interval"))
})
)
}
my_est_diff_mean_var_unknown_input<-function(){
tagList(
textInput('my_est_diff_mean_var_unknown_input_dataOne', 'Enter Data Set 1', "1,2,3,4,5,6,7,8,9,10,11,12"),
textInput('my_est_diff_mean_var_unknown_input_dataTwo', 'Enter Data Set 2', "6,3,1,2,45,8,1,12"),
textInput('my_est_diff_mean_var_unknown_input_dataThree', 'Enter level of significance (alpha) ', "0.05")
)
}
my_est_diff_mean_var_unknown_output<-function(){
tagList(
renderPrint({
# Preparing data
data1 <- as.numeric(unlist(strsplit(input$my_est_diff_mean_var_unknown_input_dataOne,",")))
data2 <- as.numeric(unlist(strsplit(input$my_est_diff_mean_var_unknown_input_dataTwo,",")))
myalpha <- as.numeric(unlist(strsplit(input$my_est_diff_mean_var_unknown_input_dataThree,",")))
# ---------------- Display data set as well smoothly ---------------------- #
# Nicely Display the source data
cat(sprintf("Estimation of Difference of Means ( Variance Unknown )\n\n"))
cat(sprintf("Data Set 1"))
cat(sprintf("\nSample size ( n1 ) : %s",length(data1)))
cat(sprintf("\nAverage ( x bar 1 ) : %s",my_mean(data1)))
cat(sprintf("\nStandard Deviation ( sigma 1 ) : %s",my_sample_SD(data1)))
# ????????????? sample sd or population
cat(sprintf("\n\nData Set 2"))
cat(sprintf("\nSample size ( n2 ) : %s",length(data2)))
cat(sprintf("\nAverage ( x bar 2 ) : %s",my_mean(data2)))
cat(sprintf("\nStandard Deviation ( sigma 2 ) : %s",my_sample_SD(data2)))
cat(sprintf("\n\nlevel of significance ( alpha ) : %s",myalpha))
if(length(data1)>30 && length(data2)>30){
cat(sprintf("\n\nBoth Sample sizes > 30\nSo it is a Normal Distribution"))
cat(sprintf("\nCalling Estimation of Difference of mean | \nKnown Variance"))
}
cat(sprintf("\n\nEstimation : \n"))
interval<-my_est_diff_mean_var_unknown(data1,data2,myalpha)
cat(sprintf("\nMu lies in the interval :\n%s\nto\n%s",interval[1],interval[2]))
cat(sprintf("\nat (1-alpha)*100 confidence interval"))
})
)
}
## ====================== Estimation of Proportions ============================
my_est_prop_input<-function(){
tagList(
textInput('my_est_prop_input_dataOne', 'Enter number of Total Outcomes (n)', "20"),
textInput('my_est_prop_input_dataTwo', 'Enter number of Favourable outcomes (fav)', "5"),
textInput('my_est_prop_input_dataThree', 'Enter level of significance (alpha) ', "0.05")
)
}
my_est_prop_output<-function(){
tagList(
renderPrint({
# Preparing data
n <- as.numeric(unlist(strsplit(input$my_est_prop_input_dataOne,",")))
fav<-as.numeric(unlist(strsplit(input$my_est_prop_input_dataTwo,",")))
myalpha <- as.numeric(unlist(strsplit(input$my_est_prop_input_dataThree,",")))
# ---------------- Display data set as well smoothly ---------------------- #
# Nicely Display the source data
cat(sprintf("Estimation of Proportions \n\n"))
cat(sprintf("\nTotal ( n ) : %s",n))
cat(sprintf("\nFavourable ( fav ) : %s",fav))
cat(sprintf("\nlevel of significance ( alpha ) : %s",myalpha))
cat(sprintf("\n\nEstimation : \n"))
interval<-my_est_prop(fav,n,myalpha)
cat(sprintf("\nMu lies in the interval :\n%s\nto\n%s",interval[1],interval[2]))
cat(sprintf("\nat (1-alpha)*100 confidence interval"))
# meu lies between interval[1] and interval[2]
# at (1-alpha) * 100 confidence interval
})
)
}
## ====================== Estimation of Difference of Proportions ============================
my_est_diff_prop_input<-function(){
tagList(
textInput('my_est_diff_prop_input_dataOne', 'Enter number of Total Outcomes for Data set 1 ( n1 )', "20"),
textInput('my_est_diff_prop_input_dataTwo', 'Enter number of Favourable outcomes for Data set 1 (fav)', "5"),
textInput('my_est_diff_prop_input_dataThree', 'Enter number of Total Outcomes for Data set 2 ( n2 )', "10"),
textInput('my_est_diff_prop_input_dataFour', 'Enter number of Favourable outcomes for Data set 2 (fav)', "2"),
textInput('my_est_diff_prop_input_dataFive', 'Enter level of significance (alpha) ', "0.05")
)
}
my_est_diff_prop_output<-function(){
tagList(
renderPrint({
# Preparing data
n1 <- as.numeric(unlist(strsplit(input$my_est_diff_prop_input_dataOne,",")))
fav1<-as.numeric(unlist(strsplit(input$my_est_diff_prop_input_dataTwo,",")))
n2 <- as.numeric(unlist(strsplit(input$my_est_diff_prop_input_dataThree,",")))
fav2<-as.numeric(unlist(strsplit(input$my_est_diff_prop_input_dataFour,",")))
myalpha <- as.numeric(unlist(strsplit(input$my_est_diff_prop_input_dataFive,",")))
# ---------------- Display data set as well smoothly ---------------------- #
# Nicely Display the source data
cat(sprintf("Estimation of Difference of Proportions \n\n"))
cat(sprintf("Data Set 1"))
cat(sprintf("\nTotal ( n1 ) : %s",n1))
cat(sprintf("\nFavourable ( fav1 ) : %s",fav1))
cat(sprintf("\n\nData Set 2"))
cat(sprintf("\nTotal ( n2 ) : %s",n2))
cat(sprintf("\nFavourable ( fav2 ) : %s",fav2))
cat(sprintf("\n\nlevel of significance ( alpha ) : %s",myalpha))
cat(sprintf("\n\nEstimation : \n"))
interval<-my_est_diff_prop(fav1,n1,fav2,n2,myalpha)
cat(sprintf("\nMu lies in the interval :\n%s\nto\n%s",interval[1],interval[2]))
cat(sprintf("\nat (1-alpha)*100 confidence interval"))
# meu lies between interval[1] and interval[2]
# at (1-alpha) * 100 confidence interval
})
)
}
## =========================== Estimation of variances ======================================
my_est_var_input<-function(){
tagList(
textInput('my_est_var_input_dataOne', 'Enter data set', "20,2,1,1,4,1,40"),
textInput('my_est_var_input_dataTwo', 'Enter Population variance ', "2"),
textInput('my_est_var_input_dataThree', 'Enter level of significance (alpha) ', "0.05")
)
}
my_est_var_output<-function(){
tagList(
renderPrint({
# Preparing data
data1 <- as.numeric(unlist(strsplit(input$my_est_var_input_dataOne,",")))
var1<-as.numeric(unlist(strsplit(input$my_est_var_input_dataTwo,",")))
myalpha <- as.numeric(unlist(strsplit(input$my_est_var_input_dataThree,",")))
# ---------------- Display data set as well smoothly ---------------------- #
# Nicely Display the source data
cat(sprintf("Estimation of Variances \n\n"))
cat(sprintf("\nSample Size ( n ) : %s",length(data1)))
cat(sprintf("\nPopulation Variance ( sigma sq ) : %s",var1))
cat(sprintf("\n\nlevel of significance ( alpha ) : %s",myalpha))
cat(sprintf("\n\nEstimation : \n"))
interval<-my_est_var(data1,var1,myalpha)
cat(sprintf("\nMu lies in the interval :\n%s\nto\n%s",interval[1],interval[2]))
cat(sprintf("\nat (1-alpha)*100 confidence interval"))
# meu lies between interval[1] and interval[2]
# at (1-alpha) * 100 confidence interval
})
)
}
## ======================= Estimation of Ratio of Two Variances ==========================
my_est_ratio_var_input<-function(){
tagList(
textInput('my_est_ratio_var_input_dataOne', 'Enter data set 1', "2,2,1,1,4,1,4"),
textInput('my_est_ratio_var_input_dataTwo', 'Enter Population variance for data set 1', "2.2"),
textInput('my_est_ratio_var_input_dataThree', 'Enter data set 2', "1,2,4,5,6,7"),
textInput('my_est_ratio_var_input_dataFour', 'Enter Population variance for data set 2 ', "3.1"),
textInput('my_est_ratio_var_input_dataFive', 'Enter level of significance (alpha) ', "0.05")
)
}
my_est_ratio_var_output<-function(){
tagList(
renderPrint({
# Preparing data
data1 <- as.numeric(unlist(strsplit(input$my_est_ratio_var_input_dataOne,",")))
var1<-as.numeric(unlist(strsplit(input$my_est_ratio_var_input_dataTwo,",")))
data2 <- as.numeric(unlist(strsplit(input$my_est_ratio_var_input_dataThree,",")))
var2<-as.numeric(unlist(strsplit(input$my_est_ratio_var_input_dataFour,",")))
myalpha <- as.numeric(unlist(strsplit(input$my_est_ratio_var_input_dataFive,",")))
# ---------------- Display data set as well smoothly ---------------------- #
# Nicely Display the source data
cat(sprintf("Estimation of Ration of Variances \n\n"))
cat(sprintf("Data Set 1"))
cat(sprintf("\nSample Size ( n1 ) : %s",length(data1)))
cat(sprintf("\nPopulation Variance ( sigma sq1 ) : %s",var1))
cat(sprintf("\n\nData Set 2"))
cat(sprintf("\nSample Size ( n1 ) : %s",length(data2)))
cat(sprintf("\nPopulation Variance ( sigma sq1 ) : %s",var2))
cat(sprintf("\n\nlevel of significance ( alpha ) : %s",myalpha))
cat(sprintf("\n\nEstimation : \n"))
interval<-my_est_ratio_var(data1,data2,var1,var2,myalpha)
cat(sprintf("\nMu lies in the interval :\n%s\nto\n%s",interval[1],interval[2]))
cat(sprintf("\nat (1-alpha)*100 confidence interval"))
# meu lies between interval[1] and interval[2]
# at (1-alpha) * 100 confidence interval
})
)
}
## ======================= END ==========================