This was really helpful, I appreciate this a whole lot! I even learned new tricks Mathematica can do that I wasn't aware of (such as // N). I also didn't know that pValue was calculated from a ChiSquareDistribution.
The only part I don't understand fully is what exactly is going on in the first portion. I would like to construct a similar system of equations for the Gaussian and possibly a Binomial portion, and I believe this is the part I would change (in addition to the bin number at the very end), but I don't quite get how this determines equally sized bins. Do you run the equation multiple times, changing the value for nBins, until you get an array of numbers in which are all integers? And finally, why do you append a -1 and infinity at the beginning and the end of this array?
Thank you so much, I've learned more from this post than anything I've tried in the past 48 hours trying to get this to work!