https://github.com/cran/spatstat
Raw File
Tip revision: 3aca716ce2576a0dab83f08052acd47afed8ee6a authored by Adrian Baddeley on 29 February 2012, 00:00:00 UTC
version 1.25-4
Tip revision: 3aca716
smoothfv.R
#
#  smoothfv.R
#
#   $Revision: 1.4 $   $Date: 2010/04/16 12:47:43 $
#
  
smooth.fv <- function(x, which="*", ...) {
  stopifnot(is.character(which))
  if(length(which) == 1 && which %in% .Spatstat.FvAbbrev) {
    if(which == ".x")
      stop("Cannot smooth the function argument")
    which <- fvnames(x, which)
  }
  if(any(nbg <- !(which %in% names(x)))) 
    stop(paste("Unrecognised column",
               ngettext(sum(nbg), "name", "names"),
               commasep(sQuote(which[nbg])), 
               "in argument", sQuote("which")))
  xx <- x[[fvnames(x, ".x")]]
  for(ynam in which) {
    yy <- x[[ynam]]
    ok <- is.finite(yy)
    ss <- smooth.spline(xx[ok], yy[ok], ...)
    yhat <- predict(ss, xx)$y
    x[[ynam]] <- yhat
  }
  return(x)
}
back to top