psVCSignal: Varying-coefficient penalized signal regression using...

psVCSignalR Documentation

Varying-coefficient penalized signal regression using P-splines.

Description

psVCSignal is used to regress a (glm) response onto a signal such that the signal coefficients can vary over another covariate t. Anisotripic penalization of tensor product B-splines produces a 2D coefficient surface that can be sliced at t.

@details Support functions needed: pspline_fitter, pspline_2dchecker, and bbase.

@import stats

Usage

psVCSignal(
  y,
  X,
  x_index,
  t_var,
  Pars = rbind(c(min(x_index), max(x_index), 10, 3, 1, 2), c(min(t_var), max(t_var), 10,
    3, 1, 2)),
  family = "gaussian",
  link = "default",
  m_binomial = 1 + 0 * y,
  wts = 1 + 0 * y,
  r_gamma = 1 + 0 * y,
  X_pred = X,
  t_pred = t_var,
  y_predicted = NULL,
  ridge_adj = 1e-08,
  int = TRUE
)

Arguments

y

a glm response vector of length m, usually continuous, binary/bimomial or counts.

X

a m by p1 Signal matrix of regressors.

x_index

p1-vector for index of Signal (e.g. wavelength).

t_var

p2-vector with other (indexing) variable in coefficient surface (e.g. temperature, depth, time).

Pars

a matrix with 2 rows, each with P-spline parameters: min max nseg bdeg lambda pord, for row and columns of tensor product surface; defaults are min and max for x_index and t_var (resp.), nseg = 10, bdeg =3, lambda = 1, pord = 2.

family

the response distribution, e.g. "gaussian", "binomial", "poisson", "Gamma" distribution; quotes are needed (default "gaussian".

link

the link function, one of "identity", "log", "sqrt", "logit", "probit", "cloglog", "loglog", "reciprocal"); quotes are needed (default "identity".

m_binomial

a vector of binomial trials having length(y). Default is 1 vector for family = "binomial", NULL otherwise.

wts

a m vector of weights (default 1).

r_gamma

a vector of gamma shape parameters. Default is 1 vector for family = "Gamma", NULL otherwise.

X_pred

a matrix of signals with ncol(X) columns for prediction, default is X.

t_pred

a vector for the VC indexing variable with length nrow(X_pred), default is t_var.

y_predicted

a vector for the responses associated with X_pred with length nrow(X_pred) useful for CV when family = "binomial", default is NULL.

ridge_adj

a small ridge penalty tuning parameter to regularize estimation (default 1e-8).

int

intercept set to TRUE or FALSE for intercept term.

Value

pcoef

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

summary_predicted

inverse link prediction vectors, and twice se bands.

dev

the deviance of fit.

eff_dim

the approximate effective dimension of fit.

family

the family of the response.

link

the link function.

aic

AIC.

df_resid

approximate df residual.

cv

leave-one-out standard error prediction when family = "gaussian", NULL otherwise.

cv_predicted

standard error prediction for y_predict when family = "gaussian", NULL otherwise.

Pars

design and tuning parameters; see arguments above.

dispersion_parm

estimate of dispersion, Dev/df_resid.

summary_predicted

inverse link prediction vectors, and twice se bands.

eta_predicted

estimated linear predictor of length(y).

press_mu

leave-one-out prediction of mean when family = "gaussian", NULL otherwise.

bin_percent_correct

percent correct classification based on 0.5 cut-off when family = "binomial", NULL otherwise.

Bx

B-spline basis matrix of dimension p1 by n1, along x_index.

By

B-spline basis matrix of dimension p2 by n2, along t_var.

Q

Modified tensor basis (m by (n1*n2)) for VC signal regression.

yint

the estimated y-intercept (when int = TRUE.)

int

a logical variable related to use of y-intercept in model.

Author(s)

Paul Eilers and Brian Marx

References

Eilers, P.H.C. and Marx, B.D. (2003). Multivariate calibration with temperature interaction using two-dimensional penalized signal regression. Chemometrics and Intellegent Laboratory Systems, 66, 159–174.

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

Examples

library(fds)
data(nirc)
iindex <- nirc$x
X <- nirc$y
sel <- 50:650 # 1200 <= x & x<= 2400
X <- X[sel, ]
iindex <- iindex[sel]
dX <- diff(X)
diindex <- iindex[-1]
y <- as.vector(labc[1, 1:40]) # percent fat
t_var <- as.vector(labc[4, 1:40]) # percent flour
oout <- 23
dX <- t(dX[, -oout])
y <- y[-oout]
t_var = t_var[-oout]
Pars = rbind(c(min(diindex), max(diindex), 25, 3, 1e-7, 2),
c(min(t_var), max(t_var), 20, 3, 0.0001, 2))
fit1 <- psVCSignal(y, dX, diindex, t_var, Pars = Pars,
family = "gaussian", link = "identity", int = TRUE)
plot(fit1, xlab = "Coefficient Index", ylab = "VC: % Flour")
names(fit1)

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

Related to psVCSignal in JOPS...