Learn R Programming

SGPR (version 0.1.2)

predict.sgp: Predictions based on a SGP model

Description

A function that extracts information from a SGP object and performs predictions.

Usage

# S3 method for sgp
predict(
  object,
  X = NULL,
  extract = c("link", "response", "class", "coef", "vars", "groups", "nvars", "ngroups",
    "norm"),
  lambda,
  index = 1:length(object$lambda),
  ...
)

Value

Different objects depending on the sting indicated by 'extract'.

Arguments

object

A object that was generated with sgp.

X

The design matrix for making predictions.

extract

A string indicating the type of information to return.

lambda

The value of lambda at which predictions should be made.

index

The index that indicates the lambda at which predictions should be made (alternative to specifying 'lambda').

...

Other parameters of underlying basic functions.

Examples

Run this code
n <- 100
p <- 12
nr <- 4
g <- paste0("Group ",ceiling(1:p / nr))
X <- matrix(rnorm(n * p), n, p)
b <- c(-3:3)
y_lin <- X[, 1:length(b)] %*% b + 5 * rnorm(n)
y_log <- rbinom(n, 1, exp(y_lin) / (1 + exp(y_lin)))

lin_fit <- sgp(X, y_lin, g, type = "linear")
predict(lin_fit, X = X, extract = "nvars")

log_fit <- sgp(X, y_log, g, type = "logit")
predict(log_fit, X = X, extract = "nvars")

Run the code above in your browser using DataLab