Skip to content
DeepForgeby svx
All problems
EasyProbabilitypr-063

Chi-Square PDF Value

Problem

Chi-square probability density with k degrees of freedom at x:

f(x) = x^(k/2 - 1) * e^(-x/2) / (2^(k/2) * Gamma(k/2)).

Return 0.0 for k <= 0 or x <= 0.

Hint

A chi-square with k degrees of freedom is Gamma(k/2, 1/2).

Test cases

case 1
in: [1,1]
expected: 0.24197072451914334
case 2
in: [2,1]
expected: 0.3032653298563167
case 3
in: [4,2]
expected: 0.18393972058572117
case 4
in: [1,0]
expected: 0
Starter codePython
import math


def chi_square_pdf_value(k, x):
    # Your code here
    pass

4 test cases · run your code against them in the editor