SDDSlib
Loading...
Searching...
No Matches
sigLevel.c File Reference

Routines for Student's t distribution, the F distribution, the linear-correlation coefficient distribution, and Poisson distribution. More...

#include "mdb.h"

Go to the source code of this file.

Functions

double normSigLevel (double z0, long tails)
 Computes the probability that a standard normal variable exceeds a given value.
 
double ChiSqrSigLevel (double ChiSquared0, long nu)
 Computes the probability that a chi-squared variable exceeds a given value.
 
double tTailSigLevel (double t0, long nu, long tails)
 Computes the probability that the absolute value of a t-distributed variable exceeds a given value.
 
double FSigLevel (double var1, double var2, long nu1, long nu2)
 Computes the probability that an F-distributed variable exceeds a given value.
 
double rSigLevel (double r0, long nu)
 Computes the probability that the linear correlation coefficient exceeds a given value.
 
double poissonSigLevel (long n, double n0)
 Computes the probability that a Poisson-distributed random variable exceeds or equals a given value.
 

Detailed Description

Routines for Student's t distribution, the F distribution, the linear-correlation coefficient distribution, and Poisson distribution.

License
This file is distributed under the terms of the Software License Agreement found in the file LICENSE included with this distribution.
Author
M. Borland, C. Saunders, R. Soliday

Definition in file sigLevel.c.

Function Documentation

◆ ChiSqrSigLevel()

double ChiSqrSigLevel ( double ChiSquared0,
long nu )

Computes the probability that a chi-squared variable exceeds a given value.

This function calculates the probability that a chi-squared random variable with nu degrees of freedom exceeds ChiSquared0.

Parameters
ChiSquared0The chi-squared value for which the probability is computed.
nuThe degrees of freedom of the chi-squared distribution.
Returns
The probability that the chi-squared variable exceeds ChiSquared0 for nu degrees of freedom. Returns -1 if ChiSquared0 is negative.

Definition at line 64 of file sigLevel.c.

65{
66 if (ChiSquared0 < 0)
67 return -1;
68 return gammaQ(nu / 2.0, ChiSquared0 / 2);
69}
double gammaQ(double a, double x)
Compute the regularized upper incomplete gamma function Q(a,x).
Definition gammai.c:64

◆ FSigLevel()

double FSigLevel ( double var1,
double var2,
long nu1,
long nu2 )

Computes the probability that an F-distributed variable exceeds a given value.

This function calculates the probability that an F-distributed random variable with nu1 and nu2 degrees of freedom exceeds F0, where F0 is defined as Max(var1, var2) / Min(var1, var2).

Parameters
var1The first variance.
var2The second variance.
nu1The degrees of freedom associated with var1.
nu2The degrees of freedom associated with var2.
Returns
The probability that F exceeds F0 for nu1 and nu2 degrees of freedom.

Definition at line 101 of file sigLevel.c.

102{
103 if (var1 < var2) {
104 SWAP_DOUBLE(var1, var2);
105 SWAP_LONG(nu1, nu2);
106 }
107 return betaInc(nu2 / 2.0, nu1 / 2.0, nu2 / (nu2 + nu1 * var1 / var2));
108}
double betaInc(double a, double b, double x)
Compute the incomplete beta function.
Definition betai.c:67

◆ normSigLevel()

double normSigLevel ( double z0,
long tails )

Computes the probability that a standard normal variable exceeds a given value.

This function calculates the probability that a standard normal random variable Z satisfies Z > z0.

Parameters
z0The value for which the probability is computed.
tailsSpecifies whether to compute a one-tailed (1) or two-tailed (2) probability.
Returns
The probability that Z exceeds z0. Returns -1 if the number of tails is invalid.

Definition at line 40 of file sigLevel.c.

41{
42 if (z0 < 0)
43 z0 = -z0;
44 if (tails != 1 && tails != 2)
45 return -1;
46#if defined(vxWorks)
47 fprintf(stderr, "erfc function is not implemented on vxWorks\n");
48 exit(1);
49#else
50 return erfc(z0 / SQRT2) / (tails == 1 ? 2 : 1);
51#endif
52}

◆ poissonSigLevel()

double poissonSigLevel ( long n,
double n0 )

Computes the probability that a Poisson-distributed random variable exceeds or equals a given value.

This function calculates the probability that the number of events n is greater than or equal to a specified value n0, given a Poisson distribution with an expected number of events n0.

Parameters
nThe number of events observed.
n0The expected number of events.
Returns
The probability that n or more events are observed given a Poisson distribution with n0 expected events.

Definition at line 141 of file sigLevel.c.

142{
143 double sum, term, result = 0;
144 long i;
145 if (n == 0)
146 return 1;
147 if (n < 0 || n0 <= 0) {
148 return n0 < n ? 0 : 1;
149 }
150 if (n0 > 200) {
151 result = normSigLevel((n - n0) / sqrt(n0), 1);
152 if (n < n0)
153 return 1 - result;
154 return result;
155 }
156 if (!exp(-n0))
157 return n0 < n ? 0 : 1;
158 sum = 1;
159 term = 1;
160 i = 0;
161 while (++i < n) {
162 term *= n0 / i;
163 sum += term;
164 }
165 result = 1 - sum * exp(-n0);
166 if (isnan(result)) {
167 return n0 < n ? 0 : 1;
168 }
169 if (result < 0)
170 return 0;
171 return result;
172}
double normSigLevel(double z0, long tails)
Computes the probability that a standard normal variable exceeds a given value.
Definition sigLevel.c:40

◆ rSigLevel()

double rSigLevel ( double r0,
long nu )

Computes the probability that the linear correlation coefficient exceeds a given value.

This function calculates the probability that the linear correlation coefficient r exceeds |r0| for nu degrees of freedom.

Parameters
r0The correlation coefficient value.
nuThe degrees of freedom.
Returns
The probability that the linear correlation coefficient exceeds |r0| for nu degrees of freedom. Returns -1 if nu is less than 2 or if r0 is not in the valid range.

Definition at line 120 of file sigLevel.c.

121{
122 if (r0 < 0)
123 r0 = -r0;
124 if (nu < 2)
125 return -1;
126 if (r0 >= 1)
127 return 0;
128 return tTailSigLevel(r0 * sqrt(nu / (1 - r0 * r0)), nu, 2);
129}
double tTailSigLevel(double t0, long nu, long tails)
Computes the probability that the absolute value of a t-distributed variable exceeds a given value.
Definition sigLevel.c:82

◆ tTailSigLevel()

double tTailSigLevel ( double t0,
long nu,
long tails )

Computes the probability that the absolute value of a t-distributed variable exceeds a given value.

This function calculates the probability that |t| > t0 for a t-distribution with nu degrees of freedom.

Parameters
t0The t-value for which the probability is computed.
nuThe degrees of freedom of the t-distribution.
tailsSpecifies whether to compute a one-tailed (1) or two-tailed (2) probability.
Returns
The probability that |t| exceeds t0 for nu degrees of freedom. Returns -1 if the number of tails is invalid.

Definition at line 82 of file sigLevel.c.

83{
84 if (tails != 1 && tails != 2)
85 return -1;
86 return betaInc(nu / 2.0, 0.5, nu / (nu + t0 * t0)) / (tails == 1 ? 2 : 1);
87}