3

help(spline) and help(na.spline) do not help me understand why I am getting this error, and there is nothing online that seems to address this directly.

I have a matrix that I generated from these two commands:

RatioTable <- ddply(Key, c('Name', 'Position'), function(x) c(AvgRatio = mean(x$RatioMeanBid)))
RatioMatrix <- daply(RatioTable, .(Name, Position), function(x) x$AvgRatio)

> RatioMatrix
             Position
     Name     1    2    3    4    5
      a      0.4  0.3  0.2  0.2   NA
      b      0.6  0.7   NA   NA  0.5
      c       NA  0.7   NA   NA   NA
      d      0.5  0.4  0.3  0.3  0.2
      e       NA   NA   NA   NA   NA

> str(RatioMatrix)
 num [1:5, 1:5] 0.4 0.6 NA 0.5 NA ...
 - attr(*, "dimnames")=List of 2
  ..$ Name      : chr [1:8305] "a" "b" "c" "d" ...
  ..$ Position: chr [1:10] "1" "2" "3" "4" ...

If I then execute the following interpolation spline commands on RatioMatrix, it WORKS:

d0 <- as.Date("2000-01-01")

RatioMatrix2 <- exp(na.spline(zoo(t(log(RatioMatrix)), d0 + seq_len(ncol(RatioMatrix))), 
                                method = "natural", na.rm = FALSE))

However, if I make any changes or additions to RatioMatrix such as truncation or adjusting the values in column 1 (so that they are larger than those in column 2), the interpolation spline command throws out an error:

RatioMatrix <- daply(RatioTable, .(Name, Position), function(x) x$AvgRatio)

Pos1Greater <- data.frame(RatioMatrix[,1] >= RatioMatrix[,2])
Pos2Greater <- data.frame(RatioMatrix[,1] < RatioMatrix[,2])

Adj=(Pos1Greater*RatioMatrix[,1]) + (Pos2Greater*(RatioMatrix[,2]+0.05))
RatioMatrix[,1] = t(Adj)

d0 <- as.Date("2000-01-01")

RatioMatrix2 <- exp(na.spline(zoo(t(log(RatioMatrix)), d0 + seq_len(ncol(RatioMatrix))), 
                                method = "natural", na.rm = FALSE))

Error in splinefun(x[!na], y[!na], ...) : zero non-NA points

I tried debug(splinefun) as suggested, but still not seeing where the NA's come from. Any ideas? Thanks for looking into this.

Cinji18
  • 619
  • 8
  • 22
  • It would help if you took the time to create a [reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). Include sufficient sample data such that we can copy/paste the code to reproduce the error in our own R session. This will help us answer your question. – MrFlick Oct 24 '14 at 18:44
  • 2
    The error you quote in the title seems pretty obvious to me; `splinefun` is being passed vectors `x` and `y` one or both of which contain **no** non `NA` observations. If your question is why is this happening, then either do as @MrFlick says & give us a reproducible example, or do `debug(splinefun)` and then re-run your code; it will drop to the debugger when `splinefun()` is called and you can step through the code and see where the `NA`s are coming from. – Gavin Simpson Oct 24 '14 at 18:58

0 Answers0