I see that function for Chi-distribution are given on this page: https://wiki.freepascal.org/Generating_Random_Numbers The code (comments added) is as follows (in Pascal - easily understandable):
function randomChisq(df: integer): real;
{comment: integer df is sent to this function and a real values is returned}
begin
if df < 1 then
result := NaN {comment: invalid df}
else
result := randomGamma(0, 2, 0.5 * df); {comment: main return value}
end;
However, how can I use this function to perform a chi-square test and calculate P value for following given data:
Affected notAffected
groupA 55 85
groupB 255 365
Thanks for your help.