predict.biglasso: Model predictions based on a fitted 'biglasso' object

Description Usage Arguments Value Author(s) See Also Examples

View source: R/predict.R

Description

Extract predictions (fitted reponse, coefficients, etc.) from a fitted biglasso object.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
## S3 method for class 'biglasso'
predict(
  object,
  X,
  row.idx = 1:nrow(X),
  type = c("link", "response", "class", "coefficients", "vars", "nvars"),
  lambda,
  which = 1:length(object$lambda),
  ...
)

## S3 method for class 'biglasso'
coef(object, lambda, which = 1:length(object$lambda), drop = TRUE, ...)

Arguments

object

A fitted "biglasso" model object.

X

Matrix of values at which predictions are to be made. It must be a big.matrix object. Not used for type="coefficients".

row.idx

Similar to that in biglasso, it's a vector of the row indices of X that used for the prediction. 1:nrow(X) by default.

type

Type of prediction: "link" returns the linear predictors; "response" gives the fitted values; "class" returns the binomial outcome with the highest probability; "coefficients" returns the coefficients; "vars" returns a list containing the indices and names of the nonzero variables at each value of lambda; "nvars" returns the number of nonzero coefficients at each value of lambda.

lambda

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

which

Indices of the penalty parameter lambda at which predictions are required. By default, all indices are returned. If lambda is specified, this will override which.

...

Not used.

drop

If coefficients for a single value of lambda are to be returned, reduce dimensions to a vector? Setting drop=FALSE returns a 1-column matrix.

Value

The object returned depends on type.

Author(s)

Yaohui Zeng and Patrick Breheny

Maintainer: Yaohui Zeng <yaohui.zeng@gmail.com>

See Also

biglasso, cv.biglasso

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
## Logistic regression
data(colon)
X <- colon$X
y <- colon$y
X.bm <- as.big.matrix(X, backingfile = "")
fit <- biglasso(X.bm, y, penalty = 'lasso', family = "binomial")
coef <- coef(fit, lambda=0.05, drop = TRUE)
coef[which(coef != 0)]
predict(fit, X.bm, type="link", lambda=0.05)
predict(fit, X.bm, type="response", lambda=0.05)
predict(fit, X.bm, type="class", lambda=0.1)
predict(fit, type="vars", lambda=c(0.05, 0.1))
predict(fit, type="nvars", lambda=c(0.05, 0.1))

Example output

Loading required package: bigmemory
Loading required package: Matrix
Loading required package: ncvreg
 [1]  7.654998e-01 -5.099878e-05 -2.753690e-03 -4.182978e-04  5.594134e-05
 [6] -1.183261e-03  4.871641e-04  2.449309e-04  4.574918e-03 -2.180171e-04
[11] -1.093833e-03 -1.739847e-03  7.168045e-04  1.007572e-03 -2.752499e-03
[16]  4.657996e-03  5.308308e-03
62 x 1 Matrix of class "dgeMatrix"
             [,1]
 [1,]  0.80657843
 [2,] -2.45408801
 [3,]  1.01501325
 [4,] -0.52530845
 [5,]  2.05195419
 [6,] -0.75989314
 [7,]  2.20060583
 [8,] -2.17747477
 [9,]  3.15958483
[10,] -2.70142909
[11,]  3.28418036
[12,] -2.84941451
[13,]  2.34485569
[14,] -1.46437048
[15,]  1.50495225
[16,] -0.13395809
[17,]  1.46328018
[18,] -1.69169844
[19,]  2.13612627
[20,] -1.68576574
[21,]  1.89532653
[22,] -1.68573044
[23,]  1.82238529
[24,] -0.09110718
[25,]  3.14796116
[26,]  2.19139308
[27,]  1.94858999
[28,]  3.22172895
[29,]  3.34914259
[30,]  3.74678672
[31,]  2.56548870
[32,]  1.81331782
[33,]  2.19823384
[34,]  2.84731241
[35,]  2.02456764
[36,]  2.89529811
[37,]  2.51903154
[38,]  3.25978170
[39,] -1.76035575
[40,]  2.35820597
[41,]  1.50485826
[42,] -1.14629083
[43,] -2.37909346
[44,]  2.82885411
[45,]  0.11231428
[46,]  4.28140006
[47,]  5.26337880
[48,] -0.90349760
[49,]  0.03791252
[50,] -1.25430761
[51,] -0.07677275
[52,]  3.07554934
[53,]  1.62172269
[54,] -0.54414763
[55,] -0.07533609
[56,] -0.46422755
[57,]  1.92967633
[58,]  2.10648539
[59,]  1.42143336
[60,] -1.90503883
[61,]  1.45174345
[62,] -0.30845878
62 x 1 Matrix of class "dgeMatrix"
            [,1]
 [1,] 0.69137991
 [2,] 0.07914011
 [3,] 0.73400010
 [4,] 0.37161178
 [5,] 0.88614493
 [6,] 0.31866947
 [7,] 0.90030390
 [8,] 0.10179158
 [9,] 0.95928473
