Exemple #1
0
func main() {
	nu := 12.0
	chis := []float64{6.3038, 8.43842, 11.3403, 14.8454, 18.5493}

	fmt.Println("Chi squared distribution for nu = %f:", nu)
	fmt.Printf("10th percentile: %g\n", num.IncGamma(nu/2, chis[0]/2))
	fmt.Printf("25th percentile: %g\n", num.IncGamma(nu/2, chis[1]/2))
	fmt.Printf("50th percentile: %g\n", num.IncGamma(nu/2, chis[2]/2))
	fmt.Printf("75th percentile: %g\n", num.IncGamma(nu/2, chis[3]/2))
	fmt.Printf("90th percentile: %g\n", num.IncGamma(nu/2, chis[4]/2))
}
Exemple #2
0
// ChiSqrDist computes cumulative probability that Chi^2 could
// take on a value less than chiSqr with the given number of degrees
// of freedom, nu.
//
// ChiSqrDist panics if given non-positive Chi^2 or nu values.
func ChiSqrDist(chiSqr float64, nu int) float64 {
	if nu <= 0 {
		panic(fmt.Sprintf("stats.ChiSqrDist given %d degrees of freedom.", nu))
	} else if chiSqr <= 0 {
		panic(fmt.Sprintf("stats.ChiSqrDist given %g degrees of freedom.", chiSqr))
	}

	return num.IncGamma(float64(nu)/2, chiSqr/2)
}