/*
 *  Draco Econometrics
 *  Copyright (C) 2006-2007 Approximatrix, LLC
 *  http://www.approximatrix.com
 *  
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package com.approximatrix.draco.analysis.statistics;

import com.approximatrix.draco.math.FunctionSupport;

public class FDistribution {

	public static double FValue(double significance, int degrees_freedom_numerator, int degrees_freedom_denominator) {
		//return getCDF(significance,degrees_freedom_numerator,degrees_freedom_denominator);
		return Double.NaN;
	}
	
	public static double getPDF(double x, int df_numerator, int df_denominator) {
		double df1 = (double)df_numerator;
		double df2 = (double)df_denominator;
		
		double return_val = FunctionSupport.Gamma(df1+df2/2.0);
		return_val = return_val/(FunctionSupport.Gamma(df1/2.0) + FunctionSupport.Gamma(df2/2.0));
		
		return_val = return_val*Math.pow(df1/df2,df1/2.0)*Math.pow(x,df1/2.0-1.0);
		
		return_val = return_val*Math.pow(1.0+df1/df2*x,(df1+df2)/(-2.0));
		
		return return_val;
	}
	
	public static double getCDF(double xn, int df_numerator, double xd, int df_denominator) {
		double denom = ChiSquared.getCDF(df_denominator, xd);
		if(denom == 0.0)
			return Double.POSITIVE_INFINITY;
		double num = ChiSquared.getCDF(df_numerator, xn);
		return num/denom;
	}
	
}
