Top |
Libgretl uses the cephes library, developed by Stephen
Moshier, as the basic engine for much of the functionality
herein. We add some extra distributions, and wrap the cephes
functions for ease of use with libgretl (e.g. on failure
they return the libgretl missing value code, NADBL
).
double
trigamma (double x
);
the trigamma function of x
, or NADBL on failure. The code
is adapted from
https://people.sc.fsu.edu/~jburkardt/f_src/asa121/asa121.html
See BE Schneider, Algorithm AS 121: Trigamma Function.
Applied Statistics, Volume 27, Number 1, pages 97-99, 1978.
The main modification with respect to the published version is the addition of three extra terms to the asymptotic expansion for x >= B.
double beta_cdf (double a
,double b
,double x
);
Returns the probability that a B(a,b) random variable is between 0 and z, or NADBL on failure.
double binomial_cdf (double p
,int n
,int k
);
p |
probability of success on each trial. |
|
n |
number of trials. |
|
k |
maximum number of successes. |
the probability of k
or less successes on
n
trials given binomial probability p
, or
NADBL on failure.
double binomial_cdf_comp (double p
,int n
,int k
);
p |
probability of success on each trial. |
|
n |
number of trials. |
|
k |
maximum number of successes. |
the probability of k
+ 1 or more successes on
n
trials given binomial probability p
, or
NADBL on failure.
double
normal_pvalue_2 (double x
);
Calculates the two-sided p-value for x
in relation to the
standard normal distribution.
double
normal_pvalue_1 (double x
);
Calculates the one-sided p-value for x
in relation to the
standard normal distribution (that is, the probability that a
random variable distributed as N(0, 1) is greater than x
).
double student_pvalue_2 (double df
,double x
);
the probability that t(df
) is greater than x
(two-sided, using the absolute value of x
), or
NADBL on failure.
double chisq_cdf (double df
,double x
);
the integral from 0 to x
of the chi-square
distribution with df
degrees of freedom, or NADBL
on failure.
double chisq_cdf_comp (double df
,double x
);
the integral from x
to infinity of the chi-square
distribution with df
degrees of freedom, or NADBL
on failure.
double nc_chisq_cdf (double df
,double delta
,double x
);
Calculates the value at x
of the CDF of the noncentral chi^2
distribution with df
dof and noncentrality parameter equal to
delta
.
This is a version of cumchn()
from dcdflib, de-spaghettized by
Jack Lucchetti (2015-06-21). The original algorithm uses formula
26.4.25 from Abramowitz and Stegun, Handbook of Mathematical
Functions, US NBS (1966).
double snedecor_cdf (double dfn
,double dfd
,double x
);
dfn |
numerator degrees of freedom. |
|
dfd |
denominator degrees of freedom. |
|
x |
the cutoff point in the distribution. |
the integral of the F distribution with dfn
and
dfd
degrees of freedom, from 0 to x
, or NADBL on failure.
double snedecor_cdf_comp (double dfn
,double dfd
,double x
);
dfn |
numerator degrees of freedom. |
|
dfd |
denominator degrees of freedom. |
|
x |
the cutoff point in the distribution. |
the integral of the F distribution with dfn
and
dfd
degrees of freedom, from x
to infinity, or NADBL
on failure.
double snedecor_critval (double dfn
,double dfd
,double a
);
dfn |
numerator degrees of freedom. |
|
dfd |
denominator degrees of freedom. |
|
a |
right-tail probability. |
the F argument x such that the integral
from x to infinity of the F density is equal
to the given probability a
, or NADBL on failure.
double nc_snedecor_cdf (double dfn
,double dfd
,double delta
,double x
);
Calculates the value at x
of the CDF of the noncentral F
distribution with dfn
, dfd
dof and noncentrality parameter equal
to delta
.
This is a version of cumfnc()
from dcdflib, de-spaghettized by
Jack Lucchetti (2015-06-21). The original algorithm uses formula
26.6.18 from Abramowitz and Stegun, Handbook of Mathematical
Functions, US NBS (1966).
double
normal_cdf_inverse (double x
);
the argument, y, for which the area under the Gaussian probability density function (integrated from minus infinity to y) is equal to x, or NADBL on failure.
double student_cdf (double df
,double x
);
the integral from minus infinity to x
of
the Student's t distribution with df
degrees of freedom, or
NADBL on failure.
double student_cdf_inverse (double df
,double a
);
the argument x such that the integral from
minus infinity to x
of the t(df
) density is equal to
the given probability a
, or NADBL on failure.
double nc_student_cdf (double df
,double delta
,double x
);
Calculates the value at x
of the CDF of the noncentral Student t
distribution with df
dof and noncentrality parameter equal to
delta
. The algorithm is by Benson-Krishnamoorthy (2003) CSDA 43,
with minimal changes.
double nc_student_pdf (double df
,double delta
,double x
);
Calculates the value at x
of the PDF of the noncentral Student t
distribution with df
dof and noncentrality parameter equal to
delta
. The algorithm is from Wikipedia, apparently used in R too.
double
normal_critval (double a
);
the argument z such that the integral from z to
infinity of the standard normal density is equal
to the given probability a
, or NADBL on failure.
double student_critval (double df
,double a
);
the argument x such that the integral from x to
infinity of the t(df
) density is equal to the given
probability a
, or NADBL on failure.
double gamma_cdf (double s1
,double s2
,double x
,int control
);
Calculates the value of the CDF of the gamma distribution
at x
. If control
equals 1, then it is assumed that the
parameters s1
and s2
represent the shape and scale,
respectively, otherwise it is assumed they give mean and
variance.
double gamma_cdf_comp (double s1
,double s2
,double x
,int control
);
Calculates the complement of the CDF of the gamma distribution
at x
. If control
equals 1, then it is assumed that the
parameters s1
and s2
represent the shape and scale,
respectively, otherwise it is assumed they give mean and
variance.
double gamma_cdf_inverse (double shape
,double scale
,double p
);
the argument x such that the integral from zero to x
of
the gamma density with given scale and shape parameters is equal to
the given probability p
, or NADBL on failure. Note that the
alternate parametrization (mean, variance) is not supported.
double GED_pdf (double nu
,double x
);
the density function of the Generalized Error distribution
with shape parameter nu
at x
, or NADBL on failure.
double GED_cdf (double nu
,double x
);
Calculates the value of the CDF of the Generalized Error
distribution with parameter nu
at x
. We exploit the fact that
if x ~ GED(n), then |x/k|^n is a Gamma rv.
double GED_cdf_comp (double nu
,double x
);
Calculates the complement of the CDF of the Generalized Error
distribution with parameter nu
at x
. We exploit the fact that
if x ~ GED(n), then |x/k|^n is a Gamma rv.
double GED_cdf_inverse (double nu
,double a
);
the argument x such that the integral from minus infinity
to x
of the standardized GED density with shape parameter nu
is
equal to the given probability a
, or NADBL on failure. We exploit
the well-known relationship between the standardized GED and the
Gamma variates.
double laplace_pdf (double mu
,double b
,double x
);
the density function of the Laplace distribution
with mean mu
and scale b
evaluated at x
, or NADBL on failure.
double laplace_cdf (double mu
,double b
,double x
);
the CDF of the Laplace distribution
with mean mu
and scale b
evaluated at x
, or NADBL on failure.
double laplace_cdf_comp (double mu
,double b
,double x
);
the complement of the CDF of the Laplace distribution
with mean mu
and scale b
evaluated at x
, or NADBL on failure.
double laplace_cdf_inverse (double mu
,double b
,double a
);
the argument x such that the integral from minus infinity
to x
of the Laplace density with mean mu
and scale b
is
equal to the given probability a
, or NADBL on failure.
double
tcrit95 (int df
);
the two-sided 95 percent critical value for the t
distribution with df
degrees of freedom, or NADBL on
failure.
double rhocrit (int n
,double alpha
);
Computes the two-sided 100 * alpha
critical value of the sample
correlation coefficient for a sample of size n
. This is based
on the inverse of the function which maps from the correlation
coefficient, r, to a student t statistic, namely
t = r / sqrt[(1—r^2) / (n-2)]
The inverse is r = sqrt(t^2 / (t^2 + n - 2)).
double gretl_get_pvalue (int dist
,const double *parm
,double x
);
double gretl_get_pdf (int dist
,const double *parm
,double x
);
Evaluates the PDF for the distribution specified by
dist
and parm
at x
.
int gretl_fill_pdf_array (int dist
,const double *parm
,double *x
,int n
);
On input, x
contains an array of abscissae at which the
PDF specified by dist
and parm
should be evaluated. On
output it contains the corresponding PDF values.
double gretl_get_cdf (int dist
,const double *parm
,double x
);
Evaluates the CDF for the distribution specified by
dist
and parm
applicable at x
.
double gretl_get_cdf_inverse (int dist
,const double *parm
,double a
);
dist |
distribution code. |
|
parm |
array holding from zero to two parameter values, depending on the distribution. |
|
a |
probability value. |
the argument, y, for which the area under the PDF
specified by dist
and parm
, integrated from its minimum to y,
is equal to a
, or NADBL on failure.
double gretl_get_critval (int dist
,const double *parm
,double a
);
dist |
distribution code. |
|
parm |
array holding from zero to two parameter values, depending on the distribution. |
|
a |
right-tail probability. |
the abcsissa value x for the distribution specified
by dist
and parm
, such that P(X >= x) = a
, or NADBL on
failure.
int gretl_fill_random_series (double *x
,int dist
,const double *parm
,const double *vecp1
,const double *vecp2
,const DATASET *dset
);
Fills x
with random values conforming to the distribution
given by dist
, which may require specification of either
one or two parameters. These parameters are either
given as (scalar) elements of parm
, or they may vary
by observation, in which case they are given as the
elements of vecp1
or vecp2
.
x |
series to fill (must be of length dset->n). |
|
dist |
distribution code. |
|
parm |
array holding either one or two scalar parameter values, depending on the distribution. |
|
vecp1 |
series containing values for first param,
or |
|
vecp2 |
series containing values for second param,
or |
|
dset |
dataset information. |
gretl_matrix * gretl_get_random_matrix (int dist
,const double *parm
,const double *vecp1
,const double *vecp2
,int rows
,int cols
,int *err
);
int batch_pvalue (const char *str
,DATASET *dset
,PRN *prn
);
Calculates and prints the probability that a random variable
distributed as specified in the command line str
exceeds the
value indicated in str
.
str |
the command line, which should be of one of the following forms: pvalue z x (Normal distribution); pvalue t df x (t-distribution); pvalue X df x (Chi-square); pvalue F dfn dfd x (F-distribution); or pvalue G mean variance x (Gamma distribution). pvalue B prob n x (Binomial distribution). pvalue P mean k (Poisson distribution). pvalue W shape scale x (Weibull distribution). |
|
dset |
dataset struct. |
|
prn |
gretl printing struct. |
void print_pvalue (int dist
,const double *parm
,double x
,double pv
,PRN *prn
);
Prints the p-value information in a consistent manner.
void print_critval (int dist
,const double *parm
,double a
,double c
,PRN *prn
);
Prints the critical value information in a consistent manner.
gretl_matrix * gretl_get_DW (int n
,int k
,int *err
);
Consults a table of Durbin-Watson critical values and returns the results in a gretl_matrix.
n |
number of observations |
|
k |
number of regressors excluding the constant. |
|
err |
location to receive error code. |
on success, a 4-vector containing the lower
and upper Durbin-Watson values, dl and du, along with
the values actually used for n
and k
(which may differ
from those given on input if the exact values are not
found in the table and have to be approximated).
On error, returns NULL
.