predict.PCLasso2: Make predictions from a PCLasso2 model

Description Usage Arguments Details Value See Also Examples

View source: R/predict.R

Description

Similar to other predict methods, this function returns predictions from a fitted PCLasso2 object.

Usage

1
2
3
4
5
6
7
8
9
## S3 method for class 'PCLasso2'
predict(
  object,
  x = NULL,
  type = c("link", "response", "class", "norm", "coefficients", "vars", "nvars",
    "vars.unique", "nvars.unique", "groups", "ngroups"),
  lambda,
  ...
)

Arguments

object

Fitted PCLasso2 model object.

x

Matrix of values at which predictions are to be made. The features (genes/proteins) contained in x should be consistent with those contained in x in the PCLasso2 function. Not used for type="coefficients" or for some of the type settings in predict.

type

Type of prediction: "link" returns the linear predictors; "response" gives the risk (i.e., exp(link)); "class" returns the binomial outcome with the highest probability; "vars" returns the indices for the nonzero coefficients; "vars.unique" returns unique features (genes/proteins) with nonzero coefficients (If a feature belongs to multiple groups and multiple groups are selected, the feature will be repeatedly selected. Compared with "var", "var.unique" will filter out repeated features.); "groups" returns the groups with at least one nonzero coefficient; "nvars" returns the number of nonzero coefficients; "nvars.unique" returns the number of unique features (genes/proteins) with nonzero coefficients; "ngroups" returns the number of groups with at least one nonzero coefficient; "norm" returns the L2 norm of the coefficients in each group.

lambda

Values of the regularization parameter lambda at which predictions are requested. For values of lambda not in the sequence of fitted models, linear interpolation is used.

...

Arguments to be passed to predict.grpreg in the R package grpreg.

Details

See predict.grpreg in the R package grpreg for details.

Value

The object returned depends on type.

See Also

PCLasso2

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# load data
data(classData)
data(PCGroups)

x <- classData$Exp
y <- classData$Label
PC.Human <- getPCGroups(Groups = PCGroups, Organism = "Human",
Type = "GeneSymbol")

set.seed(20150122)
idx.train <- sample(nrow(x), round(nrow(x)*2/3))
x.train <- x[idx.train,]
y.train <- y[idx.train]
x.test <- x[-idx.train,]
y.test <- y[-idx.train]

# fit PCLasso2 model
fit.PCLasso2 <- PCLasso2(x = x.train, y = y.train, group = PC.Human,
                  penalty = "grLasso", family = "binomial")

# predict risk scores of samples in x.test
s <- predict(object = fit.PCLasso2, x = x.test, type="link",
lambda=fit.PCLasso2$fit$lambda)

# predict classes of samples in x.test
s <- predict(object = fit.PCLasso2, x = x.test, type="class",
lambda=fit.PCLasso2$fit$lambda[10])

# Nonzero coefficients
sel.groups <- predict(object = fit.PCLasso2, type="groups",
                      lambda = fit.PCLasso2$fit$lambda)
sel.ngroups <- predict(object = fit.PCLasso2, type="ngroups",
                       lambda = fit.PCLasso2$fit$lambda)
sel.vars.unique <- predict(object = fit.PCLasso2, type="vars.unique",
                          lambda = fit.PCLasso2$fit$lambda)
sel.nvars.unique <- predict(object = fit.PCLasso2, type="nvars.unique",
                            lambda = fit.PCLasso2$fit$lambda)
sel.vars <- predict(object = fit.PCLasso2, type="vars",
                    lambda=fit.PCLasso2$fit$lambda)
sel.nvars <- predict(object = fit.PCLasso2, type="nvars",
                     lambda=fit.PCLasso2$fit$lambda)

# For values of lambda not in the sequence of fitted models,
# linear interpolation is used.
sel.groups <- predict(object = fit.PCLasso2, type="groups",
                      lambda = c(0.1, 0.05))
sel.ngroups <- predict(object = fit.PCLasso2, type="ngroups",
                       lambda = c(0.1, 0.05))
sel.vars.unique <- predict(object = fit.PCLasso2, type="vars.unique",
                           lambda = c(0.1, 0.05))
sel.nvars.unique <- predict(object = fit.PCLasso2, type="nvars.unique",
                            lambda = c(0.1, 0.05))
sel.vars <- predict(object = fit.PCLasso2, type="vars",
                    lambda=c(0.1, 0.05))
sel.nvars <- predict(object = fit.PCLasso2, type="nvars",
                     lambda=c(0.1, 0.05))

PCLassoReg documentation built on Oct. 26, 2021, 5:07 p.m.