Learn R Programming

pense (version 1.2.1)

predict.pense: Predict Method for Penalized Elastic Net S- and MM-estimators

Description

Predict Method for Penalized Elastic Net S- and MM-estimators

Usage

# S3 method for pense
predict(object, newdata, lambda, exact = FALSE,
  correction = TRUE, ...)

Arguments

object

an object of type pense or pensem to use for prediction.

newdata

an optional design matrix

lambda

the value of the penalty parameter. Default is to use the optimal lambda lambda_opt.

exact

if the lambda is not part of the lambda grid, should the estimates be obtained by linear interpolation between the nearest lambda values (default) or computed exactly.

correction

should a correction factor be applied to the PENSE(M) estimate?

...

currently ignored.

Value

a numeric vector of predicted values for the given lambda.

Examples

Run this code
# NOT RUN {
# Generate data with highly correlated groups of variables and some outliers
set.seed(12345)
n <- 50
n_out <- 3
p <- 20
x <- 1 + matrix(rnorm(n * p), ncol = p)
x[, 2] <- x[, 1] + rnorm(n, sd = 0.01)
x[, 3] <- x[, 1] + rnorm(n, sd = 0.01)
x[, 5] <- x[, 4] + rnorm(n, sd = 0.01)
x[, 6] <- x[, 4] + rnorm(n, sd = 0.01)

y <- x %*% c(rep(c(2, 5), each = 3), numeric(p - 6)) + rnorm(n)

y[seq_len(n_out)] <- rnorm(n_out, -100, sd = 3)

# Compute the PENSE estimator
set.seed(1234)
est_en <- pense(x, y, alpha = 0.5, warm_reset = 1, cv_k = 3)

# From the fitted model we can extract the coefficients, fitted values, and
# residuals at the "optimal" lambda as chosen by CV.
coef(est_en) # Extract coefficients
predict(est_en) # Extract fitted values
predict(est_en, newdata = x) # Predict values
residuals(est_en) # Extract residuals

# We can also request the coefficients/predicitons/residuals at another lambda.
# If the requested lambda is not in the original lambda grid, the methods
# will approximate the coefficient vector by linear interpolation of
# the solutions at the surrounding lambda values.
coef(est_en, lambda = 5)

# If the exact solution is needed, this can be requested
coef(est_en, lambda = 5, exact = TRUE)
residuals(est_en, lambda = 5, exact = TRUE)
# }

Run the code above in your browser using DataLab