Skip to content

Problem with adapt package

4 messages · Anthony Tate, Jonathan Rougier, Martin Maechler

#
I am having problems using the adapt add on package to integrate a function
over 2 dimensions, using the following code.

library(adapt)

alb1 <- function(p,X,th,alpha){ 
   y <- p[1]; z <- p[2] 
   c <- sqrt((X + z*tan(th))^2 + z^2) 
   r <- sqrt(c^2 + y^2) 
   exp(-alpha*r) / r^3 
} 
 
x <- 0.05
y <- x 
w <- 0.5
delta <- 0.1
czang <- pi/4
alpha <- 15.0
y[i] <- adapt(ndim=2, lower=c(0,0), upper=c(w,delta), 
        minpts=1000, maxpts=10^6, funct=alb1,  eps=0.005,
        X=x, th=czang, alpha=alpha)$value


The code gives the following error 

Error in function (p, X, th, alpha)  : Argument "X" is missing, with no default 

I am using is SUSE linux 6.4 with the following version of R.

         _
platform i586-pc-linux-gnu
arch     i586
os       linux-gnu
system   i586, linux-gnu
status
major    1
minor    3.0
year     2001
month    06
day      22
language R 

Yours sincerely,

Anthony Tate


---------------------------------------------------------------

Anthony Tate          E-Mail: Anthony Tate <agt at ma.adfa.edu.au>
School of Mathematics and Statistics
UNSW at the Australian Defence Force Academy
Canberra ACT
Australia

Date: 29-Jun-01
Time: 09:58:53

This message is intended for the addressee named and may contain
confidential information.  If you are not the intended recipient, please
delete it and notify the sender.  Views expressed in this message are those
of the individual sender and are not necessarily the views of the University
of New South Wales at the Australian Defence Force Academy



-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
#
Hi Anthony,
Anthony Tate wrote:
This is a bug that I thought we had squashed.  Crudely there is a "..."
missing in the line "ff<-functn".  I have a feeling that Martin fixed
this with some tricky code using ".Alias", but the fix has not appeared
on CRAN.  Martin?!

Cheers, Jonathan.
#
JonR> Hi Anthony,
JonR> Anthony Tate wrote:
>> 
    >> I am having problems using the adapt add on package to integrate a function
    >> over 2 dimensions, using the following code.
    >> 
    >> library(adapt)
    >> 
    >> alb1 <- function(p,X,th,alpha){
    >> y <- p[1]; z <- p[2]
    >> c <- sqrt((X + z*tan(th))^2 + z^2)
    >> r <- sqrt(c^2 + y^2)
    >> exp(-alpha*r) / r^3
    >> }
    >> 
    >> x <- 0.05
    >> y <- x
    >> w <- 0.5
    >> delta <- 0.1
    >> czang <- pi/4
    >> alpha <- 15.0
    >> y[i] <- adapt(ndim=2, lower=c(0,0), upper=c(w,delta),
    >> minpts=1000, maxpts=10^6, funct=alb1,  eps=0.005,
    >> X=x, th=czang, alpha=alpha)$value
    >> 
    >> The code gives the following error
    >> 
    >> Error in function (p, X, th, alpha)  : Argument "X" is missing, with no default

    JonR> This is a bug that I thought we had squashed.  Crudely there is a
    JonR> "..."  missing in the line "ff<-functn".  I have a feeling that
    JonR> Martin fixed this with some tricky code using ".Alias", but the
    JonR> fix has not appeared on CRAN.  Martin?!

Yes, this definitely rings a bell!  Indeed I had fixed something like that,
submitted to Thomas, who had put it into the integrate package then.

"adapt" has been packaged by Brian Ripley and I haven't checked whether
adapt() was the same as formerly in the integrate package...

Okay, yes, apply (something like) the following patch

--- R/adapt.R.~1~	Wed Jun 27 17:22:38 2001
+++ R/adapt.R	Fri Jun 29 13:38:41 2001
@@ -7,12 +7,14 @@
     keep.trying<-is.null(maxpts)
     if (is.null(maxpts)) maxpts<-max(minpts,500)
   
-    ## fudge for 1-d functions
-    if (ndim == 1) {
+    if (ndim == 1) { ## fudge for 1-d functions
         warning("Using integrate() in base R for 1-d integration")
         return(integrate(functn,lower,upper,subdivisions=maxpts,rel.tol=eps,...))
     }
-    else ff<-functn
+    else ff <-
+        if(length(list(...)) && length(formals(functn)) > 1)
+            function(x) functn(x, ...)
+        else .Alias(functn)
   
     ## Check to make sure that upper and lower are reasonable lengths
     ## Both the upper and lower limits should be at least of length ndim


-----------

Note that the point is not in using .Alias() {which could be omitted},
but in the extra

 if(length(list(...)) && length(formals(functn)) > 1)
	     function(x) functn(x, ...)
	 else 

--

Martin Maechler <maechler at stat.math.ethz.ch>	http://stat.ethz.ch/~maechler/
Seminar fuer Statistik, ETH-Zentrum  LEO D10	Leonhardstr. 27
ETH (Federal Inst. Technology)	8092 Zurich	SWITZERLAND
phone: x-41-1-632-3408		fax: ...-1228			<><
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
#
JonR> Hi Anthony,
JonR> Anthony Tate wrote:
>>> 
    >>> I am having problems using the adapt add on package to integrate a
    >>> function over 2 dimensions, using the following code.
    >>> 
    >>> library(adapt)
    >>> 
    >>> alb1 <- function(p,X,th,alpha){
    >>> y <- p[1]; z <- p[2]
    >>> c <- sqrt((X + z*tan(th))^2 + z^2)
    >>> r <- sqrt(c^2 + y^2)
    >>> exp(-alpha*r) / r^3
    >>> }
    >>> 
    >>> x <- 0.05
    >>> y <- x
    >>> w <- 0.5
    >>> delta <- 0.1
    >>> czang <- pi/4
    >>> alpha <- 15.0
    >>> y[i] <- adapt(ndim=2, lower=c(0,0), upper=c(w,delta),
    >>> minpts=1000, maxpts=10^6, funct=alb1,  eps=0.005,
    >>> X=x, th=czang, alpha=alpha)$value
    >>> 
    >>> The code gives the following error
    >>> 
    >>> Error in function (p, X, th, alpha)  : Argument "X" is missing, with no default

    JonR> This is a bug that I thought we had squashed.  Crudely there is a
    JonR> "..."  missing in the line "ff<-functn".  I have a feeling that
    JonR> Martin fixed this with some tricky code using ".Alias", but the
    JonR> fix has not appeared on CRAN.  Martin?!

    MM> Yes, this definitely rings a bell!  Indeed I had fixed something
    MM> like that, submitted to Thomas, who had put it into the integrate
    MM> package then.

    MM> "adapt" has been packaged by Brian Ripley and I haven't checked
				  ^^^^^^^^^^^^^^^
all wrong!  I apologize.
B.R. and Thomas Lumley and me were just discussing the topic, 
but Thomas, not Brian volunteered to re-package the adapt() function!
    
    MM>  ...
    MM> Okay, yes, apply (something like) the following patch

    MM>  <...>
    
 (see last message, the patch is fine).


Martin Maechler <maechler at stat.math.ethz.ch>	http://stat.ethz.ch/~maechler/
Seminar fuer Statistik, ETH-Zentrum  LEO D10	Leonhardstr. 27
ETH (Federal Inst. Technology)	8092 Zurich	SWITZERLAND
phone: x-41-1-632-3408		fax: ...-1228			<><
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._