penAFT.predict: Obtain linear predictor for new subjects using fitted model...

View source: R/penAFT.aux.R

penAFT.predictR Documentation

Obtain linear predictor for new subjects using fitted model from penAFT or penAFT.cv

Description

A function for prediction along the solution path of the regularized semiparametric accelerated failure time model estimator.

Usage

penAFT.predict(fit, Xnew, lambda = NULL)

Arguments

fit

A fitted model from penAFT or penAFT.cv.

Xnew

A matrix of dimension n_{\rm new} \times p. Must be a matrix, even if n_{\rm new}= 1.

lambda

The value of \lambda used to estimate \beta. If NULL and fit was obtained using nfolds non-NULL, the function will use the tuning parameter which minimized cross-validation linear predictor scores.

Details

It is important to note that the output of this function should not be treated as an estimate of the log-survival time. Because the Gehan loss function is location invariant, the intercept is absored into the error. If predictors were standardized for model fitting, this function returns \tilde{X}_{\rm new}\hat{\beta} where \tilde{X}_{\rm new} is the version of input Xnew which has been centered and standardized according to the design matrix used to fit the penAFT or penAFT.cv object. If predictors were not standardized, this function returns X_{\rm new}\hat{\beta}.

We recommend input Xnew as a matrix, although if a p-dimensional vector is input, the function will detect this.

Value

preds

The matrix of linear predictors: rows correspond to rows of Xnew.

Examples

# --------------------------------------
# Generate data  
# --------------------------------------
set.seed(1)
genData <- genSurvData(n = 50, p = 50, s = 10, mag = 2, cens.quant = 0.6)
X <- genData$X
logY <- genData$logY
delta <- genData$status

# --- generate data for two new subjects
p <- dim(X)[2]
Xnew <- rbind(rnorm(p), rnorm(p))

# -----------------------------------------------
# Fit elastic net penalized estimator without CV
# -----------------------------------------------
fit <- penAFT(X = X, logY = logY, delta = delta,
                   nlambda = 10, lambda.ratio.min = 0.1,
                   penalty = "EN",
                   alpha = 1)

# predict at 10th candidate tuning parameter
linPred.10 <- penAFT.predict(fit, Xnew = Xnew, lambda = fit$lambda[10])


  # ------------------------------------------
  # Fit elastic net penalized estimator with CV
  # -------------------------------------------
  fit.cv <- penAFT.cv(X = X, logY = logY, delta = delta,
                    nlambda = 50,
                    penalty = "EN",
                     alpha = 1, nfolds = 5)
  
  # --- return linear predictor at lambda minimizing cross-validation error 
  linPred.cv <- penAFT.predict(fit.cv, Xnew = Xnew) 
  
  # --- predict at 10th candidate tuning parameter
  linPred.cv10 <- penAFT.predict(fit.cv, Xnew = Xnew, lambda = fit.cv$full.fit$lambda[10]) 
  
  
  # ------------------------------------------
  # Fit penAFT with cross-validation
  # -------------------------------------------
  groups <- rep(1:5, each = 10)
  fit.sg.cv <- penAFT.cv(X = X, logY = logY, delta = delta,
                    nlambda = 50, groups = groups,
                    penalty = "SG",
                    alpha = 0.5, nfolds = 5)
  
  # ---- return linear predictor at lambda minimizing cross-validation error 
  linPred.sg.cv <- penAFT.predict(fit.sg.cv, Xnew = Xnew) 
  
  # --- predict at 10th candidate tuning parameter
  linPred.sg.cv10 <- penAFT.predict(fit.sg.cv, Xnew = Xnew, lambda = fit.sg.cv$full.fit$lambda[10]) 




penAFT documentation built on April 18, 2023, 9:10 a.m.