predict.dglars: Predict Method for dgLARS Fits.

View source: R/predict.dglars.R

predict.dglarsR Documentation

Predict Method for dgLARS Fits.

Description

predict.dglars is used to obtain general predictions from a dglars object.

Usage

## S3 method for class 'dglars'
predict(object, xnew, ynew, g = NULL, 
type = c("coefficients", "nnonzero", "predictors", "eta", 
"mu", "probability", "class", "deviance"), ...)

Arguments

object

fitted dglars object.

xnew

matrix of new values of the predictors at which predictions are to be made. This argument is not used for typecoefficients”, “nnonzero” and “predictors”.

ynew

vector of new values of the responce variable. This argument is used only when type ie equal to “deviance”.

g

value(s) of the tuning parameter \gamma at which the predictions are required. By default, the predictions are made using the sequence of \gamma values storaged in dglars.

type

type of prediction required; see below for more details.

...

additional argument used to ensure the compatibility with the generic method function “predict”.

Value

The object returned by predict.dglars depends on type argument:

coefficients:

a named list with components “beta”, i.e., the matrix corresponding to the dgLARS solution curve, and “phi”, i.e., the sequence of Pearson estimates of the dispersion parameter;

nnonzero:

the number of nonzero estimates;

predictors:

a named list; each component is a vector containing the indices of the variables that are in the active set;

eta:

a matrix with the linear preditors. If xnew is not specified then the linear predictors are computed using object$X;

mu:

a matrix with the fitted expeted values, obtained by transforming the linear predictor by the inverse of the link function. For models with ‘binomial’ family, canonical link function (‘logit’) and response a vector with elements 0 (failure) or 1 (success), type = "mu" and type = "probability" give the same result. If xnew is not spefified then these values are computed using object$X;

probability:

available only for ‘binomial’ family. In this case predict.dglars returns a matrix with the fitted probabilities; furthermore, if the model is specified by using the canonical link function (‘logit’) and response a vector with entries 0/1, type = "mu" and type = "probability" give the same result. If xnew is not specified then these values are computed using object$X;

class:

available only for ‘binomial’ family. In this case predict.dglars returns a matrix with the fitted class. If xnew is not specified then these values are computed using object$X otherwise xnew is used to compute the fitted probabilities;

deviance:

a vector with the scaled residual deviances.

Author(s)

Luigi Augugliaro
Maintainer: Luigi Augugliaro luigi.augugliaro@unipa.it

See Also

dglars and coef.dglars.

Examples

######################
# Logistic regression model
set.seed(123)
n <- 100
p <- 10
X <- matrix(rnorm(n * p), n, p)
Xnew <- matrix(rnorm(n * p), n, p)
b <- 1:2
eta <- b[1] + X[, 1] * b[2]
mu <- binomial()$linkinv(eta)
y <- rbinom(n, 1, mu)
fit <- dglars.fit(X, y, binomial)
coef(fit)
predict(fit, type = "coefficients")
g <- seq(3, 1, by = -0.1)
coef(fit, g = g)
predict(fit, type = "coefficients", g = g)
predict(fit, type = "nnonzero")
predict(fit, type = "nnonzero", g = g)
predict(fit, type = "predictors")
predict(fit, type = "predictors", g = g)
predict(fit, type = "eta", g = g)
predict(fit, type = "eta", g = g, xnew = Xnew)
predict(fit, type = "mu", g = g)
predict(fit, type = "mu", g = g, xnew = Xnew)
predict(fit, type = "probability", g = g)
predict(fit, type = "probability", g = g, xnew = Xnew)
predict(fit, type = "class", g = g)
predict(fit, type = "class", g = g, xnew = Xnew)

dglars documentation built on Oct. 10, 2023, 1:08 a.m.