psNormal: Smoothing scattered (normal) data using P-splines.

View source: R/psNormal.R

psNormalR Documentation

Smoothing scattered (normal) data using P-splines.

Description

psNormal is used to smooth scattered (normal) data using P-splines (with identity link function).

Usage

psNormal(
  x,
  y,
  xl = min(x),
  xr = max(x),
  nseg = 10,
  bdeg = 3,
  pord = 2,
  lambda = 1,
  wts = NULL,
  xgrid = 100
)

Arguments

x

the vector for the continuous regressor of length(y) and the abcissae used to build the B-spline basis.

y

the response vector, usually continuous data.

xl

the number for the min along x (default is min(x)) .

xr

the number for the max along x (default is max(x)).

nseg

the number of evenly spaced segments between xl and xr.

bdeg

the number of the degree of the basis, usually 1, 2 (default), or 3.

pord

the number of the order of the difference penalty, usually 1, 2, or 3 (defalult).

lambda

the (positive) number for the tuning parameter for the penalty (default 1).

wts

the vector of general weights, default is 1; zero allowed.

xgrid

a scalar or a vector that gives the x locations for prediction, useful for plotting. If a scalar (default 100) is used then a uniform grid of this size along (xl, xr).

Value

pcoeff

a vector of length n of estimated P-spline coefficients.

muhat

a vector of length m of smooth estimated means.

B

a matrix of dimension m by n for the B-spline basis matrix.

wts

a vector of length m of weights.

effdim

estimated effective dimension.

ed_resid

approximate df residual.

sigma

square root of MSE.

cv

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

nseg

the number of B-spline segments.

bdeg

the degree of the B-spline basis.

pord

the order of the difference penalty.

lambda

the positive tuning parameter.

xgrid

gridded x values, useful for plotting.

ygrid

gridded fitted mean values, useful for plotting.

se_eta

gridded standard errors for the fitted mean values, useful for plotting.

P

"half" of the penalty, such that P'P= lambda D'D.

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.

Examples

library(JOPS)
library(MASS)
data(mcycle)
x <- mcycle$times
y <- mcycle$accel
fit1 <- psNormal(x, y, nseg = 20, bdeg = 3, pord = 2, lambda = .8)
plot(fit1, se = 2, xlab = "Time (ms)", ylab = "Acceleration")

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

Related to psNormal in JOPS...