Honeycomb
0.1
Component-Model Framework
|
Generate a random variate from a noncentral chi-square distribution. More...
#include <ChiSqr.h>
Public Types | |
typedef Matrix< matrix::dynamic, matrix::dynamic, Real > | MatrixN |
typedef Vec< matrix::dynamic, Real > | VecN |
typedef Vec< 2, Real > | Vec2 |
Public Member Functions | |
ChiSqr_ (optional< RandomGen & > gen, Real nu, Real lambda=0) | |
ChiSqr_ (Real nu, Real lambda=0) | |
virtual Real | next () const |
Get next randomly distributed variate. Requires a random generator (see ctor or setGen()) More... | |
virtual Real | pdf (Real x) const |
Probability Density Function. More... | |
virtual Real | cdf (Real x) const |
Cumulative Distribution Function. More... | |
virtual Real | cdfInv (Real P) const |
Inverse of the CDF. More... | |
virtual Real | mean () const |
Calc mean. More... | |
virtual Real | variance () const |
Calc variance. More... | |
Vec2 | stdDevCi (Real stdDev, Real alpha) const |
Calculate the 100*(1-alpha)% confidence interval of the standard deviation. More... | |
Public Member Functions inherited from honey::RandomDist< Real > | |
RandomDist (optional< RandomGen & > gen=optnull) | |
Construct with a random generator to use for next() More... | |
virtual | ~RandomDist () |
virtual Real | cdfComp (Real x) const |
Complement of the CDF. More... | |
Real | stdDev () const |
Calc standard deviation. More... | |
void | setGen (RandomGen &gen) |
Set random generator to use for next() More... | |
RandomGen & | getGen () const |
Get random generator. More... | |
Static Public Member Functions | |
static Real | test (const VecN &observed, const VecN &expected) |
Calculate the p-value for a list of observed and expected frequencies. More... | |
static Real | test (const MatrixN &mat) |
Calculate the p-value for a 'contingency table', a matrix of frequencies for different categories. More... | |
Public Attributes | |
Real | nu |
Real | lambda |
Friends | |
template<class > | |
class | ChiSqr_ |
Additional Inherited Members | |
Protected Types inherited from honey::RandomDist< Real > | |
typedef Numeral< Real >::Real_ | Real_ |
typedef Real_::DoubleType | Double_ |
typedef Double_::Real | Double |
typedef Alge_< Real > | Alge |
typedef Alge_< Double > | Alge_d |
typedef Uniform_< Double > | Uniform |
Protected Member Functions inherited from honey::RandomDist< Real > | |
Real | cdfInvFind (Real P, Real min, Real max, bool discrete=false) const |
Generic binary search algorithm to find Cdf. More... | |
Generate a random variate from a noncentral chi-square distribution.
The chi-square distribution can be used to test how likely it is that an observed distribution is due to chance. It can test the goodness of fit of observations to a model by testing a 'null hypothesis' that the observations are tied to some expected values. It can also be used to test if categorical tallies (eg. male or female for each race) within a table are related or independent.
Use Pearson's chi-squared test to determine if a 6-sided die has been tampered with.
Take samples by rolling the die and observing the frequency of the 6 independent categorical variables (ie. number of times 1,2...6 appears face up)
Here the null hypothesis is that all the sides will appear face up the same number of times.
This result, X^2, asymptotically approaches a chi-square distribution.
Let's say that the result is 12.
Next, use the Cumulative Distribution Function (CDF). The CDF is a curve that increases from 0 to 1, it tells us the probability that a sample will be <= X^2.
The number of degrees of freedom are the number of categorical variables (6) minus one.
p will be about 0.03, or 3%. This tells us that the probability of the die samples being tied to their expected values (ie. pure chance) is 3%. Less than 5% strongly suggests that the categorical variables are correlated, so the die sides are not independent, they have been tampered with.
Probability density function when , central chi-square distribution, same as :
where is the gamma function.
Probability density function when , poisson weighted mix of central chi-square distributions:
nu | Number of degrees of freedom. Range > 0 |
lambda | Non-centrality parameter. Range >= 0 |
x | Random variate. Range [0,inf] |
typedef Matrix<matrix::dynamic, matrix::dynamic, Real> honey::ChiSqr_< Real >::MatrixN |
typedef Vec<2,Real> honey::ChiSqr_< Real >::Vec2 |
typedef Vec<matrix::dynamic, Real> honey::ChiSqr_< Real >::VecN |
|
inline |
|
inline |
|
virtual |
Cumulative Distribution Function.
The integral of the PDF from -inf to x.
x | value, range depends on distribution. |
P | a probability in range [0,1] that a random variate will be <= x. |
Reimplemented from honey::RandomDist< Real >.
|
virtual |
Inverse of the CDF.
P | cumulative probability |
x | A value that has probability P of being >= a random variate X. Also, x satisfies: cdf(x) = P. |
Reimplemented from honey::RandomDist< Real >.
|
inlinevirtual |
Calc mean.
Reimplemented from honey::RandomDist< Real >.
|
virtual |
Get next randomly distributed variate. Requires a random generator (see ctor or setGen())
Reimplemented from honey::RandomDist< Real >.
|
virtual |
Probability Density Function.
The PDF integrates to 1 over the entire range of possible values of x.
x | value, range depends on distribution. |
p | a relative likelihood in range [0,inf] that a random variate X will equal x. |
Reimplemented from honey::RandomDist< Real >.
|
inline |
Calculate the 100*(1-alpha)% confidence interval of the standard deviation.
|
static |
Calculate the p-value for a list of observed and expected frequencies.
|
static |
Calculate the p-value for a 'contingency table', a matrix of frequencies for different categories.
A p-value below 5% is significant, meaning that deviations between the categories are probably not due to random chance. All frequencies in the matrix should be at least 5 for reliable results. The degrees of freedom in the matrix is assumed to be (rows-1)*(cols-1), that is, it is not possible to populate any part of the matrix knowing other parts.
|
inlinevirtual |
Calc variance.
Reimplemented from honey::RandomDist< Real >.
Real honey::ChiSqr_< Real >::lambda |
Real honey::ChiSqr_< Real >::nu |