Description Usage Arguments Details Value References See Also Examples
Uses the Akima (1970) method for univariate interpolation and the Modified Shephard Algorithm for bivariate interpolation.
1 |
x |
The actual values of the x-variable(s). A simple numeric variable for univariate interpolation and a matrix of locations for bivariate interpolation. |
y |
The variable to be interpolated. |
xout |
Points on the x-axis where the function is to be evaluated. A single numeric variable in the case of univariate interpolation and a matrix of locations for bivariate interpolation. |
knum |
The number of target points used for bivariate interpolation. |
std |
If TRUE, re-scales the columns of x and xout by dividing by the standard deviation of the columns in x. Not applicable for univariate interpolation. |
The univariate version of the function is designed as a partial replacement for the aspline function in the akima package. It produces a smooth function that closely resembles the interpolation that would be done by hand. Values of y are averaged across any ties for x. The function does not allow for extrapolation beyond the min(x), max(x) range.
The bivariate version of the function uses the modifed Shepard's method for interpolation. The function uses the RANN package to find the nearest knum target points to each location in xout. The following formula is used to interpolate from these target points to the locations given in xout:
\frac{∑_{i=1}^{knum} w_i y_i}{∑_{i=1}^{knum} w_i}
where
w_{i} = ((maxd - d_{i})^2)/(maxd*d_{i})
and
maxd = max(d_{1}, ..., d_{knum}).
The values of y interpolated to the xout locations.
Akima, Hiroshi, "A New Method of Interpolation and Smooth Curve Fitting Based on Local Procedures," Journal of the Association for Computing Machinery 17 (1970), 589-602.
Franke, R. and G. Neilson, "Smooth Interpolation of Large Sets of Scatter data," International Journal of Numerical Methods in Engineering 15 (1980), 1691 - 1704.
maketarget
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | set.seed(484849)
n = 1000
x <- runif(n,-2*pi,2*pi)
x <- sort(x)
y <- sin(x) + cos(x) - .5*sin(2*x) - .5*cos(2*x) + sin(3*x)/3 + cos(3*x)/3
x1 <- seq(-2*pi,2*pi,length=100)
y1 <- sin(x1) + cos(x1) - .5*sin(2*x1) - .5*cos(2*x1) + sin(3*x1)/3 + cos(3*x1)/3
yout <- smooth12(x1,y1,x)
plot(x,y,type="l")
lines(x,yout,col="red")
x <- seq(0,10)
xmat <- expand.grid(x,x)
y <- sqrt((xmat[,1]-5)^2 + (xmat[,2]-5)^2)
xout <- cbind(runif(n,0,10),runif(n,0,10))
y1 <- sqrt((xout[,1]-5)^2 + (xout[,2]-5)^2)
y2 <- smooth12(xmat,y,xout)
cor(y1,y2)
|
Loading required package: lattice
Loading required package: locfit
locfit 1.5-9.1 2013-03-22
Loading required package: maptools
Loading required package: sp
Checking rgeos availability: FALSE
Note: when rgeos is not available, polygon geometry computations in maptools depend on gpclib,
which has a restricted licence. It is disabled by default;
to enable gpclib, type gpclibPermit()
Loading required package: quantreg
Loading required package: SparseM
Attaching package: 'SparseM'
The following object is masked from 'package:base':
backsolve
Loading required package: RANN
[1] 0.9989234
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.