R-beta: spline problems(?)

Douglas Bates bates at stat.wisc.edu
Tue Apr 7 04:47:32 CEST 1998


"A. Tsiolakidis" <tsioltas at cs.keele.ac.uk> writes:

> I am a total beginner with this whole thing so please have patience!
> 
> I am trying to run an S-plus program with a certain line:
> 	spline(1:nrow(y), y[,1],n=100);
> 
> This crashes with:
> 	Error: NAs in foreign function call (arg 8)
> 
> Apparently, this is caused by the last command of spline:
> 	u <- seq(xmin, xmax, length.out = n)
>         .C("spline_eval", z$method, length(u), x = u, y = double(n), 
>                 z$n, z$x, z$y, z$b, z$c, z$d)[c("x", "y")]
> }
> 
> Now, I can cause that error with: spline(1:10,1:10)
> So, there  is a whole class of problems for which spline refuses to
> compute anything - is this the correct behaviour? E.g.,
> 	spline(1:10,(1:10)/2.5) #it is alright, but ...
> 	spline(1:10,(1:10)/2)   # this has the "NAs.." problem
> 
> Finally, I am almost sure that the y matrix in my program has quite
> normal values, i.e. values that should allow for meaningful
> interpolation.
> Anybody knows what this all is about?

If you have the splines library installed, could you try the same
problem using interpSpline instead of spline?  The sequence for the
1:10, 1:10 example looks like
 R> library(splines)
 R> ttt <- interpSpline(y ~ x, data.frame(x = 1:10, y = 1:10) )
 R> ttt
 polynomial representation of spline for y ~ x
    constant linear   quadratic       cubic
  1        1      1  0.0000e+00 -3.3307e-16
  2        2      1 -9.9920e-16  9.9920e-16
  3        3      1  1.9984e-15 -1.4063e-15
  4        4      1 -2.2204e-15  7.4015e-16
  5        5      1  0.0000e+00  8.8818e-16
  6        6      1  2.6645e-15 -1.7764e-15
  7        7      1 -2.6645e-15  8.8818e-16
  8        8      1  0.0000e+00  8.8818e-16
  9        9      1  2.6645e-15 -8.8818e-16
 10       10      1  0.0000e+00 -8.8818e-16
 R> plot( ttt )  # produces a nice straight line plot.
 R> predict( ttt )
 $x
  [1]  1.00  1.18  1.36  1.54  1.72  1.90  2.08  2.26  2.44  2.62
 [11]  2.80  2.98  3.16  3.34  3.52  3.70  3.88  4.06  4.24  4.42
 [21]  4.60  4.78  4.96  5.14  5.32  5.50  5.68  5.86  6.04  6.22
 [31]  6.40  6.58  6.76  6.94  7.12  7.30  7.48  7.66  7.84  8.02
 [41]  8.20  8.38  8.56  8.74  8.92  9.10  9.28  9.46  9.64  9.82
 [51] 10.00

 $y
  [1]  1.00  1.18  1.36  1.54  1.72  1.90  2.08  2.26  2.44  2.62
 [11]  2.80  2.98  3.16  3.34  3.52  3.70  3.88  4.06  4.24  4.42
 [21]  4.60  4.78  4.96  5.14  5.32  5.50  5.68  5.86  6.04  6.22
 [31]  6.40  6.58  6.76  6.94  7.12  7.30  7.48  7.66  7.84  8.02
 [41]  8.20  8.38  8.56  8.74  8.92  9.10  9.28  9.46  9.64  9.82
 [51] 10.00

 attr(,"class")
 [1] "xyVector"
 R> predict( ttt, len = 100 )
 Error in predict.npolySpline(ttt, len = 100) : unused argument to function
 R> predict( ttt, nseg = 100 )
 $x
   [1]  1.00  1.09  1.18  1.27  1.36  1.45  1.54  1.63  1.72  1.81
  [11]  1.90  1.99  2.08  2.17  2.26  2.35  2.44  2.53  2.62  2.71
  [21]  2.80  2.89  2.98  3.07  3.16  3.25  3.34  3.43  3.52  3.61
  [31]  3.70  3.79  3.88  3.97  4.06  4.15  4.24  4.33  4.42  4.51
  [41]  4.60  4.69  4.78  4.87  4.96  5.05  5.14  5.23  5.32  5.41
  [51]  5.50  5.59  5.68  5.77  5.86  5.95  6.04  6.13  6.22  6.31
  [61]  6.40  6.49  6.58  6.67  6.76  6.85  6.94  7.03  7.12  7.21
  [71]  7.30  7.39  7.48  7.57  7.66  7.75  7.84  7.93  8.02  8.11
  [81]  8.20  8.29  8.38  8.47  8.56  8.65  8.74  8.83  8.92  9.01
  [91]  9.10  9.19  9.28  9.37  9.46  9.55  9.64  9.73  9.82  9.91
 [101] 10.00

 $y
   [1]  1.00  1.09  1.18  1.27  1.36  1.45  1.54  1.63  1.72  1.81
  [11]  1.90  1.99  2.08  2.17  2.26  2.35  2.44  2.53  2.62  2.71
  [21]  2.80  2.89  2.98  3.07  3.16  3.25  3.34  3.43  3.52  3.61
  [31]  3.70  3.79  3.88  3.97  4.06  4.15  4.24  4.33  4.42  4.51
  [41]  4.60  4.69  4.78  4.87  4.96  5.05  5.14  5.23  5.32  5.41
  [51]  5.50  5.59  5.68  5.77  5.86  5.95  6.04  6.13  6.22  6.31
  [61]  6.40  6.49  6.58  6.67  6.76  6.85  6.94  7.03  7.12  7.21
  [71]  7.30  7.39  7.48  7.57  7.66  7.75  7.84  7.93  8.02  8.11
  [81]  8.20  8.29  8.38  8.47  8.56  8.65  8.74  8.83  8.92  9.01
  [91]  9.10  9.19  9.28  9.37  9.46  9.55  9.64  9.73  9.82  9.91
 [101] 10.00

 attr(,"class")
 [1] "xyVector"

The splines library is available in the src/contrib section of any of
the CRAN archives.  The master CRAN site is
	      http://www.ci.tuwien.ac.at/R/contents.html
-- 
Douglas Bates                            bates at stat.wisc.edu
Statistics Department                    608/262-2598
University of Wisconsin - Madison        http://www.stat.wisc.edu/~bates/
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list