predict.asgl: Make predictions from an 'asgl' object

Description Usage Arguments Value Examples

View source: R/predict.R

Description

Makes predictions from a fitted 'asgl' object.

Usage

1
2
3
## S3 method for class 'asgl'
predict(object, newx, s = NULL, type = c("link",
  "response"), ...)

Arguments

object

Fitted asgl object

newx

Matrix of new values for x at which predictions are to be made.

s

Value(s) of the penalty tuning parameter at which predictions are to be made. Default is the entire sequence used to fit the regularization path.

type

Type of predicted required. For "gaussian" models, "link" and "response" give the same result: the predicted response. For "binomial" models, "link" gives the linear predictor and "response" gives the predicted probabilities.

...

Ignored.

Value

A matrix of predictions or, if s is of length 1, a vector of predictions.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
# linear regression
n <- 500; p <- 20; groupsize <- 5
index <- ceiling(1:p / groupsize)
beta <- (-2:2)
x <- matrix(rnorm(n * p), ncol = p, nrow = n)
y <- as.vector(x[,1:5] %*% beta + 0.1 * rnorm(n))
fit1 <- asgl(x, y, index, family = "gaussian")
predict(fit1, x)

# logistic regression
eta <- x[, 1:5] %*% beta
prob <- exp(eta) / (1 + exp(eta))
y <- rbinom(n, 1, prob)
fit2 <- asgl(x, y, index, family = "binomial")
predict(fit2, x, s = fit2$lambda[20], type = "response")

jeffdaniel/asgl documentation built on Nov. 4, 2019, 2:37 p.m.