-
Notifications
You must be signed in to change notification settings - Fork 1
/
analysis.js
129 lines (114 loc) · 3.45 KB
/
analysis.js
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
var dataOne;
var dataTwo;
process();
function process() {
//Steps:
// 1. Load in csvs of both raw data, and turk completion information.
// 2. Filter out rows from turkIDs who didn't complete the HIT.
// 5. Anonymize by replacing turkID with index in completion table.
// 6. save that sucker for the repo (in cleandata.csv)
// 7. do analysis.
var demoTable = dl.csv("demo.csv");
var dataOneTable = dl.csv("dataOne.csv");
var dataTwoTable = dl.csv("dataTwo.csv");
var cleanedOne = [];
var cleanedTwo = [];
var valids = [];
var turkId;
var row;
for(var i = 0;i<demoTable.length;i++) {
row = demoTable[i];
turkId = row.WorkerId;
valids = dataOneTable.filter(function(x){ return x.workerId == turkId;});
valids.forEach(function(d){ d.workerId = i+1;});
cleanedOne = cleanedOne.concat(valids);
valids = dataTwoTable.filter(function(x){ return x.workerId == turkId;});
valids.forEach(function(d){ d.workerId = i+1;});
cleanedTwo = cleanedTwo.concat(valids);
}
for(var i = 0;i<cleanedOne.length;i++) {
cleanedOne[i].correct = cleanedOne[i].error==0 ? 1 : 0;
cleanedOne[i].condition = cleanedOne[i].binned + cleanedOne[i].shape;
if(cleanedOne[i].vsup == "yes") {
cleanedOne[i].condition = "vsup" + cleanedOne[i].condition;
}
writeRow(cleanedOne[i]);
}
for(var i = 0;i<cleanedTwo.length;i++) {
cleanedTwo[i].condition = cleanedTwo[i].binned + cleanedTwo[i].shape;
if(cleanedTwo[i].vsup == "yes") {
cleanedTwo[i].condition = "vsup" + cleanedTwo[i].condition;
}
writeRow(cleanedTwo[i]);
}
dataOne = cleanedOne;
dataTwo = cleanedTwo;
}
function writeRow(row) {
var writeRequest = new XMLHttpRequest();
var writeString = "clean=true&answer="+JSON.stringify(row);
//console.log(writeString);
writeRequest.open("GET","writeJSON.php?"+writeString,true);
writeRequest.setRequestHeader("Content-Type", "application/json");
writeRequest.send();
}
function cleanRows(rows, index) {
var cleanedRows = [];
var seen = dl.repeat(false,100);
for(let row of rows) {
row.id = index;
if(!seen[row.index]){
seen[row.index]=true;
cleanedRows.push(row);
}
}
return cleanedRows;
}
dl.mean.iqm = function(values, f) {
if (f) values = values.map(dl.$(f));
values = values.filter(dl.isValid).sort(dl.cmp);
var mean = 0,
n = values.length,
c = n/4,
v, i;
for (i = c; i<(3*c); i+=0.25) {
v = values[Math.floor(i)];
mean+=0.25*v;
}
mean = n>0 ? mean/(2*c) : 0;
return mean;
};
dl.bootstrap.midmeanci = function(values, a, b, c, d) {
var X, N, alpha, smooth, bs, means, i;
if (dl.isFunction(a) || dl.isString(a)) {
X = values.map(dl.$(a));
N = b;
alpha = c;
smooth = d;
} else {
X = values;
N = a;
alpha = b;
smooth = c;
}
N = N ? +N : 1000;
alpha = alpha || 0.05;
bs = dl.random.bootstrap(X, smooth);
for (i=0, means = Array(N); i<N; ++i) {
means[i] = dl.mean.iqm(bs.samples(X.length));
}
means.sort(dl.numcmp);
return [
dl.quantile(means, alpha/2),
dl.quantile(means, 1-(alpha/2))
];
};
function analysis() {
dataOne = dl.csv("taskOne.csv");
dataTwo = dl.csv("taskTwo.csv");
}
function bsci(data, facet, measure) {
var values = d3.nest().key(function(d){ return d[facet];}).entries(data);
var cis = values.map(function(d){ return {"key": d.key, "midmean": dl.mean.iqm(d.values,measure), "ci": dl.bootstrap.midmeanci(d.values,measure,1000)};});
return cis;
}