On Sep 11, 2010, at 10:04 AM, Martin Maechler wrote:

"SW" == Samuel Wuest <wue...@tcd.ie>
   on Thu, 26 Aug 2010 14:34:26 +0100 writes:

   SW> Hi Greg,
   SW> thanks for the suggestion:

SW> I have attached some small dataset that can be used to reproduce the
   SW> odd behavior of the approxfun-function.

   SW> If it gets stripped off my email, it can also be downloaded at:
   SW> http://bioinf.gen.tcd.ie/approx.data.Rdata

SW> Strangely, the problem seems specific to the data structure in my SW> expression set, when I use simulated data, everything worked fine.

SW> Here is some code that I run and resulted in the strange output that I
   SW> have described in my initial post:

### load the data: a list called approx.data
load(file="approx.data.Rdata")
### contains the slots "x", "y", "input"
names(approx.data)
   SW> [1] "x"     "y"     "input"
### with y ranging between 0 and 1
range(approx.data$y)
   SW> [1] 0 1
### compare ranges of x and input-x values (the latter is a small subset of 500 data points):
range(approx.data$x)
   SW> [1] 3.098444 7.268812
range(approx.data$input)
   SW> [1]  3.329408 13.026700


### generate the interpolation function (warning message benign)
interp <- approxfun(approx.data$x, approx.data$y, yleft=1, yright=0, rule=2)
   SW> Warning message:
SW> In approxfun(approx.data$x, approx.data$y, yleft = 1, yright = 0, :
   SW> collapsing to unique 'x' values

### apply to input-values
y.out <- sapply(approx.data$input, interp)

### still I find output values >1, even though yleft=1:
range(y.out)
   SW> [1] 0.000000 7.207233
#-------------- on another  64 bit Mac -------------
> load(file="approx.data.Rdata")
> names(approx.data)
[1] "x"     "y"     "input"
> range(approx.data$y)
[1] 0 1
> range(approx.data$x)
[1] 3.098444 7.268812
>
> interp <- approxfun(approx.data$x, approx.data$y, yleft=1, yright=0, rule=2)
Warning message:
In approxfun(approx.data$x, approx.data$y, yleft = 1, yright = 0,  :
  collapsing to unique 'x' values
> y.out <- sapply(approx.data$input, interp)
> range(y.out)
[1] -5.143958e+284   9.816907e-01

> interp
function (v)
.C("R_approxfun", as.double(x), as.double(y), as.integer(n),
    xout = as.double(v), as.integer(length(v)), as.integer(method),
    as.double(yleft), as.double(yright), as.double(f), NAOK = TRUE,
    PACKAGE = "stats")$xout
<environment: 0x1598c91b8>

# attempt to offer yright and yledft in the sapply call failed
> y.out <- sapply(approx.data$input, interp, yright=0, yleft=1)
Error in FUN(c(6.99984458535897, 4.85139079147721, 7.58922165833, 10.8135863246057, :
  unused argument(s) (yright = 0, yleft = 1)

#Create yright and yleft in the calling environment:

> yright=0; yleft=1
> y.out <- sapply(approx.data$input, interp)
> range(y.out)
[1] 0.0000000 0.9816907

Now it "works" as expected.


It seems to me that the yleft and yright values may not be properly incorporated into the constructed function.


> sessionInfo()
R version 2.11.1 Patched (2010-06-14 r52281)
x86_64-apple-darwin9.8.0

locale:
[1] en_US.UTF-8/en_US.UTF-8/C/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] grid      splines   stats     graphics  grDevices
[6] utils     datasets  methods   base

other attached packages:
 [1] gplots_2.8.0     caTools_1.10     bitops_1.0-4.1
 [4] gdata_2.8.0      gtools_2.6.2     sos_1.2-9
 [7] brew_0.1-1       qpcR_1.3-2       minqa_1.1.9
[10] Rcpp_0.8.5       nlme_3.1-96      cluster_1.12.3
[13] rgl_0.91         minpack.lm_1.1-4 MASS_7.3-6
[16] chron_2.3-35     maps_2.1-4       gmodels_2.15.0
[19] rbenchmark_0.3   data.table_1.5   rms_3.0-0
[22] Hmisc_3.8-1      survival_2.35-8  plyr_1.1
[25] lattice_0.18-8

loaded via a namespace (and not attached):
[1] tools_2.11.1

--
David Winsemius



I get completely different (and correct) results,
by the way the *same* you have in the bug report you've
submitted
(https://bugs.r-project.org/bugzilla3/show_bug.cgi?id=14377)
and which does *not* show any bug:

range(y.out)
[1] 0.0000000 0.9816907

Of course, I do believe that you've seen the above problems,
-- on 64-bit Mac ? as you report in sessionInfo() ? --
but I cannot reproduce them.

And also, you seem yourself to be able to get different results
for the same data... what are the circumstances?

Regards,
Martin Maechler, ETH Zurich


David Winsemius, MD
West Hartford, CT

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to