yat  0.20.3pre
Public Member Functions | List of all members
theplu::yat::statistics::Fisher Class Reference

Fisher's exact test. More...

#include <yat/statistics/Fisher.h>

Public Member Functions

 Fisher (bool yates=false)
 
virtual ~Fisher (void)
 
double Chi2 (void) const
 
void expected (double &a, double &b, double &c, double &d) const
 
unsigned int & minimum_size (void)
 
const unsigned int & minimum_size (void) const
 
double p_left (void) const
 
double p_right (void) const
 
double p_value (void) const
 
double p_value_one_sided () const
 
double oddsratio (const unsigned int a, const unsigned int b, const unsigned int c, const unsigned int d)
 
double oddsratio (void) const
 

Detailed Description

Fisher's exact test.

Fisher's Exact test is a procedure that you can use for data in a two by two contingency table:

\[ \begin{tabular}{|c|c|} \hline a&b \tabularnewline \hline c&d \tabularnewline \hline \end{tabular} \]

Fisher's Exact Test is based on exact probabilities from a specific distribution (the hypergeometric distribution). There's really no lower bound on the amount of data that is needed for Fisher's Exact Test. You do have to have at least one data value in each row and one data value in each column. If an entire row or column is zero, then you don't really have a 2 by 2 table. But you can use Fisher's Exact Test when one of the cells in your table has a zero in it. Fisher's Exact Test is also very useful for highly imbalanced tables. If one or two of the cells in a two by two table have numbers in the thousands and one or two of the other cells has numbers less than 5, you can still use Fisher's Exact Test. For very large tables (where all four entries in the two by two table are large), your computer may take too much time to compute Fisher's Exact Test. In these situations, though, you might as well use the Chi-square test because a large sample approximation (that the Chi-square test relies on) is very reasonable. If all elements are larger than 10 a Chi-square test is reasonable to use.

Note
The statistica assumes that each column and row sum, respectively, are fixed. Just because you have a 2x2 table, this assumtion does not necessarily match you experimental setup. See e.g. Barnard's test for alternative.

Constructor & Destructor Documentation

◆ Fisher()

theplu::yat::statistics::Fisher::Fisher ( bool  yates = false)

Default Constructor.

Parameters
yatesif true Yates's correction is used for chi-squared calculation
Since
Constructor with argument was introduced in yat 0.13

◆ ~Fisher()

virtual theplu::yat::statistics::Fisher::~Fisher ( void  )
virtual

Destructor

Member Function Documentation

◆ Chi2()

double theplu::yat::statistics::Fisher::Chi2 ( void  ) const

The Chi2 score is calculated as $ \sum \frac{(O_i-E_i)^2}{E_i}$ where E is expected value and O is observed value.

If indicated in constructor, Yates's correction is used, i.e., Chi2 is calculated as $ \frac{(|O_i-E_i|-0.5)^2}{E_i} $

See also
expected(double&, double&, double&, double&)
Returns
Chi2 score

◆ expected()

void theplu::yat::statistics::Fisher::expected ( double &  a,
double &  b,
double &  c,
double &  d 
) const

Calculates the expected values under the null hypothesis. $ a' = \frac{(a+c)(a+b)}{a+b+c+d} $, $ b' = \frac{(a+b)(b+d)}{a+b+c+d} $, $ c' = \frac{(a+c)(c+d)}{a+b+c+d} $, $ d' = \frac{(b+d)(c+d)}{a+b+c+d} $,

◆ minimum_size() [1/2]

unsigned int& theplu::yat::statistics::Fisher::minimum_size ( void  )

If all elements in table is at least minimum_size(), a Chi2 approximation is used for p-value calculation.

Returns
reference to minimum_size

◆ minimum_size() [2/2]

const unsigned int& theplu::yat::statistics::Fisher::minimum_size ( void  ) const

If all elements in table is at least minimum_size(), a Chi2 approximation is used for p-value calculation.

Returns
const reference to minimum_size

◆ oddsratio() [1/2]

double theplu::yat::statistics::Fisher::oddsratio ( const unsigned int  a,
const unsigned int  b,
const unsigned int  c,
const unsigned int  d 
)

Function calculating odds ratio from 2x2 table

\[ \begin{tabular}{|c|c|} \hline a&b \tabularnewline \hline c&d \tabularnewline \hline \end{tabular} \]

as $ \frac{ad}{bc} $

Object will remember the values of a, b, c, and d.

Returns
odds ratio.
Exceptions
Iftable is invalid a runtime_error is thrown. A table is invalid if a row or column sum is zero.

◆ oddsratio() [2/2]

double theplu::yat::statistics::Fisher::oddsratio ( void  ) const
Returns
oddsratio loaded via oddsratio(4)
Since
New in yat 0.8

◆ p_left()

double theplu::yat::statistics::Fisher::p_left ( void  ) const

Calculates probability to get oddsratio (or smaller).

If all elements in table is at least minimum_size(), a Chi2 approximation is used.

Since
New in yat 0.11

◆ p_right()

double theplu::yat::statistics::Fisher::p_right ( void  ) const

Calculates probability to get oddsratio (or greater).

If all elements in table is at least minimum_size(), a Chi2 approximation is used.

Since
New in yat 0.11

◆ p_value()

double theplu::yat::statistics::Fisher::p_value ( void  ) const

If all elements in table is at least minimum_size(), a Chi2 approximation is used.

Otherwise a two-sided p-value is calculated using the hypergeometric distribution $ \sum_k P(k) $ where summation runs over k such that $ P(k) \le P(a) $.

Returns
two-sided p-value

◆ p_value_one_sided()

double theplu::yat::statistics::Fisher::p_value_one_sided ( ) const

One-sided p-value is probability to get larger (or equal) oddsratio.

If all elements in table is at least minimum_size(), a Chi2 approximation is used.

Returns
One-sided p-value
Deprecated:
Provided for backward compatibility with the 0.10 API. Use p_right() instead.

The documentation for this class was generated from the following file:

Generated on Sat Feb 18 2023 03:31:45 for yat by  doxygen 1.8.14