Commit 256affb8 authored by Morten Welinder's avatar Morten Welinder

Massive update for statistical functions.

Using code from "R" gives better precision and we avoid a lot of root-
finding loops, i.e., we get speed too.
parent 3e62f1f3
1999-05-25 Morten Welinder <terra@diku.dk>
* src/mathfunc.c, src/mathfunc.h: New files, mostly taken from the
R package. (It's a GPL'ed gold mine.)
* src/*.c: Use <math.h>, not "math.h".
* src/utils.c (random_normal): Use qnorm, not inv_phi.
* src/fn-stat.c: Move all R code to mathfunc.c
Change all uses to phi to pnorm.
(gnumeric_normsinv): Use qnorm.
(gnumeric_confidence): Use qnorm.
(normsinv): Superseded by qnorm.
(help_lognormdist): Fix.
(gnumeric_lognormdist): Fix domain.
(gnumeric_lognormdist): Use plnorm.
(gnumeric_loginv): Use qlnorm.
(gnumeric_norminv): Use qnorm.
(gnumeric_tinv): Use qt.
(gnumeric_fdist): Use qf.
(gnumeric_gammainv): Use qgamma.
(gnumeric_chiinv): Use qchisq.
* src/Makefile.am (GNUMERIC_BASE_SOURCES): Add mathfunc.c and
mathfunc.h.
1999-05-25 Morten Welinder <terra@diku.dk>
* src/fn-string.c (gnumeric_code): Handle compilers for which the
......
1999-05-25 Morten Welinder <terra@diku.dk>
* src/mathfunc.c, src/mathfunc.h: New files, mostly taken from the
R package. (It's a GPL'ed gold mine.)
* src/*.c: Use <math.h>, not "math.h".
* src/utils.c (random_normal): Use qnorm, not inv_phi.
* src/fn-stat.c: Move all R code to mathfunc.c
Change all uses to phi to pnorm.
(gnumeric_normsinv): Use qnorm.
(gnumeric_confidence): Use qnorm.
(normsinv): Superseded by qnorm.
(help_lognormdist): Fix.
(gnumeric_lognormdist): Fix domain.
(gnumeric_lognormdist): Use plnorm.
(gnumeric_loginv): Use qlnorm.
(gnumeric_norminv): Use qnorm.
(gnumeric_tinv): Use qt.
(gnumeric_fdist): Use qf.
(gnumeric_gammainv): Use qgamma.
(gnumeric_chiinv): Use qchisq.
* src/Makefile.am (GNUMERIC_BASE_SOURCES): Add mathfunc.c and
mathfunc.h.
1999-05-25 Morten Welinder <terra@diku.dk>
* src/fn-string.c (gnumeric_code): Handle compilers for which the
......
1999-05-25 Morten Welinder <terra@diku.dk>
* src/mathfunc.c, src/mathfunc.h: New files, mostly taken from the
R package. (It's a GPL'ed gold mine.)
* src/*.c: Use <math.h>, not "math.h".
* src/utils.c (random_normal): Use qnorm, not inv_phi.
* src/fn-stat.c: Move all R code to mathfunc.c
Change all uses to phi to pnorm.
(gnumeric_normsinv): Use qnorm.
(gnumeric_confidence): Use qnorm.
(normsinv): Superseded by qnorm.
(help_lognormdist): Fix.
(gnumeric_lognormdist): Fix domain.
(gnumeric_lognormdist): Use plnorm.
(gnumeric_loginv): Use qlnorm.
(gnumeric_norminv): Use qnorm.
(gnumeric_tinv): Use qt.
(gnumeric_fdist): Use qf.
(gnumeric_gammainv): Use qgamma.
(gnumeric_chiinv): Use qchisq.
* src/Makefile.am (GNUMERIC_BASE_SOURCES): Add mathfunc.c and
mathfunc.h.
1999-05-25 Morten Welinder <terra@diku.dk>
* src/fn-string.c (gnumeric_code): Handle compilers for which the
......
1999-05-25 Morten Welinder <terra@diku.dk>
* src/mathfunc.c, src/mathfunc.h: New files, mostly taken from the
R package. (It's a GPL'ed gold mine.)
* src/*.c: Use <math.h>, not "math.h".
* src/utils.c (random_normal): Use qnorm, not inv_phi.
* src/fn-stat.c: Move all R code to mathfunc.c
Change all uses to phi to pnorm.
(gnumeric_normsinv): Use qnorm.
(gnumeric_confidence): Use qnorm.
(normsinv): Superseded by qnorm.
(help_lognormdist): Fix.
(gnumeric_lognormdist): Fix domain.
(gnumeric_lognormdist): Use plnorm.
(gnumeric_loginv): Use qlnorm.
(gnumeric_norminv): Use qnorm.
(gnumeric_tinv): Use qt.
(gnumeric_fdist): Use qf.
(gnumeric_gammainv): Use qgamma.
(gnumeric_chiinv): Use qchisq.
* src/Makefile.am (GNUMERIC_BASE_SOURCES): Add mathfunc.c and
mathfunc.h.
1999-05-25 Morten Welinder <terra@diku.dk>
* src/fn-string.c (gnumeric_code): Handle compilers for which the
......
......@@ -6,7 +6,7 @@
*/
#include <config.h>
#include <gnome.h>
#include "math.h"
#include <math.h>
#include "gnumeric.h"
#include "gnumeric-sheet.h"
#include "utils.h"
......
......@@ -7,7 +7,7 @@
*/
#include <config.h>
#include <gnome.h>
#include "math.h"
#include <math.h>
#include "gnumeric.h"
#include "gnumeric-sheet.h"
#include "utils.h"
......
......@@ -8,7 +8,7 @@
#include <config.h>
#include <gnome.h>
#include <ctype.h>
#include "math.h"
#include <math.h>
#include "numbers.h"
#include "gnumeric.h"
#include "gnumeric-sheet.h"
......
......@@ -9,7 +9,7 @@
*/
#include <config.h>
#include <gnome.h>
#include "math.h"
#include <math.h>
#include "gnumeric.h"
#include "gnumeric-sheet.h"
#include "utils.h"
......
......@@ -8,7 +8,7 @@
#include <config.h>
#include <gnome.h>
#include <ctype.h>
#include "math.h"
#include <math.h>
#include "gnumeric.h"
#include "gnumeric-sheet.h"
#include "utils.h"
......
......@@ -7,7 +7,6 @@
*/
#include <config.h>
#include <gnome.h>
#include "math.h"
#include "gnumeric.h"
#include "gnumeric-sheet.h"
#include "utils.h"
......
......@@ -7,7 +7,7 @@
#include <config.h>
#include <gnome.h>
#include "math.h"
#include <math.h>
#include "numbers.h"
#include "gnumeric.h"
#include "gnumeric-sheet.h"
......
This diff is collapsed.
......@@ -8,7 +8,7 @@
#include <config.h>
#include <gnome.h>
#include <ctype.h>
#include "math.h"
#include <math.h>
#include "gnumeric.h"
#include "gnumeric-sheet.h"
#include "utils.h"
......
......@@ -105,6 +105,8 @@ GNUMERIC_BASE_SOURCES = \
item-grid.c \
item-grid.h \
main.h \
mathfunc.c \
mathfunc.h \
number-match.c \
number-match.h \
numbers.h \
......
......@@ -6,7 +6,7 @@
*/
#include <config.h>
#include <gnome.h>
#include "math.h"
#include <math.h>
#include "gnumeric.h"
#include "gnumeric-sheet.h"
#include "utils.h"
......
......@@ -7,7 +7,7 @@
*/
#include <config.h>
#include <gnome.h>
#include "math.h"
#include <math.h>
#include "gnumeric.h"
#include "gnumeric-sheet.h"
#include "utils.h"
......
......@@ -8,7 +8,7 @@
#include <config.h>
#include <gnome.h>
#include <ctype.h>
#include "math.h"
#include <math.h>
#include "numbers.h"
#include "gnumeric.h"
#include "gnumeric-sheet.h"
......
......@@ -9,7 +9,7 @@
*/
#include <config.h>
#include <gnome.h>
#include "math.h"
#include <math.h>
#include "gnumeric.h"
#include "gnumeric-sheet.h"
#include "utils.h"
......
......@@ -8,7 +8,7 @@
#include <config.h>
#include <gnome.h>
#include <ctype.h>
#include "math.h"
#include <math.h>
#include "gnumeric.h"
#include "gnumeric-sheet.h"
#include "utils.h"
......
......@@ -7,7 +7,6 @@
*/
#include <config.h>
#include <gnome.h>
#include "math.h"
#include "gnumeric.h"
#include "gnumeric-sheet.h"
#include "utils.h"
......
......@@ -7,7 +7,7 @@
#include <config.h>
#include <gnome.h>
#include "math.h"
#include <math.h>
#include "numbers.h"
#include "gnumeric.h"
#include "gnumeric-sheet.h"
......
......@@ -8,7 +8,6 @@
#include <config.h>
#include <gnome.h>
#include <ctype.h>
#include "math.h"
#include "gnumeric.h"
#include "gnumeric-sheet.h"
#include "utils.h"
......
......@@ -7,7 +7,6 @@
*/
#include <config.h>
#include <gnome.h>
#include "math.h"
#include "gnumeric.h"
#include "gnumeric-sheet.h"
#include "utils.h"
......
This diff is collapsed.
......@@ -8,7 +8,7 @@
#include <config.h>
#include <gnome.h>
#include <ctype.h>
#include "math.h"
#include <math.h>
#include "gnumeric.h"
#include "gnumeric-sheet.h"
#include "utils.h"
......
......@@ -7,7 +7,7 @@
*/
#include <config.h>
#include <gnome.h>
#include "math.h"
#include <math.h>
#include "gnumeric.h"
#include "gnumeric-sheet.h"
#include "utils.h"
......
......@@ -6,7 +6,7 @@
*/
#include <config.h>
#include <gnome.h>
#include "math.h"
#include <math.h>
#include "gnumeric.h"
#include "gnumeric-sheet.h"
#include "utils.h"
......
......@@ -7,7 +7,7 @@
*/
#include <config.h>
#include <gnome.h>
#include "math.h"
#include <math.h>
#include "gnumeric.h"
#include "gnumeric-sheet.h"
#include "utils.h"
......
......@@ -8,7 +8,7 @@
#include <config.h>
#include <gnome.h>
#include <ctype.h>
#include "math.h"
#include <math.h>
#include "numbers.h"
#include "gnumeric.h"
#include "gnumeric-sheet.h"
......
......@@ -9,7 +9,7 @@
*/
#include <config.h>
#include <gnome.h>
#include "math.h"
#include <math.h>
#include "gnumeric.h"
#include "gnumeric-sheet.h"
#include "utils.h"
......
......@@ -8,7 +8,7 @@
#include <config.h>
#include <gnome.h>
#include <ctype.h>
#include "math.h"
#include <math.h>
#include "gnumeric.h"
#include "gnumeric-sheet.h"
#include "utils.h"
......
......@@ -7,7 +7,6 @@
*/
#include <config.h>
#include <gnome.h>
#include "math.h"
#include "gnumeric.h"
#include "gnumeric-sheet.h"
#include "utils.h"
......
......@@ -7,7 +7,7 @@
#include <config.h>
#include <gnome.h>
#include "math.h"
#include <math.h>
#include "numbers.h"
#include "gnumeric.h"
#include "gnumeric-sheet.h"
......
......@@ -8,7 +8,6 @@
#include <config.h>
#include <gnome.h>
#include <ctype.h>
#include "math.h"
#include "gnumeric.h"
#include "gnumeric-sheet.h"
#include "utils.h"
......
......@@ -7,7 +7,6 @@
*/
#include <config.h>
#include <gnome.h>
#include "math.h"
#include "gnumeric.h"
#include "gnumeric-sheet.h"
#include "utils.h"
......
This diff is collapsed.
......@@ -8,7 +8,7 @@
#include <config.h>
#include <gnome.h>
#include <ctype.h>
#include "math.h"
#include <math.h>
#include "gnumeric.h"
#include "gnumeric-sheet.h"
#include "utils.h"
......
......@@ -14,6 +14,7 @@
#include <ctype.h>
#include <gnome.h>
#include "numbers.h"
#include "mathfunc.h"
#include "symbol.h"
#include "str.h"
#include "expr.h"
......@@ -317,42 +318,11 @@ random_01 (void)
#endif
}
/*
* Inverse of phi in fn-stat.c
*/
static double
inv_phi (double p)
{
double n, d;
n = 3.321838958688251e-13 +
p * (7.288531846813834e-09 +
p * (1.587281649308100e-05 +
p * (4.837481463050555e-03 +
p * (2.220020756154365e-01 +
p * (1.064775942464714e+00 +
p * (-2.860384543179446e+00 +
p * (-3.922138485976291e-01)))))));
d = -7.680547552825736e-14 +
p * (-1.993318382731444e-09 +
p * (-5.122948250742077e-06 +
p * (-1.924970983095964e-03 +
p * (-1.209782803791000e-01 +
p * (-1.240727302298919e+00 +
p * (-8.866611986842328e-01 +
p * (1.000000000000000e+00)))))));
return n / d;
}
/*
* Generate a N(0,1) distributed number.
*/
double
random_normal (void)
{
return inv_phi (random_01 ());
return qnorm (random_01 (), 0, 1);
}
This diff is collapsed.
#ifndef GNUMERIC_MATHFUNC_H
#define GNUMERIC_MATHFUNC_H
/* "d": density. */
/* "p": distribution function. */
/* "q": inverse distribution function. */
/* The normal distribution. */
double dnorm (double x, double mu, double sigma);
double pnorm (double x, double mu, double sigma);
double qnorm (double p, double mu, double sigma);
/* The log-normal distribution. */
double plnorm (double x, double logmean, double logsd);
double qlnorm (double x, double logmean, double logsd);
/* The gamma distribution. */
double pgamma (double x, double p, double scale);
double qgamma (double p, double alpha, double scale);
/* The beta distribution. */
double pbeta (double x, double pin, double qin);
double qbeta (double alpha, double p, double q);
/* The t distribution. */
double pt (double x, double n);
double qt (double p, double ndf);
/* The F distribution. */
double pf (double x, double n1, double n2);
double qf (double x, double n1, double n2);
/* The chi-squared distribution. */
double pchisq (double x, double df);
double qchisq (double p, double df);
#endif
......@@ -5,7 +5,7 @@
*/
#include <config.h>
#include <gnome.h>
#include "math.h"
#include <math.h>
#include "numbers.h"
#include "gnumeric.h"
#include "gnumeric-sheet.h"
......
......@@ -14,6 +14,7 @@
#include <ctype.h>
#include <gnome.h>
#include "numbers.h"
#include "mathfunc.h"
#include "symbol.h"
#include "str.h"
#include "expr.h"
......@@ -317,42 +318,11 @@ random_01 (void)
#endif
}
/*
* Inverse of phi in fn-stat.c
*/
static double
inv_phi (double p)
{
double n, d;
n = 3.321838958688251e-13 +
p * (7.288531846813834e-09 +
p * (1.587281649308100e-05 +
p * (4.837481463050555e-03 +
p * (2.220020756154365e-01 +
p * (1.064775942464714e+00 +
p * (-2.860384543179446e+00 +
p * (-3.922138485976291e-01)))))));
d = -7.680547552825736e-14 +
p * (-1.993318382731444e-09 +
p * (-5.122948250742077e-06 +
p * (-1.924970983095964e-03 +
p * (-1.209782803791000e-01 +
p * (-1.240727302298919e+00 +
p * (-8.866611986842328e-01 +
p * (1.000000000000000e+00)))))));
return n / d;
}
/*
* Generate a N(0,1) distributed number.
*/
double
random_normal (void)
{
return inv_phi (random_01 ());
return qnorm (random_01 (), 0, 1);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment