ps2DGLM: Two-dimensional smoothing of scattered normal or non-normal...

ps2DGLMR Documentation

Two-dimensional smoothing of scattered normal or non-normal (GLM) responses using tensor product P-splines.

Description

ps2DGLM is used to smooth scattered normal or non-normal responses, with aniosotripic penalization of tensor product P-splines.

Usage

ps2DGLM(
  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)),
  ridge_adj = 0,
  XYpred = Data[, 1:2],
  z_predicted = NULL,
  se_pred = 2,
  family = "gaussian",
  link = "default",
  m_binomial = rep(1, nrow(Data)),
  wts = rep(1, nrow(Data)),
  r_gamma = rep(1, nrow(Data))
)

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).

ridge_adj

a ridge penalty tuning parameter, usually set to small value, e.g. 1e-8 to stabilize estimation (default 0).

XYpred

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

z_predicted

a vector of responses associated with XYpred, useful for external validation with family = "gaussian".

se_pred

a scalar, default se_pred = 2 to produce se surfaces, set se_pred > 0. Used for CIs for XYpred locations.

family

"gaussian", "binomial", "poisson", "Gamma" (quotes needed). Default is "gaussian".

link

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

m_binomial

vector of binomial trials, default is vector of ones with family = "binomial", NULL otherwise.

wts

non-negative weights, which can be zero (default ones).

r_gamma

gamma scale parameter, default is vector ones with family = "Gamma", NULL otherwise.

Details

Support functions needed: pspline_fitter, bbase, and pspline_2dchecker.

Value

pcoef

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

mu

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

dev

the deviance of fit.

eff_df

the approximate effective dimension of fit.

aic

AIC.

df_resid

approximate df residual.

cv

leave-one-out standard error prediction, when family = 'gaussian'.

cv_predicted

standard error prediction for y_predict, when family = 'gaussian'.

avediff_pred

mean absolute difference prediction, when family = 'gaussian'.

Pars

the design and tuning parameters (see arguments above).

dispersion_parm

estimate of dispersion, dev/df_resid.

summary_predicted

inverse link prediction vectors, and se_pred bands.

eta_predicted

estimated linear predictor of length(z).

press_mu

leave-one-out prediction of mean, when family = 'gaussian'.

bin_percent_correct

percent correct classification based on 0.5 cut-off (when family = "binomial").

Data

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

Q

the tensor product B-spline basis.

qr

the Q-R of the model.

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

ps2DNormal

Examples

library(fields)
library(JOPS)
# Extract data
library(rpart)
Kyphosis <- kyphosis$Kyphosis
Age <- kyphosis$Age
Start <- kyphosis$Start
y <- 1 * (Kyphosis == "present") # make y 0/1
fit <- ps2DGLM(
  Data = cbind(Start, Age, y),
  Pars = rbind(c(1, 18, 10, 3, .1, 2), c(1, 206, 10, 3, .1, 2)),
  family = "binomial", link = "logit")
plot(fit, xlab = "Start", ylab = "Age")
#title(main = "Probability of Kyphosis")

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

Related to ps2DGLM in JOPS...