Commit 2c9528cd authored by Radford Neal's avatar Radford Neal

implement derivatives for plogis

parent 2b0256a6
......@@ -156,7 +156,7 @@ dpois \cr
rcauchy \cr
dnorm, pnorm, qnorm, rnorm \cr
rlnorm \cr
rlogis \cr
dlogis, plogis, rlogis \cr
rweibull
}
}
......
......@@ -2881,6 +2881,26 @@ static void Dplogis (double q, double location, double scale,
if (dscale) *dscale = 0;
}
else {
double q0 = (q - location) / scale;
double dp0 = dlogis (q0, 0, 1, 0);
if (dq) *dq = dp0 / scale;
if (dlocation) *dlocation = - dp0 / scale;
if (dscale) *dscale = - dp0 * q0 / scale;
if (!lower_tail) {
if (dq) *dq = -*dq;
if (dlocation) *dlocation = -*dlocation;
if (dscale) *dscale = -*dscale;
}
if (log_p) {
double expv = exp(-v);
if (dq) *dq *= expv;
if (dlocation) *dlocation *= expv;
if (dscale) *dscale *= expv;
}
}
}
......@@ -2920,7 +2940,7 @@ static struct { double (*fncall)(); void (*Dcall)(); } math3_table[48] = {
{ plnorm, 0 },
{ qlnorm, 0 },
{ dlogis, Ddlogis },
{ plogis, 0 },
{ plogis, Dplogis },
{ qlogis, 0 },
{ dnbinom, 0 },
{ pnbinom, 0 },
......
......@@ -333,6 +333,15 @@ test3(dlogis,log=TRUE)
test3z(dlogis)
test3z(dlogis,log=TRUE)
test3(plogis)
test3(plogis,log=TRUE)
test3(plogis,lower=FALSE)
test3(plogis,log=TRUE,lower=FALSE)
test3z(plogis)
test3z(plogis,log=TRUE)
test3z(plogis,lower=FALSE)
test3z(plogis,log=TRUE,lower=FALSE)
test2r(rlogis)
test3(dnorm)
......
......@@ -715,6 +715,111 @@ r2 -3.302515 -0.1448006
r1 -3.302515 0.01869128 -0.01869128 -0.1448006
r2 -3.302515 0.01869128 -0.01869128 -0.1448006
>
> test3(plogis)
[,1] [,2]
r1 0.3497392 0.3377968
r2 0.3497392 0.3377968
[,1] [,2]
r1 0.3497392 -0.3377968
r2 0.3497392 -0.3377968
[,1] [,2]
r1 0.3497392 0.2094967
r2 0.3497392 0.2094967
x1 x2 x3
r1 0.3497392 0.3377968 -0.3377968 0.2094967
r2 0.3497392 0.3377968 -0.3377968 0.2094967
> test3(plogis,log=TRUE)
[,1] [,2]
r1 -1.050567 0.9658534
r2 -1.050567 0.9658534
[,1] [,2]
r1 -1.050567 -0.9658534
r2 -1.050567 -0.9658534
[,1] [,2]
r1 -1.050567 0.5990084
r2 -1.050567 0.5990084
x1 x2 x3
r1 -1.050567 0.9658534 -0.9658534 0.5990084
r2 -1.050567 0.9658534 -0.9658534 0.5990084
> test3(plogis,lower=FALSE)
[,1] [,2]
r1 0.6502608 -0.3377968
r2 0.6502608 -0.3377968
[,1] [,2]
r1 0.6502608 0.3377968
r2 0.6502608 0.3377968
[,1] [,2]
r1 0.6502608 -0.2094967
r2 0.6502608 -0.2094967
x1 x2 x3
r1 0.6502608 -0.3377968 0.3377968 -0.2094967
r2 0.6502608 -0.3377968 0.3377968 -0.2094967
> test3(plogis,log=TRUE,lower=FALSE)
[,1] [,2]
r1 -0.4303818 -0.519479
r2 -0.4303818 -0.519479
[,1] [,2]
r1 -0.4303818 0.519479
r2 -0.4303818 0.519479
[,1] [,2]
r1 -0.4303818 -0.3221734
r2 -0.4303818 -0.3221734
x1 x2 x3
r1 -0.4303818 -0.519479 0.519479 -0.3221734
r2 -0.4303818 -0.519479 0.519479 -0.3221734
> test3z(plogis)
[,1] [,2]
r1 0.4374869 0.03679051
r2 0.4374869 0.03679051
[,1] [,2]
r1 0.4374869 -0.03679051
r2 0.4374869 -0.03679051
[,1] [,2]
r1 0.4374869 0.009247941
r2 0.4374869 0.009247941
z1 z2 z3
r1 0.4374869 0.03679051 -0.03679051 0.009247941
r2 0.4374869 0.03679051 -0.03679051 0.009247941
> test3z(plogis,log=TRUE)
[,1] [,2]
r1 -0.8267084 0.08409512
r2 -0.8267084 0.08409512
[,1] [,2]
r1 -0.8267084 -0.08409512
r2 -0.8267084 -0.08409512
[,1] [,2]
r1 -0.8267084 0.02113878
r2 -0.8267084 0.02113878
z1 z2 z3
r1 -0.8267084 0.08409512 -0.08409512 0.02113878
r2 -0.8267084 0.08409512 -0.08409512 0.02113878
> test3z(plogis,lower=FALSE)
[,1] [,2]
r1 0.5625131 -0.03679051
r2 0.5625131 -0.03679051
[,1] [,2]
r1 0.5625131 0.03679051
r2 0.5625131 0.03679051
[,1] [,2]
r1 0.5625131 -0.009247940
r2 0.5625131 -0.009247941
z1 z2 z3
r1 0.5625131 -0.03679051 0.03679051 -0.009247940
r2 0.5625131 -0.03679051 0.03679051 -0.009247941
> test3z(plogis,log=TRUE,lower=FALSE)
[,1] [,2]
r1 -0.5753409 -0.06540384
r2 -0.5753409 -0.06540384
[,1] [,2]
r1 -0.5753409 0.06540384
r2 -0.5753409 0.06540384
[,1] [,2]
r1 -0.5753409 -0.0164404
r2 -0.5753409 -0.0164404
z1 z2 z3
r1 -0.5753409 -0.06540384 0.06540384 -0.0164404
r2 -0.5753409 -0.06540384 0.06540384 -0.0164404
>
> test2r(rlogis)
x1 x2
r1 0.9543501 1 0.5333178
......
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