Get χ² score

@param int   $df Degrees of freedom
@param float $p P value

@return float χ² score

@throws Exception\BadDataException
351411
public static function getChiSquareValue(int $df, float $p): float
    {
        if (isset(self::CHI_SQUARED_SCORES[$df][sprintf('%1.3f', $p)])) {
            return self::CHI_SQUARED_SCORES[$df][sprintf('%1.3f', $p)];
        }

        throw new Exception\BadDataException("No chi-squared value for degrees of freedom $df and p value " . sprintf('%1.3f', $p));
    }
1009084
public function inverse($p)
    {
        $x = $p->x;
        $y = $p->y;

        $L = atan(sinh(($x - $this->xs) / $this->n2) / cos(($y - $this->ys) / $this->n2));
        $lat1 = asin(sin(($y - $this->ys) / $this->n2 ) / cosh(($x - $this->xs) / $this->n2));
        $LC = Common::latiso(0.0, $lat1, sin($lat1));

        $p->x = $this->lc + $L / $this->rs;
        $p->y = Common::invlatiso($this->e, ($LC - $this->cp) / $this->rs);

        return $p;
    }
1144995
double getThreshold(String x, String y, double p) {
		return 2 * Math.max(x.length(), y.length()) * (1 - p);
	}
941756
def predict_df(self, df, pstate_col=PSTATE_COL):
        
        scores = {}
        for label, pohmm in self.pohmms.items():
            scores[label] = pohmm.score_df(df, pstate_col=pstate_col)
        max_score_label = max(scores.items(), key=itemgetter(1))[0]
        return max_score_label, scores
601112
public function pNorm(float $p = 3.)
    {
        if ($p <= 0.) {
            throw new InvalidArgumentException('P must be greater'
                . " than 0, $p given.");
        }

        return $this->abs()->powScalar($p)->sum() ** (1. / $p);
    }
16503
public double quantile2tiled(double p) {
        if (p < 0.0 || p > 1.0) {
            throw new IllegalArgumentException("Invalid p: " + p);
        }

        double x = Beta.inverseRegularizedIncompleteBetaFunction(0.5 * nu, 0.5, 1.0 - p);
        return Math.sqrt(nu * (1.0 - x) / x);
    }
805773
public static double getPvalue(FlatDataCollection flatDataCollection, double median) {
        int n=0;
        AssociativeArray Di = new AssociativeArray();
        Iterator<Double> it = flatDataCollection.iteratorDouble();
        while(it.hasNext()) {
            double delta=it.next()-median;

            if(delta==0.0) {
                continue; //don't count it at all
            }

            String key="+";
            if(delta<0) {
                key="-";
            }
            Di.put(key+String.valueOf(n), Math.abs(delta));
            ++n;
        }
        if(n<=0) {
            throw new IllegalArgumentException("The provided collection can't be empty.");
        }

        //converts the values of the table with its Ranks
        Ranks.getRanksFromValues(Di);
        double W=0.0;
        for(Map.Entry<Object, Object> entry : Di.entrySet()) {
            String key = entry.getKey().toString();
            Double rank = TypeInference.toDouble(entry.getValue());
        
            if(key.charAt(0)=='+') {
                W+=rank;
            }
        }

        double pvalue= scoreToPvalue(W, n);

        return pvalue;
    }
1090105
public static int dp2px(Context context, float dpVal) {
        return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,
                dpVal, context.getResources().getDisplayMetrics());
    }
177021
private String getDPT()
	{
		final String dpt = (String) options.get("dpt");
		if (dpt.equals("switch"))
			return "1.001";
		if (dpt.equals("bool"))
			return "1.002";
		if (dpt.equals("string"))
			return "16.001";
		if (dpt.equals("float"))
			return "9.002";
		if (dpt.equals("ucount"))
			return "5.010";
		if (dpt.equals("angle"))
			return "5.003";
		return dpt;
	}
269631
public BigramCollocation[] find(Corpus corpus, double p) {
        if (p <= 0.0 || p >= 1.0) {
            throw new IllegalArgumentException("Invalid p = " + p);
        }

        double cutoff = chisq.quantile(p);
        
        ArrayList<BigramCollocation> bigrams = new ArrayList<>();

        Iterator<Bigram> iterator = corpus.getBigrams();
        while (iterator.hasNext()) {
            Bigram bigram = iterator.next();
            int c12 = corpus.getBigramFrequency(bigram);

            if (c12 > minFreq) {
                int c1 = corpus.getTermFrequency(bigram.w1);
                int c2 = corpus.getTermFrequency(bigram.w2);

                double score = likelihoodRatio(c1, c2, c12, corpus.size());
                if (score > cutoff) {
                    bigrams.add(new BigramCollocation(bigram.w1, bigram.w2, c12, score));
                }
            }
        }

        int n = bigrams.size();
        BigramCollocation[] collocations = new BigramCollocation[n];
        for (int i = 0; i < n; i++) {
            collocations[i] = bigrams.get(i);
        }

        Arrays.sort(collocations);
        // Reverse to descending order
        for (int i = 0; i < n/2; i++) {
            BigramCollocation b = collocations[i];
            collocations[i] = collocations[n-i-1];
            collocations[n-i-1] = b;
        }

        return collocations;
    }
