https://github.com/cran/spatstat
Raw File
Tip revision: 3c2c3f44ed5d0545db59719ef4387255fce494d5 authored by Adrian Baddeley on 12 August 2011, 14:30:54 UTC
version 1.23-3
Tip revision: 3c2c3f4
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