[10,] 0.06288908
[11,] 0.96388210
[12,] 0.05471159
[13,] 0.91252446
[14,] 0.18779978
[15,] 0.81831193
[16,] 0.46656047
[17,] 0.81203386
[18,] 0.15555261
[19,] 0.89436519
[20,] 0.15633350
[21,] 0.86936167
[22,] 0.15633816
[23,] 0.86085210
[24,] 0.47723895
[25,] 0.95882831
[26,] 0.89947394
[27,] 0.87529281
[28,] 0.96164384
[29,] 0.96607675
[30,] 0.97695038
[31,] 0.92860719
[32,] 0.85976238
[33,] 0.90009080
[34,] 0.94517959
[35,] 0.88335249
[36,] 0.94761352
[37,] 0.92546528
[38,] 0.96302302
[39,] 0.14674579
[40,] 0.91358428
[41,] 0.81829795
[42,] 0.24116723
[43,] 0.08478088
[44,] 0.94421528
[45,] 0.52804909
[46,] 0.98636518
[47,] 0.99484889
[48,] 0.28833227
[49,] 0.50947700
[50,] 0.22195536
[51,] 0.48081624
[52,] 0.95587284
[53,] 0.83503257
[54,] 0.36722327
[55,] 0.48117488
[56,] 0.38598341
[57,] 0.87321359
[58,] 0.89153193
[59,] 0.80556302
[60,] 0.12953924
[61,] 0.81026661
[62,] 0.42349098
62 x 1 Matrix of class "dgeMatrix"
      [,1]
 [1,]    1
 [2,]    0
 [3,]    1
 [4,]    1
 [5,]    1
 [6,]    0
 [7,]    1
 [8,]    0
 [9,]    1
[10,]    0
[11,]    1
[12,]    0
[13,]    1
[14,]    0
[15,]    1
[16,]    1
[17,]    1
[18,]    0
[19,]    1
[20,]    0
[21,]    1
[22,]    0
[23,]    1
[24,]    1
[25,]    1
[26,]    1
[27,]    1
[28,]    1
[29,]    1
[30,]    1
[31,]    1
[32,]    1
[33,]    1
[34,]    1
[35,]    1
[36,]    1
[37,]    1
[38,]    1
[39,]    0
[40,]    1
[41,]    1
[42,]    0
[43,]    0
[44,]    1
[45,]    0
[46,]    1
[47,]    1
[48,]    0
[49,]    1
[50,]    0
[51,]    1
[52,]    1
[53,]    1
[54,]    0
[55,]    1
[56,]    0
[57,]    1
[58,]    1
[59,]    1
[60,]    0
[61,]    1
[62,]    0
$`0.05`
 Hsa.8147 Hsa.36689 Hsa.42949 Hsa.22762 Hsa.692.2 Hsa.31801  Hsa.3016  Hsa.5392 
      249       377       617       639       765      1024      1325      1346 
 Hsa.1832 Hsa.12241 Hsa.44244  Hsa.2928 Hsa.41159 Hsa.33268  Hsa.6814  Hsa.1660 
     1423      1482      1504      1582      1641      1644      1772      1870 

$`0.1`
 Hsa.8147 Hsa.36689 Hsa.37937  Hsa.3306 Hsa.692.2  Hsa.5392  Hsa.2928 Hsa.33268 
      249       377       493       625       765      1346      1582      1644 
 Hsa.6814  Hsa.1660 
     1772      1870 

0.05  0.1 
  16   10 

biglasso documentation built on Jan. 31, 2021, 5:06 p.m.