[Rd] (PR#7070)

Tony Plate tplate at blackmesacapital.com
Thu Jul 8 17:53:01 CEST 2004


AFAICS, this is not a bug: you need to name those extra arguments that you 
want passed to the function, otherwise they are positionally matched to 
other arguments of integrate.

E.g.:

# Here "-1" and "7" are interpreted as the values for the arguments 
"rel.tol" and "abs.tol" of integrate
 > integrate(dnorm,lower=0,upper=1,subdivisions=100,-1,7)
0.3413447 with absolute error < 3.8e-15

# Give your extra arguments names (that do not match arguments of 
integrate) and they get passed down to the function being integrated
 > integrate(dnorm,lower=0,upper=1,subdivisions=100,mean=-1,sd=7)
0.05565302 with absolute error < 6.2e-16
 >

However, given that the "..." appears at the end of the argument list for 
integrate() (which means that prior argument names can be partially 
matched), how would one pass the value for an argument named "k" (for example)?

 > integrate(function(x,k=NA) browser(), 0, 1, k=7)
Called from: f(x, ...)
Browse[1]> k
[1] NA
Browse[1]>

(the problem is that "k" partially matches the integrate() argument "keep.xy")

-- Tony

At Thursday 09:31 AM 7/8/2004, Rembert.DeBlander at econ.kuleuven.ac.be wrote:
> > version
>          _
>platform i686-pc-linux-gnu
>arch     i686
>os       linux-gnu
>system   i686, linux-gnu
>status
>major    1
>minor    7.1
>year     2003
>month    06
>day      16
>language R
>
>Bug:
>
>integrate(f,lower,upper,extra_args)
>
>where
>
>f <- function(x,extra_args)
>{
>body
>}
>
>integrate doesn't pass the extra arguments when calling f.
>As a first check of this finding I integrated dnorm from minus infinity =
>to 1, with mu =3D -1 and sd =3D 7. As shown below the result is not =
>equal to pnorm(1,-1,7), but it is equal to pnorm(1,0,1) where the =
>default values for mu and sd are taken.
>As a second check I debugged integrate see example 2 below.
>Since the function I need to integrate doesn't make sense with default =
>values for the extra parameters, I do not find a way to work around this =
>problem.
>I have not found any relevant existing bug reports.
>
>Rembert.DeBlander at econ.kuleuven.ac.be
>
>Example 1
>*********
> > integrate(dnorm,lower=3D"-INF",upper=3D1,-1,7)
>Error in integrate(dnorm, lower =3D "-INF", upper =3D 1, -1, 7) :
>         invalid parameter values
>
> > integrate(dnorm,lower=3D"-INF",upper=3D1,subdivisions=3D100,-1,7)
>0.841331 with absolute error < 0.16=20
>
> >integrate(dnorm,lower=3D"-INF",upper=3D1,subdivisions=3D100,rel.tol=3D.M=
>achine$double.eps^0.25,abs.tol=3D.Machine$double.eps^0.25,-1,7)
>0.8413448 with absolute error < 1.5e-05
>
> > pnorm(1,-1,7)
>[1] 0.6124515
>
> > pnorm(1,0,1)
>[1] 0.8413447
>
>Example 2
>*********
>fex <- function(x, v, M)
>{
>(x - t(v) %*% M %*% v)^2
>}
>debug(integrate)
>integrate(fex,lower=3D-3,upper=3D7,subdivisions=3D100,c(1,2,3),matrix(2,3=
>,3))
>
>results in
>.
>.
>.
>debug: wk <- .External("call_dqags", ff, rho =3D environment(), =
>as.double(lower),
>     as.double(upper), as.double(abs.tol), as.double(rel.tol),
>     limit =3D limit, PACKAGE =3D "base")
>Browse[1]>
>Error in t(v) : Argument "v" is missing, with no default
>
>______________________________________________
>R-devel at stat.math.ethz.ch mailing list
>https://www.stat.math.ethz.ch/mailman/listinfo/r-devel



More information about the R-devel mailing list