3

I'm kind of stats noob, so appreciate any help.

I'm writing a program in iOS (Swift) to work out ANOVAs and I want to know if values from the F-Distribution tables could be calculated manually, instead of just looking them up on a table.

Instead of having to reference the tables every time, it would be nice just to be able to calculate them on the fly.

monotreme
  • 131
  • 5
  • 1
    This sounds like a stackoverflow question. I think you want some kind of scientific computing library that gives you a function for the fcdf or the [incomplete beta function](http://mathworld.wolfram.com/IncompleteBetaFunction.html) which would allow you to calculate the fcdf. – Matthew Gunn Oct 21 '16 at 01:57
  • Not really. What I don't know is the basic formula for getting these values, the swift code I can figure out on my own. – monotreme Oct 21 '16 at 01:59
  • Ok, I'm confused what you're asking now. Are you asking how to write a function which gives you a value from cumulative distribution function (CDF) for the [F-distribution](https://en.wikipedia.org/wiki/F-distribution) for a given $x$ and degrees of freedom $v_1$ and $v_2$? Or do you want something else? – Matthew Gunn Oct 21 '16 at 02:04
  • Sorry:( Basically I want to know how I can manually calculate the F-values that are on an F-Distribution table for α = 0.05 or α = 0.01. I've already got my nDF(r1) and dDF(r2) values, so what is the formula or function that comes up with the F-Value? As I'm learning this, everything I find online just tells me to look it up on the table, but I want to just calculate it. – monotreme Oct 21 '16 at 02:11
  • 2
    The CDF for the [f-distribution can be written in terms of the incomplete beta function](https://en.wikipedia.org/wiki/F-distribution). If you want to compute an F-value, you need the inverse F-cdf which would use the inverse incomplete beta function. [This link here](http://stackoverflow.com/questions/8956503/fast-implementation-of-inverse-incomplete-beta-function-in-c) has some discussion. [This link here](http://www.aip.de/groups/soe/local/numres/bookcpdf/c6-4.pdf) has code to compute the f-cdf and the incomplete beta function, but you want the other way (worth reading though)... – Matthew Gunn Oct 21 '16 at 02:29
  • That looks like what I need! A bit above my head, so this is my homework for the day. Thanks! – monotreme Oct 21 '16 at 02:37
  • 1
    IMHO, this is a situation where you should use some kind of scientific computing library that has taken the time to get the code right. Eg. it appears Boost library can calculate it: http://www.boost.org/doc/libs/1_62_0/libs/math/doc/html/math_toolkit/stat_tut/weg/f_eg.html – Matthew Gunn Oct 21 '16 at 02:53
  • Perfect. I should be able to integrate these libraries into my project instead of rewriting the code myself! – monotreme Oct 21 '16 at 03:10
  • If you are calculating them on a computer, I would not call that *manual calculation*. To me that involves pen and paper, and at a push, maybe log-tables and some series or continued fraction to work on. – Glen_b Oct 21 '16 at 05:28
  • I know, but in order to write the code, I need to understand how to do it with a pencil and paper before I write the code. – monotreme Oct 21 '16 at 05:29
  • Methods suitable for actual manual calculation are not the same as methods suitable for computer calculation. In any case you shouldn't write the code unless its unavoidable. Most standard math libraries have the incomplete beta function built in, and you can readily compute it from that. It would be silly to build it yourself when there's decades of expertise and debugging gone into standard libraries. They're efficient, robust (e.g. they typically already deal with the tricky edge cases), and are substantially more likely to be *correct*. – Glen_b Oct 21 '16 at 05:34
  • I know. There's nothing for swift right now though. There's methods for calculating CDF and beta in Objective C, but I simply don't know how to use these to find the values I need, hence my desire to learn how to do it by hand. Thanks - @Matthew's answer was super helpful. – monotreme Oct 21 '16 at 05:38
  • SOme of the discussion here might help: http://stats.stackexchange.com/questions/137612/calculating-the-critical-value-for-f-test/137633#137633 – Glen_b Oct 21 '16 at 05:45

1 Answers1

0

As per @Matthew in comments:

The CDF for the f-distribution can be written in terms of the incomplete beta function. If you want to compute an F-value, you need the inverse F-cdf which would use the inverse incomplete beta function. This link here has some discussion. This link here has code to compute the f-cdf and the incomplete beta function, but you want the other way (worth reading though)...

monotreme
  • 131
  • 5