Statistical functions

I am trying to create a few statistical analyses on my app. But Xojo lacks a lot of mathematical shortcuts. For example, I am struggling to create a Chi-Square test calculation and the p-value. I don’t want to reinvent the wheel. Does anyone know if it has already been done?

I found a FORTRAN listing here (https://jblevins.org/mirror/amiller/as275.f90. Should be relatively simple to convert to basic.