-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
05f3168
commit 9c2ade2
Showing
9 changed files
with
434 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
Package: kzs | ||
Type: Package | ||
Title: Kolmogorov-Zurbenko Spline | ||
Version: 1.1.0 | ||
Date: 2007-07-01 | ||
Author: Derek Cyr <dc896148@albany.edu> and Igor Zurbenko <igorg.zurbenko@gmail.com>. | ||
Maintainer: Derek Cyr <dc896148@albany.edu> | ||
Depends: R (>= 2.5.0), graphics, stats | ||
Description: A collection of functions utilizng splines to smooth a noisy data set in order | ||
to estimate its underlying signal. | ||
Title: Kolmogorov-Zurbenko Spline Smoothing and Applications | ||
Version: 1.2.0 | ||
Date: 2007-11-02 | ||
Author: Derek Cyr <cyr.derek@gmail.com> and Igor Zurbenko <igorg.zurbenko@gmail.com>. | ||
Maintainer: Derek Cyr <cyr.derek@gmail.com> | ||
Depends: R (>= 2.6.0), graphics, lattice, stats | ||
Description: A collection of functions utilizng splines to construct a smooth estimate | ||
of a signal buried in noise. | ||
License: GPL version 2 or newer | ||
Packaged: Sun Jul 1 15:30:14 2007; Owner | ||
Packaged: Fri Nov 2 23:36:30 2007; Owner |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
import(graphics, stats) | ||
export(kzs) | ||
import(graphics, lattice, stats) | ||
export(argkzs, kzs, argskzs, skzs) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
argkzs <- function(data, x) { | ||
delta <- max(data[,x]) - min(data[,x]) | ||
sx <- sort(data[,x]) | ||
dx <- diff(sx) | ||
minx <- min(dx[dx > 0]) | ||
arg1 <- sprintf("delta must be a real number much less than %s", delta) | ||
arg2 <- sprintf("h must be a positive real number less than %s", minx) | ||
lst <- list(delta = arg1, h = arg2) | ||
return(lst) | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
argskzs <- function(data, x1, x2) { | ||
delta1 <- max(data[,x1]) - min(data[,x1]) | ||
delta2 <- max(data[,x2]) - min(data[,x2]) | ||
sx1 <- sort(data[,x1]) | ||
sx2 <- sort(data[,x2]) | ||
dx1 <- diff(sx1) | ||
dx2 <- diff(sx2) | ||
minx1 <- min(dx1[dx1 > 0]) | ||
minx2 <- min(dx2[dx2 > 0]) | ||
arg11 <- sprintf("delta1 must be a real number much less than %s", delta1) | ||
arg12 <- sprintf("delta2 must be a real number much less than %s", delta2) | ||
arg21 <- sprintf("h1 must be a positive real number less than %s", minx1) | ||
arg22 <- sprintf("h2 must be a positive real number less than %s", minx2) | ||
lst <- list(delta1 = arg11, delta2 = arg12, h1 = arg21, h2 = arg22) | ||
return(lst) | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
skzs <- function(data, y, x1, x2, delta1, delta2, h1, h2, k=1, show.edges=FALSE, plot=TRUE) | ||
{ | ||
s1 <- diff(sort(data[,x1])) | ||
s2 <- diff(sort(data[,x2])) | ||
if (h1 >= min(s1[s1 > 0])) | ||
stop("Invalid 'h1': Value should be much less than the minimum difference of consecutive x1 values") | ||
if (h2 >= min(s2[s2 > 0])) | ||
stop("Invalid 'h2': Value should be much less than the minimum difference of consecutive x2 values") | ||
if (delta1 >= (max(data[,x1]) - min(data[,x1]))) | ||
stop("Invalid 'delta1': Value should be much less than the difference of the max and min x1 values") | ||
if (delta2 >= (max(data[,x2]) - min(data[,x2]))) | ||
stop("Invalid 'delta2': Value should be much less than the difference of the max and min x2 values") | ||
origx1 <- data[,x1] | ||
origx2 <- data[,x2] | ||
origy <- data[,y] | ||
x1range <- range(data[,x1]) | ||
x2range <- range(data[,x2]) | ||
d1 <- delta1/2 | ||
d2 <- delta2/2 | ||
for (i in 1:k) { | ||
data <- as.vector(data) | ||
maxx1 <- max(data[,x1]) | ||
minx1 <- min(data[,x1]) | ||
maxx2 <- max(data[,x2]) | ||
minx2 <- min(data[,x2]) | ||
yvals <- data[,y] | ||
xk1 <- seq(minx1 - d1, maxx1 + d1, h1) | ||
xk2 <- seq(minx2 - d2, maxx2 + d2, h2) | ||
xk <- expand.grid(xk1 = xk1, xk2 = xk2) | ||
zk <- array(NA, dim = c(nrow(xk),1)) | ||
for (j in 1:nrow(xk)) { | ||
w1 <- abs(data[,x1] - xk$xk1[j]) | ||
w1[w1 > d1] <- NA | ||
w2 <- abs(data[,x2] - xk$xk2[j]) | ||
w2[w2 > d2] <- NA | ||
Ik <- which(!(is.na(w1) | is.na(w2))) | ||
YIk <- yvals[Ik] | ||
zk[j] <- mean(YIk) | ||
} | ||
xk$zk <- zk | ||
data <- na.omit(xk) | ||
x1 <- 1 | ||
x2 <- 2 | ||
y <- 3 | ||
} | ||
if (show.edges == FALSE){ | ||
x1d <- data[data[,1] >= min(x1range) & data[,1] <= max(x1range), ] | ||
x2d <- x1d[(x1d[,2] >= min(x2range)) & (x1d[,2] <= max(x2range)), ] | ||
data <- na.omit(x2d) | ||
} | ||
if (plot == TRUE){ | ||
plot(wireframe(zk ~ xk1 * xk2, data,drape = TRUE, colorkey = TRUE, scales = list(arrows = FALSE))) | ||
} | ||
return(data) | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
\name{argkzs} | ||
\alias{argkzs} | ||
\title{ Argument Limits for KZS } | ||
\description{ | ||
This function calculates the value for which the arguments \code{delta} and \code{h} | ||
in the KZS function are bounded above or below by. | ||
} | ||
\usage{ | ||
argkzs(data, x) | ||
} | ||
\arguments{ | ||
\item{data}{ | ||
a data frame of paired values X and Y representing pairs (Xi, Yi ), i = 1,... ,n and | ||
X, Y are real values. This should be the data frame that is to be used with KZS. | ||
} | ||
\item{x}{ | ||
an integer specifying the position of the column in the data frame containing the one | ||
dimensional input variable, X, coordinates. | ||
} | ||
} | ||
\details{ | ||
In the KZS function, the argument \code{delta} is the physical range of smoothing in terms of | ||
unit values of X; the argument \code{h} is a scale reading of all outcomes of the algorithm. | ||
More specifically, \code{h} is the interval width of a uniform scale overlaying the X axis. | ||
The purpose of this function is to give an upper and/or lower bound on the values of \code{delta} | ||
and \code{h} so that users may select appropriate values that satisfy all restrictions. This | ||
function eliminates any guess-work involved in choosing a satisfying value for \code{delta} and | ||
\code{h} and should be used prior to KZS in order to save time and increase efficiency of use. | ||
} | ||
\value{ | ||
a list containing two elements: | ||
\item{delta }{the bounding value for the argument \code{delta}} | ||
\item{h }{the bounding value for the argument \code{h}} | ||
} | ||
\author{ Derek Cyr \email{cyr.derek@gmail.com} and Igor Zurbenko \email{igorg.zurbenko@gmail.com} } | ||
\seealso{ \code{\link{kzs}} } | ||
\examples{ | ||
#This example uses the same data from the KZS example | ||
|
||
# Define the time sequence | ||
t <- seq(from = -round(400*pi), to = round(400*pi), by = .25) | ||
|
||
# Positive t (includes time = 0) | ||
tp <- seq(from = 0, to = round(400*pi), by = .25) | ||
|
||
# Negative t | ||
tn <- seq(from = -round(400*pi), to = -.25, by = .25) | ||
|
||
# Positive side of signal | ||
signalp <- 0.5*sin(sqrt((2*pi*abs(tp))/200)) | ||
|
||
# Negative side of signal | ||
signaln <- 0.5*sin(-sqrt((2*pi*abs(tn))/200)) | ||
|
||
# Appending into one signal | ||
signal <- append(signaln, signalp, after = length(tn)) | ||
|
||
# Randomly generate noise from the standard normal distribution | ||
et <- rnorm(length(t), mean = 0, sd = 1) | ||
|
||
# Add the noise to the signal | ||
yt <- et + signal | ||
|
||
# Data frame of (t,yt) | ||
pts <- data.frame(cbind(t,yt)) | ||
|
||
argkzs(pts, 1) | ||
} | ||
\keyword{ smooth } | ||
\keyword{ nonparametric } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
\name{argskzs} | ||
\alias{argskzs} | ||
\title{ Argument Limits for SKZS } | ||
\description{ | ||
This function calculates the values for which the arguments \code{delta1}, | ||
\code{delta2} and \code{h1}, \code{h2} in SKZS are bounded above or below by. | ||
} | ||
\usage{ | ||
argskzs(data, x1, x2) | ||
} | ||
\arguments{ | ||
\item{data}{ | ||
a data frame to be used with SKZS. Only the columns corresponding the input variables | ||
X = (\code{x1}, \code{x2}) are needed; the column corresponding to the response variable is | ||
optional, but plays no part in the use of this function. | ||
} | ||
\item{x1}{ | ||
an integer specifying the position of the column in the data frame containing \code{x1} values. | ||
} | ||
\item{x2}{ | ||
an integer specifying the position of the column in the data frame containing \code{x2} values. | ||
} | ||
} | ||
\details{ | ||
In the SKZS function (similarly to the \code{\link{kzs}} function), the arguments \code{delta1} and | ||
\code{delta2} are the physical ranges of smoothing in terms of the unit values of the input variables | ||
\code{x1} and \code{x2}; the arguments \code{h1} and \code{h2} are scale readings of all outcomes of | ||
the algorithm; more specifically, \code{h1} and \code{h2} are values denoting the interval widths of | ||
two uniform scales overlapping the \code{x1} and \code{x2} axes. The restrictions on the arguments | ||
are the same as for the one dimensional input variable in KZS, only here, the restrictions are extended | ||
to the two-dimensional input variables \code{x1} and \code{x2}. The purpose of this function is to give | ||
an upper bound on the values \code{delta1, delta2} and \code{h1, h2} so that users may select appropriate | ||
values that satisfy all restrictions. This function eliminates any guess-work involved in choosing a | ||
satisfying value for the arguments and should be used prior to using SKZS in order to save time and | ||
increase efficiency of use. | ||
} | ||
\value{ | ||
a list containing the following: | ||
\item{delta1 }{the bounding value for the argument \code{delta1}} | ||
\item{delta2 }{the bounding value for the argument \code{delta2}} | ||
\item{h1 }{the bounding value for the argument \code{h1}} | ||
\item{h2 }{the bounding value for the argument \code{h2}} | ||
} | ||
\author{ Derek Cyr \email{cyr.derek@gmail.com} and Igor Zurbenko \email{igorg.zurbenko@gmail.com} } | ||
\seealso{ \code{\link{skzs}} } | ||
\examples{ | ||
### Recall the SKZS example of the Sinc function | ||
|
||
# Setup the data | ||
u <- seq(-3*pi, 3*pi, 3*pi/100) | ||
v <- u | ||
x1 <- sample(u, size = 4000, replace = TRUE) | ||
x2 <- sample(v, size = 4000, replace = TRUE) | ||
d <- data.frame(cbind(x1,x2)) | ||
df <- unique(d) | ||
df$z <- sin(sqrt(df$x1^2 + df$x2^2)) / sqrt(df$x1^2 + df$x2^2) | ||
df$z[is.na(df$z)] <- 1 | ||
|
||
# Return the bounding values for each argument | ||
argskzs(df, 1, 2) | ||
} | ||
\keyword{ smooth } | ||
\keyword{ nonparametric } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.