162333
public Color getColorAt(float p) {
		if (p <= 0) {
			return ((Step) steps.get(0)).col;
		}
		if (p > 1) {
			return ((Step) steps.get(steps.size()-1)).col;
		}
		
		for (int i=1;i<steps.size();i++) {
			Step prev = ((Step) steps.get(i-1));
			Step current = ((Step) steps.get(i));
			
			if (p <= current.location) {
				float dis = current.location - prev.location;
				p -= prev.location;
				float v = p / dis;
				
				Color c = new Color(1,1,1,1);
				c.a = (prev.col.a * (1 - v)) + (current.col.a * (v));
				c.r = (prev.col.r * (1 - v)) + (current.col.r * (v));
				c.g = (prev.col.g * (1 - v)) + (current.col.g * (v));
				c.b = (prev.col.b * (1 - v)) + (current.col.b * (v));
				
				return c;
			}
		}

		// shouldn't ever happen
		return Color.black;
	}
399249
public function reduce( $p, $r )
    {
        $p = (double)$p;
        $r = (double)$r;
        $key = 0;
        while ( $key < $this->lastKey(-3) ) {
            $out = $key + 2;
            while (
                $out < $this->lastKey()
                && $this->_shortest($out, $key) < $p
                && $this->_distance($out, $key) < $r
            ) {
                $out++;
            }
            for ( $i = $key+1, $l = $out - 1; $i < $l; $i++ ) {
                unset($this->points[$i]);
            }
            $this->reindex();
            $key++;
        }
        return $this->points;
    }
1085794
public function inverse($p)
    {
        $p->x -= $this->x0;
        $p->y -= $this->y0;

        $lat = $p->y / $this->a;

        if (abs($lat) > Common::HALF_PI) {
            Proj4php::reportError("equi:Inv:DataError");
        }

        $lon = Common::adjust_lon( $this->long0 + $p->x / ($this->a * cos( $this->lat0 )) );

        $p->x = $lon;
        $p->y = $lat;
    }
215307
def get_p_vals(df, positive_category, term_significance):
	'''
	
	'''
	df_pos = df[[positive_category]]
	df_pos.columns = ['pos']
	df_neg = pd.DataFrame(df[[c for c in df.columns if
	                          c != positive_category
	                          and c.endswith(' freq')]].sum(axis=1))
	df_neg.columns = ['neg']
	X = df_pos.join(df_neg)[['pos','neg']].values
	return term_significance.get_p_vals(X)
673953
@Override
    public double quantile(double p) {
        if (p < 0.0 || p > 1.0) {
            throw new IllegalArgumentException("Invalid p: " + p);
        }

        if (sigma == 0.0) {
            if (p < 1.0) {
                return mu - 1E-10;
            } else {
                return mu;
            }
        }
        return -1.41421356237309505 * sigma * Erf.inverfc(2.0 * p) + mu;
    }
442696
final function p() {
		$tag = df_cts($this, '_'); /** @var string $tag */
		if ($d = $this->destructive()) { /** @var bool $d */
			df_cache_clean_tag($tag);
		}
		return $d ? $this->_p() : df_cache_get_simple($this->_ckey, function() {return $this->_p();}, [$tag]);
	}
1247304
public static double getPvalue(TransposeDataCollection transposeDataCollection) {
        if(transposeDataCollection.size()!=2) {
            throw new IllegalArgumentException("The collection must contain observations from 2 groups.");
        }
        
        Object[] keys = transposeDataCollection.keySet().toArray();
        
        //IMPORTANT!!! place as n1 the smallest sample!!!!! This is required by the Test.
        
        
        int smallIndex = 0;
        int largeIndex = 1;
        int n1 = transposeDataCollection.get(keys[smallIndex]).size();
        int n2 = transposeDataCollection.get(keys[largeIndex]).size();
        if(n1>n2) {
            int tmp = n1;
            n1 = n2;
            n2 = tmp;
            smallIndex=1;
            //largeIndex=0;
        }
        
        //flatten the original internalData table
        AssociativeArray associativeArray = new AssociativeArray();
        
        for(Map.Entry<Object, FlatDataCollection> entry : transposeDataCollection.entrySet()) {
            Object i = entry.getKey();
            FlatDataCollection row = entry.getValue();
            
            Integer j=0;
            for (Object value : row) {
                Map.Entry<Object, Object> i_j = new AbstractMap.SimpleEntry<>(i, (Object)j);
                associativeArray.put(i_j, value);
                ++j;
            }
        }
        
        //converts the values of the flatDataCollection with their Ranks
        Ranks.getRanksFromValues(associativeArray);

        //sum up the scores of the smallest sample
        double MWscore=0.0;
        
        for(Map.Entry<Object,Object> entry : associativeArray.entrySet()) {
            @SuppressWarnings("unchecked")
            Map.Entry<Object, Object> i_j = (Map.Entry<Object, Object>)entry.getKey();
            Object i = i_j.getKey(); //get i and j values
            
            if(i.equals(keys[smallIndex])) { //if it belongs to the FIRST group (small group)
                Double rank = TypeInference.toDouble(entry.getValue());
                MWscore+=rank; //add the score
            }
        }
        //associativeArray=null;

        double pvalue= scoreToPvalue(MWscore, n1, n2);

        return pvalue;
    }