Module: SpatialStats::Utils

Defined in:
lib/spatial_stats/utils.rb,
lib/spatial_stats/utils/lag.rb

Overview

The Utils module contains various utilities used in the gem.

Defined Under Namespace

Modules: Lag

Class Method Summary collapse

Class Method Details

.fdr(pvals, alpha) ⇒ Object

Compute the false discovery rate (FDR) of a set of p-values given an alpha value.

If there is no FDR available in the dataset, the Bonferroni Bound is returned instead.

Parameters:

  • pvals (Array)

    from an mc test

  • alpha (Float)

    value for the fdr



20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/spatial_stats/utils.rb', line 20

def self.fdr(pvals, alpha)
  n = pvals.size
  b_bound = alpha / n
  pvals.sort!

  p_val = b_bound
  (0..n - 1).each do |i|
    p_fdr = (i + 1) * b_bound
    break unless pvals[i] <= p_fdr

    p_val = p_fdr
  end
  p_val
end