3 * given an array of arrays dataset ([[A, 1], [B, 2], [C, 4], [D, 1]]),
4 it standardizes dependent variable values (calculates z-scores), calculates probabilties
5 and returns an array of js objects of the form
6 [{x: xvalue, y: yvalue, z: z-score , p: probability}, ....]
8 * uses methods from statistics/simple_statistics js library
10 * Isaak Y Tecle <iyt2@cornell.edu>
14 var solGS = solGS || function solGS () {};
16 solGS.normalDistribution = function () {};
19 solGS.normalDistribution.prototype.getNormalDistData = function (xy) {
21 var yValues = this.getYValues(xy);
23 var mean = ss.mean(yValues);
24 var std = ss.standard_deviation(yValues);
26 var normalDistData = [];
28 for (var i=0; i < xy.length; i++) {
32 y = d3.format('.2f')(y);
33 var z = ss.z_score(y, mean, std);
34 z = d3.format('.2f')(z);
35 var p = ss.cumulative_std_normal_probability(z);
41 normalDistData.push({'x': x, 'y': y, 'z': z, 'p': p});
44 return normalDistData;
48 solGS.normalDistribution.prototype.getPValues = function (normalData) {
52 for (var i=0; i < normalData.length; i++) {
53 var pV = normalData[i].p;
62 solGS.normalDistribution.prototype.getXValues = function (xy) {
66 for (var i=0; i < xy.length; i++) {
68 x = x.replace(/^\s+|\s+$/g, '');
77 solGS.normalDistribution.prototype.getYValues = function (xy) {
81 for (var i=0; i < xy.length; i++) {
93 solGS.normalDistribution.prototype.getYValuesZScores = function (normalData) {
97 for (var i=0; i < normalData.length; i++) {
98 var y = normalData[i].y;
99 var z = normalData[i].z;
108 solGS.normalDistribution.prototype.getZScoresP = function (normalData) {
112 for (var i=0; i < normalData.length; i++) {
113 var zV = normalData[i].z;
114 var pV = normalData[i].p;
123 solGS.normalDistribution.prototype.getYValuesP = function (normalData) {
127 for (var i=0; i < normalData.length; i++) {
128 var x = normalData[i].y;
129 var y = normalData[i].p;
138 solGS.normalDistribution.prototype.getObsValueZScore = function (obsValuesZScores, zScore) {
141 for (var i=0; i < obsValuesZScores.length; i++) {
143 var j = obsValuesZScores[i];
145 if (obsValuesZScores[i][1] == zScore) {
146 obsValue = obsValuesZScores[i][0];
150 return [obsValue, zScore];