4

I am trying to find a builtin CDF for chi square distribution.

Basically, I wish to have a CDF function like pchisq in R, where

chisquare(x,p,q) gives you the probability. x is the distribution of the function, p is the dof and q is the noncentrality parameter. I tried looking for some packages, but some library does not take in the q parameter.

Jason
  • 36,170
  • 5
  • 26
  • 60
hao
  • 635
  • 2
  • 8
  • 20
  • C++ doesn't have a standard stats package, but doing more Google searches should turn up many of them. I haven't looked but the big math & stats packages (SAS, SPSS, Matlab, ...) might also have C++ automation interfaces. – Dave S Mar 05 '19 at 19:43
  • If this is Windows, could you use .NET C++/C# and R.Net? - https://stackoverflow.com/questions/37140322/creating-an-instance-of-the-rengine-using-r-net-version-1-5-5 – Dave S Mar 05 '19 at 19:47
  • i am on mac book.... – hao Mar 05 '19 at 19:59

1 Answers1

1

To answer your question, unfortunately, no, this doesn’t exist in C++ as of C++20.

I needed to compute this CDF earlier today for a project and ended up just coding it up as a Riemann sum. For the special case where for k = 1, where the Riemann integral is hard to evaluate accurately because of the blowup of the PDF at x = 0, is used the fact that the CDF is given by erf(sqrt(x)), and those functions do exist in C++ in the <cmath> header.

templatetypedef
  • 362,284
  • 104
  • 897
  • 1,065