Interpolation | R Documentation |
Some interpolation methods are available to be used as part of 'RTMB' objective functions.
interpol1Dfun(z, xlim = c(1, length(z)), ...)
interpol2Dfun(z, xlim = c(1, nrow(z)), ylim = c(1, ncol(z)), ...)
## S4 method for signature 'ANY,advector,ANY,missing'
splinefun(x, y, method = c("fmm", "periodic", "natural"))
## S4 method for signature 'advector,missing,ANY,missing'
splinefun(x, method = c("fmm", "periodic", "natural"))
z |
Matrix to be interpolated |
xlim |
Domain of x |
... |
Configuration parameters |
ylim |
Domain of y |
x |
spline x coordinates |
y |
spline y coordinates |
method |
Same as for the stats version, however only the three first are available. |
interpol1Dfun
and interpol2Dfun
are kernel smoothers useful in the case where you need a 3rd order smooth representation of a data vector or matrix.
A typical use case is when a high-resolution map needs to be accessed along a random effect trajectory.
Both 1D and 2D cases accept an 'interpolation radius' parameter (default R=2) controlling the degree of smoothness. Note, that only the value R=1 will match the data exactly, while higher radius trades accuracy for smoothness. Note also that these smoothers do not attempt to extrapolate: The returned value will be NaN
outside the valid range (xlim
/ ylim
).
splinefun
imitates the corresponding stats
function. The AD implementation (in contrast to interpol1Dfun
) works for parameter dependent y-coordinates.
function of x.
function of x and y.
interpol1Dfun()
: Construct a kernel smoothed representation of a vector.
interpol2Dfun()
: Construct a kernel smoothed representation of a matrix.
splinefun(x = ANY, y = advector, method = ANY, ties = missing)
: Construct a spline function.
splinefun(x = advector, y = missing, method = ANY, ties = missing)
: Construct a spline function.
## ======= interpol1D
## R=1 => exact match of observations
f <- interpol1Dfun(sin(1:10), R=1)
layout(t(1:2))
plot(sin(1:10))
plot(f, 1, 10, add=TRUE)
title("R=1")
F <- MakeTape(f, 0)
F3 <- F$jacfun()$jacfun()$jacfun()
plot(Vectorize(F3), 1, 10)
title("3rd derivative")
## ======= interpol2D
## R=1 => exact match of observations
f <- interpol2Dfun(volcano, xlim=c(0,1), ylim=c(0,1), R=1)
f(0,0) == volcano[1,1] ## Top-left corner
f(1,1) == volcano[87,61] ## Bottom-right corner
## R=2 => trades accuracy for smoothness
f <- interpol2Dfun(volcano, xlim=c(0,1), ylim=c(0,1), R=2)
f(0,0) - volcano[1,1] ## Error Top-left corner
F <- MakeTape(function(x) f(x[1],x[2]), c(.5,.5))
## ======= splinefun
T <- MakeTape(function(x){
S <- splinefun(sin(x))
S(4:6)
}, 1:10)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.