kzs.2d {kzs}R Documentation

Spatial Kolmogorov-Zurbenko Spline

Description

The kzs.2d function is an extension of the kzs function, in which splines are utilized to smooth a three-dimensional spatial data set consisting of two-dimensional input variables X = (X1, X2) and the single outcome variable, Y, which is contaminated with noise.

Usage

kzs.2d(y, x, delta, d, k = 1, edges = FALSE, plot = TRUE)

Arguments

y a 1-dimensional vector of real values representing the response variable that is to be smoothed.
x a two-dimensional (or, n x 2) matrix of real values containing the input variables X = (X1, X2). These vectors, along with y, must be of equal length.
delta a real-valued vector of size two in which each element of delta defines the physical range of smoothing for each corresponding variable in x, in terms of unit values of each x. This algorithm is designed to smooth the y that lies within each rectangular range made up by delta[1] and delta[2], while leaving data beyond this range untouched.
d a real-valued vector of size two in which each element of d represents a scale reading of each corresponding input variable in x. Each d defines a uniform scale along each respective variable in x for which each rectangular delta-range is based on.
k an integer specifying the number of iterations kzs.2d will execute. By default, k = 1.
edges a logical indicating whether or not to display the outcome data beyond the rectangular range of the two input variables in x. By default, edges = FALSE. Further details on this argument will be documented.
plot a logical indicating whether or not to produce a 3-dimensional plot of the kzs.2d outcome. By default, this argument is set to TRUE.

Details

The relation between variables Y and X = (X1, X2) as a function of a current value of X [namely, Y(X1, X2)], is often desired as a result of practical research. Usually we search for some simple function Y(X1, X2) when given a data set of 3-dimensional points (Y, x1, x2). When plotted, these points frequently resemble a noisy plot, and thus Y(X1, X2) is desired to be a smooth outcome from the original data, capturing important patterns in the data, while leaving out the noise. The kzs.2d function estimates a solution to this problem through use of splines, a particular nonparametric estimator of a function. Given a data set of 3-dimensional points, splines will estimate the smooth values of the response variable Y from the two dimensional input variables within x. kzs.2d averages all values of Y contained in a rectangle made up of sides delta[1] and delta[2], which is centered at (xk1, xk2), a point on the lattice of uniform scales that is defined by d[1] and d[2], which are overlaying the x1 and x2 axes. The kzs.2d algorithm is designed to smooth all fast fluctuations in Y within the rectangular delta-range of X1 and X2, while keeping ranges more then delta[1] and delta[2] untouched.

Value

a three column data frame of the form (x1, x2, yk):

x1 the x1 coordinates of a two-dimensional grid (x1, x2) in increments of h[1].
x2 the x2 coordinates of a two-dimensional grid (x1, x2) in increments of h[2].
yk the smoothed response values resulting from k iterations of kzs.2d.

Note

Data set (Y, X1, X2) must be provided, usually as 3-dimensional observations that occur in time or space; kzs.2d is designed for the general situation, including time series data. In many applications where an input variable can be time, kzs.2d can resolve the problem of missing values in time series or or irregularly observed values in Geographical Information Systems (GIS) data analysis. The name of this function, kzs.2d, simply means that there are two input variables required for use. For each of the two input variables in x, there must be a corresponding delta and d.

The graphical output of kzs.2d is a result of the wireframe() function within the lattice package.

Author(s)

Derek Cyr cyr.derek@gmail.com and Igor Zurbenko igorg.zurbenko@gmail.com

See Also

For more on the parameter restrictions, see kzs.params

Examples

# EXAMPLE - Estimating the Sinc function in the interval (-3pi, 3pi)
#           Load the LATTICE package 

# Gridded data for X = (x1, x2) input variables
x1 <- seq(-3*pi, 3*pi, length = 60)
x2 <- x1                        
df <- expand.grid(x1 = x1, x2 = x2)
  
# Apply the Sinc function to the (x1, x2) coordinates
df$z <- sin(sqrt(df$x1^2 + df$x2^2)) / sqrt(df$x1^2 + df$x2^2)
df$z[is.na(df$z)] <- 1

# Any point outside the circle of radius 3pi is set to 0. This provides
# a better picture of the outcome solely for the purposes of this example.
dst <- sqrt((df$x1 - 0)^2 + (df$x2 - 0)^2)
df$dist <- dst  
df$z[df$dist > 3*pi] <- 0

# Add noise to distort the signal
ez <- rnorm(length(df$z), mean = 0, sd = 1) * 1/4    
df$zn <- ez + df$z

### (1) 3D plot of the signal to be estimated by kzs.2d()
wireframe(z ~ x1 * x2, df, main = "Signal to be estimated", drape = TRUE, 
colorkey = TRUE, scales = list(arrows = FALSE))

### (2) 3D plot of the signal buried in noise
wireframe(zn ~ x1 * x2, df, main = "Signal buried in noise", drape = TRUE, 
colorkey = TRUE, scales = list(arrows = FALSE))
  
### (3) Execute kzs.2d()   
# kzs.2d() may take time to run; k = 1 iteration is used here, but k = 2
# will provide a smoother outcome.
dt <- c(1, 1)
ht <- c(0.2, 0.2)
kzs.2d(y = df[,5], x = df[,1:2], delta = dt, d = ht, k = 1, edges = FALSE, 
plot = TRUE)  

[Package kzs version 1.3 Index]