forked from pieces201020/AB-Test-Sample-Size-Calculator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.R
155 lines (119 loc) · 5.14 KB
/
server.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
## 错误处理
tryIE <- function(code, silent=F){
tryCatch(code, error = function(c) '错误: 请仔细检查输入的参数是否合理。',
warning = function(c) '错误: 请仔细检查输入的参数是否合理。',
message = function(c) '错误: 请仔细检查输入的参数是否合理。')
}
shinyServer(
function(input, output) {
################################################概率类指标###################################################
numlift_prop_test <- reactive({
switch(input$lift_prop_test,"1%"=0.01,"5%" =0.05,
"10%" = 0.10,"15%"=0.15,"20%"=0.20, "50%"=0.50, "100%"=1.00)
})
numsif_prop_test <- reactive({
switch(input$sif_prop_test,"80%"=0.80,"85%" =0.85,
"90%" = 0.90,"95%"=0.95)
})
texttime_unit_prop_test <- reactive({
switch(input$time_unit_prop_test, "日"="每日","周"="每周",
"月"="每月","年"="每年")
})
textperiod_prop_test <- reactive({
switch(input$period_prop_test, "日"="日","周"="周",
"月"="月","年"="年")
})
number_prop_test <- reactive({ceiling(power.prop.test(p1=input$avgRR_prop_test/100,
p2=input$avgRR_prop_test/100*(1+input$lift_prop_test/100),
sig.level=1-numsif_prop_test(),
power=0.8)[[1]])
})
output$liftText_prop_test <- renderText({
paste('如果实验组指标为',
as.character(input$avgRR_prop_test*(1+input$lift_prop_test/100)),'% 或更高的话,',
'我们才可以观测到统计显著性结果。'
)
})
output$resulttext1_prop_test <- renderText({
"每组的样本量为 "
})
output$resultvalue1_prop_test<-renderText({
tryIE(number_prop_test())
})
output$resulttext2_prop_test <- renderText({
"总样本量为"
})
output$resultvalue2_prop_test <- renderText({
tryIE(number_prop_test()*input$num_prop_test)
})
output$resulttext3_prop_test <- renderText({
paste('需要得到总样本量的时间大约是',
as.character(tryIE(floor(number_prop_test()*input$num_prop_test/input$imps_prop_test))),
'到',
as.character(tryIE(ceiling(number_prop_test()*input$num_prop_test/input$imps_prop_test))),
as.character(textperiod_prop_test())
)
})
output$resulttext4_prop_test <- renderText({
paste('为了得到总样本量所需要的',
as.character(texttime_unit_prop_test()),
'的流量为',
as.character(tryIE(ceiling(number_prop_test()*input$num_prop_test/input$time_prop_test)))
)
})
################################################均值类指标###################################################
numlift_t_test <- reactive({
switch(input$lift_t_test,"1%"=0.01,"5%" =0.05,
"10%" = 0.10,"15%"=0.15,"20%"=0.20, "50%"=0.50, "100%"=1.00)
})
numsif_t_test <- reactive({
switch(input$sif_t_test,"80%"=0.80,"85%" =0.85,
"90%" = 0.90,"95%"=0.95)
})
texttime_unit_t_test <- reactive({
switch(input$time_unit_t_test, "日"="每日","周"="每周",
"月"="每月","年"="每年")
})
textperiod_t_test <- reactive({
switch(input$period_t_test, "日"="日","周"="周",
"月"="月","年"="年")
})
number_t_test <- reactive({ceiling(power.t.test(delta=input$lift_t_test,
sd=input$sd_t_test,
sig.level=1-numsif_t_test(),
power=0.8)[[1]])
})
output$liftText_t_test <- renderText({
paste('如果两组指标的绝对差值为',
as.character(input$lift_t_test),'或者更大的话,',
'我们才可以观测到统计显著性结果。'
)
})
output$resulttext1_t_test <- renderText({
"每组的样本量为 "
})
output$resultvalue1_t_test<-renderText({
tryIE(number_t_test())
})
output$resulttext2_t_test <- renderText({
"总样本量为"
})
output$resultvalue2_t_test <- renderText({
tryIE(number_t_test()*input$num_t_test)
})
output$resulttext3_t_test <- renderText({
paste('需要得到总样本量的时间大约是',
as.character(tryIE(floor(number_t_test()*input$num_t_test/input$imps_t_test))),
'到',
as.character(tryIE(ceiling(number_t_test()*input$num_t_test/input$imps_t_test))),
as.character(textperiod_t_test())
)
})
output$resulttext4_t_test <- renderText({
paste('为了得到总样本量所需要的',
as.character(texttime_unit_t_test()),
'的流量为',
as.character(tryIE(ceiling(number_t_test()*input$num_t_test/input$time_t_test)))
)
})
})