-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtable_beta_old.html
485 lines (418 loc) · 18.6 KB
/
table_beta_old.html
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
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
<html>
<head>
<title>Single-Cell Sample Size</title>
<link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css">
<style>
* {
box-sizing: border-box;
}
body, html {
height: 100%;
margin: 0;
font-family: Arial;
}
/* Style tab links */
.tablink {
border-radius: 10px 10px 0px 0px;
background-color: #555;
color: white;
float: left;
border: none;
outline: none;
cursor: pointer;
padding: 8px 16px;
font-size: 17px;
width: 300px;
height: 40px;
}
.tablink:hover {
background-color: #777;
}
/* Style the tab content (and add height:100% for full page content) */
.tabcontent {
/*color: white;*/
display: none;
padding: 40px 0px;
height: 100%;
}
.row {
display: flex;
}
.column1 {
flex: 100%;
border-radius: 10px;
border: 2px solid #73AD21;
padding: 10px;
margin: 3px;
}
.column {
flex: 50%;
border-radius: 10px;
border: 2px solid #73AD21;
padding: 10px;
margin: 3px;
}
.column30 {
flex: 30%;
border-radius: 10px;
border: 2px solid #73AD21;
padding: 10px;
margin: 3px;
min-width: 300px;
}
.column40 {
flex: 40%;
border-radius: 10px;
border: 2px solid #73AD21;
padding: 10px;
margin: 3px;
}
.column70 {
flex: 70%;
border-radius: 10px;
border: 2px solid #73AD21;
padding: 10px;
margin: 3px;
}
label {
display: inline-block;
width: 150px;
text-align: left;
}
input[type=number] {
width:100px;
margin: 2px;
padding-left: 3px;
border: none; /* <-- This thing here */
border:solid 1px #ccc;
border-radius: 3px;
}
</style>
<script src="https://cdn.jsdelivr.net/npm/jstat@latest/dist/jstat.min.js"></script>
<script src='https://cdn.plot.ly/plotly-latest.min.js'></script>
<script type="text/javascript">
function betaStatParam(m, std)
{
m = parseFloat(m);
var v = parseFloat(std);
v = v * v;
var a = ((1 - m) / v - 1 / m) * m * m;
var b = a * (1 / m - 1)
return [a, b]
}
function betaParamStat(a, b)
{
a = parseFloat(a);
b = parseFloat(b);
var m = a / (a + b);
var v = a * b / Math.pow(a + b, 2) / (a + b + 1);
return [m, Math.sqrt(v)];
}
function execBetaParamStat(suffix)
{
var temp = betaParamStat(document.getElementById("a".concat(suffix)).value, document.getElementById("b".concat(suffix)).value);
document.getElementById("mean".concat(suffix)).value = round(temp[0], 4);
document.getElementById("std".concat(suffix)).value = round(temp[1], 4);
}
function execBetaStatParam(suffix)
{
var temp = betaStatParam(document.getElementById("mean".concat(suffix)).value, document.getElementById("std".concat(suffix)).value);
document.getElementById("a".concat(suffix)).value = round(temp[0], 3);
document.getElementById("b".concat(suffix)).value = round(temp[1], 3);
}
function calcBeta(M0, M1, N0, N1, a0, a1, b0, b1, alpha)
{
N0 = parseFloat(N0);
N1 = parseFloat(N1);
M0 = parseFloat(M0);
M1 = parseFloat(M1);
a0 = parseFloat(a0);
a1 = parseFloat(a1);
b0 = parseFloat(b0);
b1 = parseFloat(b1);
alpha = parseFloat(alpha);
Ep0 = a0 / (a0 + b0);
Ep1 = a1 / (a1 + b1);
Vp0 = a0 * b0 * (a0 + b0 + N0) / ((N0 * (a0 + b0) * (a0 + b0)) * (a0 + b0 + 1));
Vp1 = a1 * b1 * (a1 + b1 + N1) / ((N1 * (a1 + b1) * (a1 + b1)) * (a1 + b1 + 1));
Et = Math.abs(Ep1 - Ep0) / Math.sqrt(Vp0 / M0 + Vp1 / M1);
nu = (Vp0 / M0 + Vp1 / M1) ** 2 / ((Vp0 / M0) ** 2 / (M0 - 1) + (Vp1 / M1) ** 2 / (M1 - 1));
t_star1 = jStat.studentt.inv(1 - alpha, nu);
t_star2 = jStat.studentt.inv(1 - alpha / 2, nu);
return [jStat.normal.cdf(t_star1 - Et, 0, 1), jStat.normal.cdf(t_star2 - Et, 0, 1)]
}
function round(x, p) {return Math.round(x * Math.pow(10, p)) / Math.pow(10, p)}
function execCalcBeta()
{
var M0_min = parseFloat(document.getElementById("M0_min").value);
var M0_max = parseFloat(document.getElementById("M0_max").value);
var M1_min = parseFloat(document.getElementById("M1_min").value);
var M1_max = parseFloat(document.getElementById("M1_max").value);
var N0 = document.getElementById("N0").value;
var N1 = document.getElementById("N1").value;
var a0 = document.getElementById("a0").value;
var a1 = document.getElementById("a1").value;
var b0 = document.getElementById("b0").value;
var b1 = document.getElementById("b1").value;
var alpha = document.getElementById("alpha").value;
var beta = parseFloat(document.getElementById("beta").value);
var output1 = "<table class='w3-table' border='1' width='500' cellspacing='0'cellpadding='5'>";
var output2 = "<table class='w3-table' border='1' width='500' cellspacing='0'cellpadding='5'>";
output1 = output1 + "<tr>";
output2 = output2 + "<tr>";
output1 = output1 + "<td>" + "ctrl \\ exp" + "</td>";
output2 = output2 + "<td>" + "ctrl \\ exp" + "</td>";
for (j = M1_min; j <= M1_max; j++)
{
output1 = output1 + "<td>" + j + "</td>";
output2 = output2 + "<td>" + j + "</td>";
}
output1 = output1 + "</tr>";
output2 = output2 + "</tr>";
for(i = M0_min; i <= M0_max; i++)
{
output1 = output1 + "<tr>";
output2 = output2 + "<tr>";
output1 = output1 + "<td>" + i + "</td>";
output2 = output2 + "<td>" + i + "</td>";
for (j = M1_min; j <= M1_max; j++)
{
var temp = calcBeta(i, j, N0, N1, a0, a1, b0, b1, alpha)
if (temp[0] < beta) output1 = output1 + "<td bgcolor=#E0E0E0>" + round(temp[0], 3) + "</td>";
else output1 = output1 + "<td>" + round(temp[0], 3) + "</td>";
if (temp[1] < beta) output2 = output2 + "<td bgcolor=#E0E0E0>" + round(temp[1], 3) + "</td>";
else output2 = output2 + "<td>" + round(temp[1], 3) + "</td>";
}
output1 = output1 + "</tr>";
output2 = output2 + "</tr>";
}
output1 = output1 + "</table>";
output2 = output2 + "</table>";
document.getElementById("M0_min").value
if (document.getElementById('one_sided').checked) document.getElementById("result").innerHTML = output1;
else document.getElementById("result").innerHTML = output2;
//document.getElementById("results").scrollIntoView();
}
function plotBeta()
{
var a0 = parseFloat(document.getElementById("a0").value);
var a1 = parseFloat(document.getElementById("a1").value);
var b0 = parseFloat(document.getElementById("b0").value);
var b1 = parseFloat(document.getElementById("b1").value);
x = []
y = []
for (i = 0.0; i <= 1.0; i = i + 0.01) x.push(i)
for (i = 0; i < x.length; i++) y.push(jStat.beta.pdf(x[i], a0, b0))
console.log(jStat.beta.pdf(0.5, 2, 2));
var ctrl = {
x: x,
y: y,
type: 'scatter',
name: 'Control'
};
y = []
for (i = 0; i < x.length; i++) y.push(jStat.beta.pdf(x[i], a1, b1))
var exp = {
x: x,
y: y,
type: 'scatter',
name: 'Experimental'
};
var data = [ctrl, exp];
var layout = {showlegend: true, legend: {"orientation": "h"}, height: 300, width: 400,
margin: {
l: 50,
r: 50,
b: 50,
t: 50,
pad: 4
}
};
Plotly.newPlot('plot', data, layout)
}
function init()
{
document.getElementById("M0_min").value = 5;
document.getElementById("M1_min").value = 5;
document.getElementById("M0_max").value = 12;
document.getElementById("M1_max").value = 12;
document.getElementById("N0").value = 1000;
document.getElementById("N1").value = 1000;
document.getElementById("a0").value = 7;
document.getElementById("a1").value = 10;
document.getElementById("b0").value = 10;
document.getElementById("b1").value = 7;
document.getElementById("alpha").value = 0.05;
document.getElementById("beta").value = 0.1;
execBetaParamStat(0);
execBetaParamStat(1);
plotBeta();
}
</script>
</head>
<body>
<button class="tablink" onclick="openPage('main', this, 'green')" id="defaultOpen">Power Estimation</button>
<button class="tablink" onclick="openPage('instructions', this, 'green')">Instructions</button>
<div class="tabcontent" id="main">
<div class="row">
<div class="column30">
<h2>Control group</h2>
<div class="block">
<label for="">Range of samples M<sub>0</sub></label>
<input type="number" id="M0_min" value="" style="width: 45px;">
~
<input type="number" id="M0_max" value="" style="width: 45px;">
</div>
<div class="block">
<label for="N0">Number of cells N<sub>0</sub></label>
<input type="number" id="N0" value="" step=100>
</div>
<h3>Beta distribution</h3>
<h4><b>Specify</b> Mean and variance</h4>
<div class="block">
<label for="mean0">Mean</label>
<input type="number" id="mean0" value="" step="0.05" min="0.05" max="0.95" onchange="execBetaStatParam(0); plotBeta();">
</div>
<div class="block">
<label for="">Standard deviation</label>
<input type="number" id="std0" value="" step="0.01" min="0.001" onchange="execBetaStatParam(0); plotBeta();">
</div>
<h4><b>or</b> a<sub>0</sub> and b<sub>0</sub></h4>
<div class="block">
Beta(a<sub>0</sub> =
<input type="number" id="a0" value="" step="1" min="1" style="width: 70px" onchange="execBetaParamStat(0); plotBeta();">
, b<sub>0</sub> =
<input type="number" id="b0" value="" step="1" min="1" style="width: 70px" onchange="execBetaParamStat(0); plotBeta();">
)
</div>
</div>
<div class="column30">
<h2>Experimental group</h2>
<label for="">Range of samples M<sub>1</sub></label>
<input type="number" id="M1_min" value="" style="width: 45px;">
~
<input type="number" id="M1_max" value="" style="width: 45px;">
<div class="block">
<label for="N1">Number of cells N<sub>1</sub></label>
<input type="number" id="N1" value="" step=100>
</div>
<h3>Beta distribution</h3>
<h4><b>Specify</b> Mean and variance</h4>
<div class="block">
<label for="mean1">Mean</label>
<input type="number" id="mean1" value="" step="0.05" min="0.05" max="0.95" onchange="execBetaStatParam(1); plotBeta();">
</div>
<div class="block">
<label for="">Standard deviation</label>
<input type="number" id="std1" value="" step="0.01" min="0.001" onchange="execBetaStatParam(1); plotBeta();">
</div>
<h4><b>or</b> a<sub>1</sub> and b<sub>1</sub></h4>
<div class="block">
Beta(a<sub>1</sub> =
<input type="number" id="a1" value="" step="1" min="1" style="width: 70px" onchange="execBetaParamStat(1); plotBeta();">
, b<sub>1</sub> =
<input type="number" id="b1" value="" step="1" min="1" style="width: 70px" onchange="execBetaParamStat(1); plotBeta();">
)
</div>
</div>
<div class="column40">
<h2>Visualize Beta-distributions</h2>
<div id='plot'><!-- Plotly chart will be drawn inside this DIV --></div>
<div>The graph will update when the Beta-distributions change.</div>
</div>
</div>
<div class="row">
<div class="column30">
<h2>t-Test</h2>
<div>
<div class="block">
<label for="alpha">False positive rate α</label>
<input type="number" id="alpha" value="" step=0.01>
</div>
<div class="block">
<label for="beta">False negative threshold β<sub>th</sub></label>
<input type="number" id="beta" value="" step=0.01>
</div>
<div>
<h3>Type</h3>
<div>
<input type="radio" id="one_sided" name="test_type" value="one_sided" checked>
<label for="One-sided t-test">One-sided t-test</label>
</div>
<div>
<input type="radio" id="two_sided" name="test_type" value="two_sided">
<label for="Two-sided t-test">Two-sided t-test</label>
</div>
</div>
</div>
<!--<input type="button" id="create" value="Calculate beta table" onclick="execCalcBeta(); "/>-->
</div>
<div class="column70">
<h2>Result: False-negative rate β</h2>
<div>
<div id="result">
Results pending calculating...
</div>
</div>
<div>False negative rates. Lower is better. Each row correponds to a fixed number of control samples.
Each row correponds to a fixed number of experimental samples. Values pass β<sub>th</sub> are colored in gray.
</div>
</div>
</div>
</div>
<div class="tabcontent" id="instructions">
<div class="row">
<div class="column">
<h2>Instructions</h2>
<ol>
<li>Set range of M<sub>0</sub> and M<sub>1</sub>, i.e., the numbers of samples in control group and experimental group, respectively.</li>
<li>Set N<sub>0</sub> and N<sub>1</sub> for number of cells in each sample for each group. (Total number of cells = M<sub>0</sub>N<sub>0</sub> + M<sub>1</sub>N<sub>1</sub>) </li>
<li>Set mean and standard deviation for proportion of a cell type. This corresponds to variances among samples in a group. <b>Alternatively</b>, set a and b for each beta distribution.</li>
<li>Set α, it is the threshold for a significant p-value. 0.05 and 0.01 are commonly used.</li>
<li>Set threshold β<sub>th</sub> for preferred false negative rate. It is the probability of failing to yield a siginificant result.</li>
<li>Choose from one-sided test and two-sided test.</li>
</ol>
The table will automatically refresh when a value is changed.
</div>
</div>
<div class="row">
<div class="column">
<h2>Q&A</h2>
</div>
</div>
<div class="row">
<div class="column">
<h2>About</h2>
Github: <a href="https://github.com/KChen-lab/sensei">https://github.com/KChen-lab/sensei</a>
</div>
</div>
</div>
</body>
<script>
init();
function openPage(pageName, elmnt, color) {
// Hide all elements with class="tabcontent" by default */
var i, tabcontent, tablinks;
tabcontent = document.getElementsByClassName("tabcontent");
for (i = 0; i < tabcontent.length; i++) {
tabcontent[i].style.display = "none";
}
// Remove the background color of all tablinks/buttons
tablinks = document.getElementsByClassName("tablink");
for (i = 0; i < tablinks.length; i++) {
tablinks[i].style.backgroundColor = "";
}
// Show the specific tab content
document.getElementById(pageName).style.display = "block";
// Add the specific color to the button used to open the tab content
elmnt.style.backgroundColor = color;
}
// Get the element with id="defaultOpen" and click on it
document.getElementById("defaultOpen").click();
var inputs = document.getElementsByTagName("input");
for (i=0; i<inputs.length; i++){
inputs[i].setAttribute('onchange', inputs[i].getAttribute('onchange') + '; execCalcBeta();');
}
execCalcBeta();
</script>
</html>