lokern (version 1.1-8.1)

KernS-methods: Methods for ("KernS" classed) Results of lokerns() and glkerns()

Description

Methods for results of glkerns() and lokerns() which are of (S3) class "KernS".

Usage

# S3 method for KernS
fitted(object, …)
# S3 method for KernS
plot(x, type = "l", lwd = 2.5, col = 3, …)
# S3 method for KernS
predict(object, x, deriv = object[["deriv"]],
        korder = deriv+2, trace.lev = 0, …)
# S3 method for KernS
print(x, digits = getOption("digits"), …)
# S3 method for KernS
residuals(object, …)

Arguments

x,object

an R object, of S3 class "KernS", typically result either from glkerns() or lokerns().

type, lwd, col

arguments for plot() only for the case when x$deriv is not 0.

deriv

integer, \(\ge 0\), specifiying order of derivative that should be predicted.

korder

nonnegative integer giving the kernel order; see lokerns or glkerns.

digits

number of significant digits, see print.

trace.lev

integer; level of tracing of Fortran level computations; see lokerns.

potentially further arguments passed to and from methods. For the plot(*, deriv=0) method, these are passed to plotDS from package sfsmisc.

Value

(differing, depending on the generic function)

Details

Note that fitted() and residuals() rely on x.inOut having been true or x.out having contained the data x, in the lokerns or glkerns call.

The plot() method calls plotDS from package sfsmisc.

predict(object, x, deriv) when either some x are not in x.out or deriv is not 0, basically recalls the original lokerns or glkerns function (keeping the bandwidths for lokerns).

See Also

glkerns, lokerns.

Examples

Run this code
# NOT RUN {
## "interesting" artificial data:
set.seed(47)
x <- sort(round(10*runif(250),2))
fx <- 5 - x/2 + 3*exp(-(x-5)^2)
y <- fx + rnorm(fx)/4
plot(x,y)
lof <- lokerns(x,y, trace=1)# tracing the phases inside the Fortran code
plot(lof)
plot(lof, cex = 1/4)# maybe preferable
## Simpler, using the lines() method:
plot(x,y); lines(lof, lwd=2, col=2)

qqnorm(residuals(lof)) # hmm... overfitting?
stopifnot(all.equal(y, fitted(lof) + residuals(lof), tolerance = 1e-15),
          predict(lof)$y == fitted(lof))
lof$iter # negative ?
tt <- seq(0, 10, by=1/32)
p0 <- predict(lof, x=tt)
p1 <- predict(lof, x=tt, deriv=1)
p2 <- predict(lof, x=tt, deriv=2)
plot(p2, type="l"); abline(h=0, lty=3) # not satisfactory:
lof2 <- lokerns(x,y, deriv=2)
plot(lof2, main=
   "lokerns(*, deriv=2) -- much more smooth than predict(*,deriv=2)")
lines(p2); abline(h=0, lty=3)
# }

Run the code above in your browser using DataLab