kzs.2d | R Documentation |
The kzs.2d
function is a spatial extension of the kzs
function for two input variables.
kzs.2d(y, x, smooth, scale, k = 1, edges = TRUE, plot = TRUE)
y |
a one-dimensional vector of real values representing the response variable to be smoothed. |
x |
a two-dimensional matrix of real values containing the input variables X = (X1, X2). Each column represents an input variable. |
smooth |
a vector of size two that defines the width of the smoothing window along each input variable. |
scale |
a vector of size two in which each element will define a uniformly spaced scale along its respective input variable. |
k |
an integer specifying the number of iterations |
edges |
a logical indicating whether or not to display the outcome data beyond the rectangular range of the two
input variables. By default, |
plot |
a logical indicating whether or not to produce a 3-dimensional plot of the |
The details for this function are nearly identical to that of kzs
, except now extended to
three dimensional space. The only difference is that the kzs.2d
function averages all y
that
are contained within a rectangular window made up of sides smooth[1]
and smooth[2]
.
a three column data frame of the form (x1, x2, yk)
:
x1 |
the |
x2 |
the |
yk |
the smoothed response values resulting from |
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.
The graphical output of kzs.2d
is a result of the wireframe()
function within the lattice package.
Derek Cyr cyr.derek@gmail.com and Igor Zurbenko igorg.zurbenko@gmail.com
kzs
; For more on the parameter restrictions, see kzs.params
# 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.
sw <- c(1, 1)
sc <- c(0.2, 0.2)
kzs.2d(y = df[,5], x = df[,1:2], smooth = sw, scale = sc, k = 1, edges = TRUE,
plot = TRUE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.