ps2DNormal: Two-dimensional smoothing scattered (normal) data using...

View source: R/ps2DNormal.R

ps2DNormalR Documentation

Two-dimensional smoothing scattered (normal) data using P-splines.

Description

ps2DNormal is used to smooth scattered (normal) data, with aniosotripic penalization of tensor product P-splines.

Usage

ps2DNormal(
  Data,
  Pars = rbind(c(min(Data[, 1]), max(Data[, 1]), 10, 3, 1, 2), c(min(Data[, 2]),
    max(Data[, 2]), 10, 3, 1, 2)),
  XYpred = expand.grid(Data[, 1], Data[, 2])
)

Arguments

Data

a matrix of 3 columns x, y, z of equal length; the response is z.

Pars

a matrix of 2 rows, where the first and second row sets the P-spline paramters for x and y, respectively. Each row consists of: min max nseg bdeg lambda pord. The min and max set the ranges, nseg (default 10) is the number of evenly spaced segments between min and max, bdeg is the degree of the basis (default 3 for cubic), lambda is the (positive) tuning parameter for the penalty (default 1), pord is the number for the order of the difference penalty (default 2),

XYpred

a matrix with two columns (x,y) that give the coordinates of (future) prediction; the default is the data locations.

Details

Support functions needed: pspline_fitter, bbase, and pspline_2dchecker.

Value

coef

a vector of length (Pars[1,3]+Pars[1,4])*(Pars[2,3]+Pars[2,4]) of (unfolded) estimated P-spline coefficients.

fit

a vector of length(y) of smooth estimated means (at the x,y locations).

pred

a vector of length nrow(XYpred) of (future) predictions.

Pars

the design and tuning parameters (see arguments above).

cv

leave-one-out standard error of prediction or root average PRESS.

h

"hat" diagonals of tensor P-spline fit.

B

tensor product B-spline basis used for fitting.

Author(s)

Paul Eilers and Brian Marx

References

Eilers, P.H.C. and Marx, B.D. (2021). Practical Smoothing, The Joys of P-splines. Cambridge University Press.

Eilers, P.H.C., Marx, B.D., and Durban, M. (2015). Twenty years of P-splines, SORT, 39(2): 149-186.

See Also

ps2DGLM

Examples

library(SemiPar)
library(fields)
library(spam)
library(JOPS)

# Get the data
data(ethanol)
x <- ethanol$C
y <- ethanol$E
z <- ethanol$NOx

# Set parameters for domain
xlo <- 7
xhi <- 19
ylo <- 0.5
yhi <- 1.25

# Set P-spline parameters, fit and compute surface
xpars <- c(xlo, xhi, 10, 3, 3, 1)
ypars <- c(ylo, yhi, 10, 3, 3, 1)
Pars1 <- rbind(xpars, ypars)
fit <- ps2DNormal(cbind(x, y, z), Pars = Pars1)
plot(fit, xlab = "C", ylab = "E")

JOPS documentation built on Sept. 8, 2023, 5:42 p.m.

Related to ps2DNormal in JOPS...