time-to-botec

Benchmark sampling in different programming languages
Log | Files | Refs | README

by.js (1688B)


      1 /**
      2 * @license Apache-2.0
      3 *
      4 * Copyright (c) 2020 The Stdlib Authors.
      5 *
      6 * Licensed under the Apache License, Version 2.0 (the "License");
      7 * you may not use this file except in compliance with the License.
      8 * You may obtain a copy of the License at
      9 *
     10 *    http://www.apache.org/licenses/LICENSE-2.0
     11 *
     12 * Unless required by applicable law or agreed to in writing, software
     13 * distributed under the License is distributed on an "AS IS" BASIS,
     14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     15 * See the License for the specific language governing permissions and
     16 * limitations under the License.
     17 */
     18 
     19 'use strict';
     20 
     21 // MODULES //
     22 
     23 var min = require( '@stdlib/math/base/special/min' );
     24 var cumin = require( './../../base/cumin' );
     25 var Float64Array = require( '@stdlib/array/float64' );
     26 var order = require( './order.js' );
     27 
     28 
     29 // MAIN //
     30 
     31 /**
     32 * Adjusts the p-values via the Benjamini & Yekutieli method.
     33 *
     34 * @private
     35 * @param {ProbabilityArray} pvalues - p-values to be adjusted
     36 * @param {PositiveInteger} comparisons - number of comparisons
     37 * @returns {ProbabilityArray} adjusted p-values
     38 */
     39 function by( pvalues, comparisons ) {
     40 	var indices;
     41 	var sorted;
     42 	var len;
     43 	var out;
     44 	var i;
     45 	var q;
     46 
     47 	len = pvalues.length;
     48 	indices = order( pvalues, true );
     49 	q = 0;
     50 	for ( i = 0; i < comparisons; i++ ) {
     51 		q += 1 / ( 1 + i );
     52 	}
     53 	sorted = new Float64Array( len );
     54 	for ( i = 0; i < len; i++ ) {
     55 		sorted[ i ] = q * comparisons / ( len - i ) * pvalues[ indices[ i ] ];
     56 	}
     57 	sorted = cumin( len, sorted, 1, sorted, 1 );
     58 	out = new Array( len );
     59 	for ( i = 0; i < len; i++ ) {
     60 		out[ indices[ i ] ] = min( sorted[ i ], 1.0 );
     61 	}
     62 	return out;
     63 }
     64 
     65 
     66 // EXPORTS //
     67 
     68 module.exports = by;