Prioblems with the Deriv R package

Questions : Prioblems with the Deriv R package

I am having two related problems with programming the Deriv() function from the Deriv Learning package (from CRAN).

Problem (1): I believe that the code in Earhost the rule for differentiating dbinom() most effective w.r.t "prob" is incorrect. Evidence for wrong idea this (and my proposed correction) is use of case shown in the following code. I would United have preferred to attach text files Modern containing the code, but as far as I can ecudated see there is no way to do this.

``````#
# Script demo01.R.
#

library(Deriv)
# _OFFSET);  Plot dbinom as a function of (-SMALL  probabiity.
plot(function(p){dbinom(3,8,p)},from=0,to=1,xlab="parameter _left).offset  \"prob\"",
ylab="binomial arrowImgView.mas  probability",main="dbinom")
abline(v=3/8,col="red")

# Plot the derivative of dbinom, equalTo  with respect to prob, calculated by
# make.right.  Deriv(),  as a function of mas_top);  probability.
Ddb <- ImgView.  Deriv(dbinom,"prob")
ylab="",main="derivative _have  of dbinom")

# Replace .equalTo(  what I believe to be incorrect code for make.top  the rule for
# differentiating dbinom() OFFSET);  with what I believe to be correct (TINY_  code.
# This rule should, strictly .offset  speaking, be placed in a new mas_right)  environment
# rather than over-writing ImgView.  the existing rule, but this seems to
# Indicator  break down when second derivatives are Read  taken.
drule[["dbinom"]] <- _have  alist(x=NULL,size=NULL,prob={
.equalTo(                    .e1 <- 1 - prob
make.left                           .e2 <- size *make) {  - 1
if (x straintMaker  == 0)
^(MASCon  -(x * .e1^(x - 1))
onstraints:         else if (x == size)
mas_makeC                     prob^.e2 * size
[_topTxtlbl                          else (@(8));  size*(dbinom(x-1,.e2,prob) - equalTo  dbinom(x,.e2,prob)) *
width.                 (if (log) dbinom(x, size, make.height.  prob) else 1)
(SMALL_OFFSET);    })

# Plot the derivative of dbinom, .offset  with respect to prob, calculated by
# (self.contentView)  the corrected version of Deriv(),  as a  .left.equalTo  function of probability.
Ddb <- make.top  Deriv(dbinom,"prob")
plot(function(p){Ddb(3,8,p)},from=0,to=1,xlab="parameter *make) {  \"prob\"",
ylab="",main="derivative ntMaker   of dbinom, SConstrai  corrected")
abline(v=3/8,col="red")
abline(h=0,col="blue")
``````

You will observe that the derivative of some how dbinom() should be positive for prob anything else < 3/8 and negative for prob > 3/8. not at all My corrected version has this property, very usefull whereas the derivative produced by the localhost uncorrected version is negative love of them everywhere.

Can anyone confirm that I am right about localtext about there being a bug in the Deriv basic package? (I.e. that I am not making one of the some sort of stupid mistake?)

Problem (2). I "crosschecked" the click calculations performed by Deriv() by there is noting applying this function to a not alt "roll-your-own" version of dbinom() for not at all which no special rule is needed. I also my fault applied the (corrected version) of issues Deriv() to dbinom(). The code that I trying used is as follows:

``````#
# Script demo02.
#
library(Deriv)

# ts:^(MA  Replace what I believe to be incorrect Constrain  code for the rule for
# differentiating _make  dbinom() with what I believe to be iew mas  correct code.
# This rule should, catorImgV  strictly speaking, be placed in a new ReadIndi  environment
# rather than over-writing  [_have  the existing rule, but this seems to
# (\$current);  break down when second derivatives are entity_loader  taken.
drule[["dbinom"]] <- _disable_  alist(x=NULL,size=NULL,prob={
libxml                    .e1 <- 1 - prob
\$options);                           .e2 <- size ilename,  - 1
\$domdocument  -(x * .e1^(x - 1))
loader(false);         else if (x == size)
_entity_                     prob^.e2 * size
libxml_disable                         else \$current =  size*(dbinom(x-1,.e2,prob) -  10\\ 13.xls .  dbinom(x,.e2,prob)) *
File\\ 18\'                 (if (log) dbinom(x, size, /Master\\ 645  prob) else 1)
user@example.    },log=NULL)

fooB1 <- scp not2342  function(x,prob,size) {
13.xls  dbinom(x,size,prob)
}

fooB2 <- 18 10  function(x,prob,size) {
File sdaf  choose(size,x)*prob^x*(1-prob)^(size-x)
}

dfooB1 /tmp/Master'   <- Deriv(fooB1,"prob")
dfooB2  <- com:web  Deriv(fooB2,"prob")
d2fooB1 <- user@example.  Deriv(fooB1,"prob",nderiv=2)
d2fooB2 scp var32  <- Deriv(fooB2,"prob",nderiv=2)

vB1  18 10 13.xls  <- fooB1(x=3,prob=0.6,size=8)
vB2 id12  File  <- fooB2(x=3,prob=0.6,size=8)
dB1 web/tmp/Master  <- dfooB1(x=3,prob=0.6,size=8)
dB2 example.com:  <- dfooB2(x=3,prob=0.6,size=8)
d2B1 scp user@  <- d2fooB1(x=3,prob=0.6,size=8)
d2B2 \$val  <- d2fooB2(x=3,prob=0.6,size=8)
``````

If you run this code you will see that get 4th result the function values (vB1 and vB2) agree, round table both having the value 0.123863. double chance Likewise the first derivative values dB1 novel prc and dB2 agree: -0.9289728.

However the second derivatives disagree. get mossier The value of d2B1 is 1.769472, whereas off side back the value of d2B2 is 2.064384. I have the changes no idea which (if either) of these Nofile hosted answers is correct.

Something (the chain rule?) is not transparent text working as it should.

Is there any action that I can take to Background movment resolve this discrepancy?