blob: c5f06635ab7d0b3c8b9165d66491692d11721783 (
plain)
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
|
#include <iostream>
#include <stdio.h>
#include <cmath>
#include <cstring>
using namespace std;
/* Huge hack. */
/* post-process the output of tabulate.sh */
/* input:
[x1] [y1_0] [div1_0]
[x1] [y1_1] [div1_1]
...
[x2] [y2_0] [div2_0]
[x2] [y2_1] [div2_1]
...
[x] is an integer up to 100
*/
/* output:
[x1] [average y1]/[div_n] [stderr y1]
*/
static double values[100][100], sums[100], means[100], stddevs[100], stderrs[100];
static int counts[100] = { 0 };
int main()
{
memset(counts, 0, sizeof(counts));
while(cin)
{
int x;
double y;
unsigned long long div = 1;
cin >> x >> y; // >> div;
values[x][counts[x]] = y / div;
sums[x] += values[x][counts[x]];
counts[x]++;
}
for(int i = 0; i < 100; ++i)
{
if(counts[i])
{
means[i] = sums[i] / counts[i];
double var = 0;
for(int j = 0; j < counts[i]; ++j)
{
double del = (values[i][j] - means[i]);
var += del * del;
}
if(counts[i] <= 1)
stddevs[i] = 0;
else
stddevs[i] = sqrt(var / (counts[i] - 1));
stderrs[i] = stddevs[i] / sqrt(counts[i]);
/* 95% confidence interval */
double z = 1.96;
printf("%d %g %g\n", i, means[i], z * stderrs[i]);
}
}
}
|