Prediction method for Orthogonalizing EM fitted objects

# S3 method for oem
predict(
  object,
  newx,
  s = NULL,
  which.model = 1,
  type = c("link", "response", "coefficients", "nonzero", "class"),
  ...
)

Arguments

object

fitted "oem" model object

newx

Matrix of new values for x at which predictions are to be made. Must be a matrix; can be sparse as in the CsparseMatrix objects of the Matrix package. This argument is not used for type=c("coefficients","nonzero")

s

Value(s) of the penalty parameter lambda at which predictions are required. Default is the entire sequence used to create the model.

which.model

If multiple penalties are fit and returned in the same oem object, the which.model argument is used to specify which model to make predictions for. For example, if the oem object oemobj was fit with argument penalty = c("lasso", "grp.lasso"), then which.model = 2 provides predictions for the group lasso model.

type

Type of prediction required. type = "link" gives the linear predictors for the "binomial" model; for "gaussian" models it gives the fitted values. type = "response" gives the fitted probabilities for "binomial". type = "coefficients" computes the coefficients at the requested values for s. type = "class" applies only to "binomial" and produces the class label corresponding to the maximum probability.

...

not used

Value

An object depending on the type argument

Examples

set.seed(123) n.obs <- 1e4 n.vars <- 100 n.obs.test <- 1e3 true.beta <- c(runif(15, -0.5, 0.5), rep(0, n.vars - 15)) x <- matrix(rnorm(n.obs * n.vars), n.obs, n.vars) y <- rnorm(n.obs, sd = 3) + x %*% true.beta x.test <- matrix(rnorm(n.obs.test * n.vars), n.obs.test, n.vars) y.test <- rnorm(n.obs.test, sd = 3) + x.test %*% true.beta fit <- oem(x = x, y = y, penalty = c("lasso", "grp.lasso"), groups = rep(1:10, each = 10), nlambda = 10) preds.lasso <- predict(fit, newx = x.test, type = "response", which.model = 1) preds.grp.lasso <- predict(fit, newx = x.test, type = "response", which.model = 2) apply(preds.lasso, 2, function(x) mean((y.test - x) ^ 2))
#> [1] 10.206086 9.305604 9.114948 9.099376 9.122277 9.142751 9.150690 #> [8] 9.153957 9.155163 9.155600
apply(preds.grp.lasso, 2, function(x) mean((y.test - x) ^ 2))
#> [1] 10.206086 9.594635 9.141101 9.091859 9.119994 9.141259 9.150381 #> [8] 9.153852 9.155125 9.155586