How to use the d3-array.deviation function in d3-array

To help you get started, we’ve selected a few d3-array examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github DefinitelyTyped / DefinitelyTyped / d3-array / d3-array-tests.ts View on Github external
numOrUndefined = d3Array.quantile(mixedObjectArray, 0.5, accessorMixedObjectToNum);
numOrUndefined = d3Array.quantile(mixedObjectOrUndefinedArray, 0.5, accessorMixedObjectToNumOrUndefined);

// sum() -----------------------------------------------------------------------

numOrUndefined = d3Array.sum(numbersArray);
numOrUndefined = d3Array.sum(numericArray);
numOrUndefined = d3Array.sum(numbersOrUndefinedArray);

numOrUndefined = d3Array.sum(mixedObjectArray, accessorMixedObjectToNum);
numOrUndefined = d3Array.sum(mixedObjectOrUndefinedArray, accessorMixedObjectToNumOrUndefined);

// deviation() -----------------------------------------------------------------

numOrUndefined = d3Array.deviation(numbersArray);
numOrUndefined = d3Array.deviation(numericArray);
numOrUndefined = d3Array.deviation(numbersOrUndefinedArray);

numOrUndefined = d3Array.deviation(mixedObjectArray, accessorMixedObjectToNum);
numOrUndefined = d3Array.deviation(mixedObjectOrUndefinedArray, accessorMixedObjectToNumOrUndefined);

// variance() ------------------------------------------------------------------

numOrUndefined = d3Array.variance(numbersArray);
numOrUndefined = d3Array.variance(numericArray);
numOrUndefined = d3Array.variance(numbersOrUndefinedArray);

numOrUndefined = d3Array.variance(mixedObjectArray, accessorMixedObjectToNum);
numOrUndefined = d3Array.variance(mixedObjectOrUndefinedArray, accessorMixedObjectToNumOrUndefined);

// -----------------------------------------------------------------------------
// Test Searching Arrays
github Datawheel / canon / packages / cms / src / api / cmsRoute.js View on Github external
const formatter = (members, data, dimension, level) => {

  const newData = members.reduce((arr, d) => {
    const obj = {};
    obj.id = `${d.key}`;
    obj.name = d.name;
    obj.display = d.caption || d.name;
    obj.zvalue = data[obj.id] || 0;
    obj.dimension = dimension;
    obj.hierarchy = level;
    obj.stem = -1;
    arr.push(obj);
    return arr;
  }, []);
  const st = d3Array.deviation(newData, d => d.zvalue);
  const average = d3Array.median(newData, d => d.zvalue);
  newData.forEach(d => d.zvalue = (d.zvalue - average) / st);
  return newData;
};
github Datawheel / canon / packages / vizbuilder / src / helpers / math.js View on Github external
export function relativeStdDev(data, measureName) {
  const dataPoints = data.map(d => d[measureName]);
  return deviation(dataPoints) / mean(dataPoints);
}
github rrag / react-stockcharts / src / lib / interactive / components / LinearRegressionChannelWithArea.js View on Github external
const xys = combine(xs, ys);
	const xSquareds = xs.map(x => Math.pow(x, 2));

	const b = (n * sum(xys) - sum(xs) * sum(ys)) / (n * sum(xSquareds) - Math.pow(sum(xs), 2));
	const a = (sum(ys) - b * sum(xs)) / n;

	const newy1 = a + b * x1Value;
	const newy2 = a + b * x2Value;

	const x1 = xScale(x1Value);
	const y1 = yScale(newy1);
	const x2 = xScale(x2Value);
	const y2 = yScale(newy2);

	const stdDev = type === "SD"
		? deviation(array, d => d.close)
		: 0;

	const dy = yScale(newy1 - stdDev) - y1;

	return {
		x1, y1, x2, y2, dy
	};
}
github keplergl / kepler.gl / src / utils / aggregate-utils.js View on Github external
uniques[val] = uniques[val] || 0;
          uniques[val] += 1;
          return uniques;
        }, {})
      ).length;
    case AGGREGATION_TYPES.mode:
      return getMode(data);

    case AGGREGATION_TYPES.maximum:
      return max(data);
    case AGGREGATION_TYPES.minimum:
      return min(data);
    case AGGREGATION_TYPES.median:
      return median(data);
    case AGGREGATION_TYPES.stdev:
      return deviation(data);
    case AGGREGATION_TYPES.sum:
      return sum(data);
    case AGGREGATION_TYPES.variance:
      return variance(data);
    default:
      return data.length;
  }
}
github rrag / react-stockcharts / src / lib / calculator / bollingerband.js View on Github external
.accumulator((values) => {
				const avg = last(values).mean;
				const stdDev = deviation(values, (each) => source(each.datum));
				return {
					top: avg + multiplier * stdDev,
					middle: avg,
					bottom: avg - multiplier * stdDev
				};
			});
github broadinstitute / gtex-viz / src / modules / kde.js View on Github external
nrd: function(x) {
        let iqr = quantile(x, 0.75) - quantile(x, 0.25);
        let h = iqr / 1.34;
        return 1.06 * Math.min(deviation(x), h) * Math.pow(x.length, -1/5);
    }
};