-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsingle_beta.html
269 lines (240 loc) · 9.79 KB
/
single_beta.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
<html>
<head>
<title>Beta for a single sample size</title>
<style>
* {
box-sizing: border-box;
}
.row {
display: flex;
}
.column {
flex: 50%;
padding: 10px;
}
label {
display: inline-block;
width: 150px;
text-align: left;
}
</style>
<script src="https://cdn.jsdelivr.net/npm/jstat@latest/dist/jstat.min.js"></script>
<script type="text/javascript">
function createTable()
{
var M0 = document.getElementById('N0').value;
var M1 = document.getElementById('N1').value;
var j=1;
var output = "<table border='1' width='500' cellspacing='0'cellpadding='5'>";
for(i=1;i<=M0;i++)
{
output = output + "<tr>";
while(j<=M1)
{
output = output + "<td>" + i*j + "</td>";
j = j+1;
}
output = output + "</tr>";
j = 1;
}
output = output + "</table>";
document.getElementById("holder").innerHTML = output;
}
function betaStatParam(m, std)
{
m = parseFloat(m);
var v = parseFloat(std);
v = v * v;
document.getElementById("holder").innerHTML = m;
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], 5);
document.getElementById("std".concat(suffix)).value = round(temp[1], 5);
}
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], 5);
document.getElementById("b".concat(suffix)).value = round(temp[1], 5);
}
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 temp = calcBeta(document.getElementById("M0").value,
document.getElementById("M1").value,
document.getElementById("N0").value,
document.getElementById("N1").value,
document.getElementById("a0").value,
document.getElementById("a1").value,
document.getElementById("b0").value,
document.getElementById("b1").value,
document.getElementById("alpha").value)
document.getElementById("beta1").value = round(temp[0], 5);
document.getElementById("beta2").value = round(temp[1], 5);
}
function init()
{
document.getElementById("M0").value = 10;
document.getElementById("M1").value = 10;
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;
execBetaParamStat(0);
execBetaParamStat(1)
}
</script>
</head>
<body>
<div class="row">
<div class="column">
<h2>Control sample beta(a, b)</h2>
<div class="block">
<label for="M0">Number of samples M0</label>
<input type="number" id="M0" value="">
</div>
<div class="block">
<label for="N0">Number of cells N0</label>
<input type="number" id="N0" value="">
</div>
<h3>Beta distribution</h3>
<h4>Mean and variance</h4>
<div class="block">
<label for="mean0">Mean</label>
<input type="number" id="mean0" value="" step="0.1" onchange="execBetaStatParam(0)">
</div>
<div class="block">
<label for="">Std</label>
<input type="number" id="std0" value="" step="0.1" onchange="execBetaStatParam(0)">
</div>
<h4>a and b</h4>
<div class="block">
<label for="">a0</label>
<input type="number" id="a0" value="" step="1" onchange="execBetaParamStat(0)">
</div>
<div class="block">
<label for="">b0</label>
<input type="number" id="b0" value="" step="1" onchange="execBetaParamStat(0)">
</div>
</div>
<div class="column">
<h2>Experimental sample beta(a, b)</h2>
<div class="block">
<label for="M1">Number of samples M1</label>
<input type="number" id="M1" value="">
</div>
<div class="block">
<label for="N1">Number of cells N1</label>
<input type="number" id="N1" value="">
</div>
<h3>Beta distribution</h3>
<h4>Mean and variance</h4>
<div class="block">
<label for="mean1">Mean</label>
<input type="number" id="mean1" value="" step="0.1" onchange="execBetaStatParam(1)">
</div>
<div class="block">
<label for="">Std</label>
<input type="number" id="std1" value="" step="0.1" onchange="execBetaStatParam(1)">
</div>
<h4>a and b</h4>
<div class="block">
<label for="">a0</label>
<input type="number" id="a1" value="" step="1" onchange="execBetaParamStat(1)">
</div>
<div class="block">
<label for="">b0</label>
<input type="number" id="b1" value="" step="1" onchange="execBetaParamStat(1)">
</div>
</div>
</div>
<div class="row">
<div class="column">
<h2>False positive rate α</h2>
<div>
<div class="block">
<label for="alpha">False positive rate α</label>
<input type="number" id="alpha" value="">
</div>
</div>
<input type="button" id="create" value="Calculate beta" onclick="execCalcBeta();"/>
</div>
</div>
<div class="row">
<div class="column">
<h2>Result</h2>
<h3>One-sided</h3>
<div>
<div class="block">
<label for="beta1">False negative rate β</label>
<input type="number" id="beta1" value="">
</div>
</div>
<h3>Two-sided</h3>
<div>
<div class="block">
<label for="beta2">False negative rate β</label>
<input type="number" id="beta2" value="">
</div>
</div>
<div id="holder"> debug </div>
</div>
</div>
<div class="row">
<div class="column">
<h2>Instructions</h2>
You have M0 control samples, and M1 experimental samples.
You do single-cell sequencing on each of the samples.
You have an estimate of N0 and N1 cells resulting from each sample.
(Note: cells in cell types whose number may vary a lot should be excluded to avoid composition effect.)
<br /><br />
For each sample, you have an estimate of the proportion of the cell type you are interested in, that is "Mean".
You also have an estimate of how the proportion may vary in different donors, that is "Std".
<br /><br />
You then choose a threshold of p-value, say 0.05.
<br /><br />
You can now calculate the probability of getting a false negative result.
</div>
</div>
</body>
<script>
init();
</script>
</html>