R/transformseries.loess.R

Defines functions transformseries.loess

Documented in transformseries.loess

#' loess transformation
#'
#' @keywords internal
transformseries.loess <- function(i.x, i.positive = F, ...) {
  i.x[is.nan(i.x)] <- NA
  i.x[is.infinite(i.x)] <- NA
  xy.data <- data.frame(dx = 1:length(i.x), dy = i.x)
  if (all(is.na(xy.data$dy))) {
    xt <- xy.data$dy
  } else {
    loessMod <- try(loess(dy ~ dx, data = xy.data, ...), silent = T)
    res <- try(predict(loessMod, newdata = xy.data$dx), silent = T)
    if ("try-error" %in% class(loessMod) | "try-error" %in% class(res)) {
      xt <- xy.data$dy
    } else {
      if (i.positive) res[res < 0] <- 0
      xt <- res
    }
  }
  return(xt)
}

Try the mem package in your browser

Any scripts or data that you put into this service are public.

mem documentation built on July 9, 2023, 6:34 p.m.