Commit f245011e authored by Radford Neal's avatar Radford Neal

implement derivatives for dbeta

parent fdfd6644
......@@ -153,6 +153,7 @@ dunif, punif, qunif, runif \cr
dexp, pexp, qexp, rexp \cr
dgeom, pgeom \cr
dpois \cr
dbeta \cr
dbinom \cr
pcauchy, qcauchy, rcauchy \cr
dnorm, pnorm, qnorm, rnorm \cr
......
......@@ -2841,6 +2841,33 @@ SEXP do_Math2(SEXP call, SEXP op, SEXP args, SEXP env, int variant)
/* Derivatives of math3 functions. */
static void Ddbeta (double x, double a, double b,
double *dx, double *da, double *db,
int give_log, double v)
{
if (!R_FINITE(v)) {
if (dx) *dx = 0;
if (da) *da = 0;
if (db) *db = 0;
}
else {
if (dx) *dx = (a-1)/x - (b-1)/(1-x);
if (da || db) {
double diab = digamma(a+b);
if (da) *da = log(x) - digamma(a) + diab;
if (db) *db = log1p(-x) - digamma(b) + diab;
}
if (!give_log) {
if (dx) *dx *= v;
if (da) *da *= v;
if (db) *db *= v;
}
}
}
static void Ddbinom (double x, double n, double p,
double *dx /*ignored*/, double *dn /*ignored*/, double *dp,
int give_log, double v)
......@@ -3152,7 +3179,7 @@ static void Dqlogis (double p, double location, double scale,
static struct { double (*fncall)(); void (*Dcall)(); } math3_table[48] = {
{ 0, 0 },
{ dbeta, 0 },
{ dbeta, Ddbeta },
{ pbeta, 0 },
{ qbeta, 0 },
{ dbinom, Ddbinom },
......
......@@ -379,6 +379,11 @@ test2i(pgeom,log=TRUE,lower=FALSE)
test2i(dpois)
test2i(dpois,log=TRUE)
test3(dbeta)
test3(dbeta,log=TRUE)
test3w(dbeta)
test3w(dbeta,log=TRUE)
test3v(dbinom)
test3v(dbinom,log=TRUE)
......
pqR version 2.15.1 (2018-00-00), based on R 2.15.0 (2012-03-30)
pqR version 2.15.1 (2019-00-00), based on R 2.15.0 (2012-03-30)
R 2.15.0 is Copyright (C) 2012 The R Foundation for Statistical Computing
ISBN 3-900051-07-0
Modifications to R in pqR are Copyright (C) 2013-2018 Radford M. Neal
Modifications to R in pqR are Copyright (C) 2013-2019 Radford M. Neal
Some modules are from R-2.15.1 or later versions distributed by the R Core Team
......@@ -815,6 +815,59 @@ r2 0.04879083 0.114805
r1 -3.020213 2.353004
r2 -3.020213 2.353004
>
> test3(dbeta)
[,1] [,2]
r1 0.8258716 0.3339383
r2 0.8258716 0.3339383
[,1] [,2]
r1 0.8258716 0.1019506
r2 0.8258716 0.1019506
[,1] [,2]
r1 0.8258716 0.6176604
r2 0.8258716 0.6176604
x1 x2 x3
r1 0.8258716 0.3339383 0.1019506 0.6176604
r2 0.8258716 0.3339383 0.1019506 0.6176604
> test3(dbeta,log=TRUE)
[,1] [,2]
r1 -0.191316 0.4043466
r2 -0.191316 0.4043466
[,1] [,2]
r1 -0.191316 0.1234461
r2 -0.191316 0.1234461
[,1] [,2]
r1 -0.191316 0.7478892
r2 -0.191316 0.7478892
x1 x2 x3
r1 -0.191316 0.4043466 0.1234461 0.7478892
r2 -0.191316 0.4043466 0.1234461 0.7478892
> test3w(dbeta)
[,1] [,2]
r1 0.000194595 -0.004659505
r2 0.000194595 -0.004659506
[,1] [,2]
r1 0.000194595 0.00206193
r2 0.000194595 0.00206193
[,1] [,2]
r1 0.000194595 -0.0003501507
r2 0.000194595 -0.0003501508
w1 w2 w3
r1 0.000194595 -0.004659505 0.00206193 -0.0003501507
r2 0.000194595 -0.004659506 0.00206193 -0.0003501508
> test3w(dbeta,log=TRUE)
[,1] [,2]
r1 -8.54459 -23.94464
r2 -8.54459 -23.94464
[,1] [,2]
r1 -8.54459 10.59601
r2 -8.54459 10.59601
[,1] [,2]
r1 -8.54459 -1.799383
r2 -8.54459 -1.799383
w1 w2 w3
r1 -8.54459 -23.94464 10.59601 -1.799383
r2 -8.54459 -23.94464 10.59601 -1.799383
>
> test3v(dbinom)
[,1] [,2]
r1 0.1429615 -0.9814315
......
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