Skip to contents

Predict from an xplus model

Usage

# S3 method for class 'xplus'
predict(object, newx = NULL, s = "lambda.min", type = "response", ...)

Arguments

object

An xplus object.

newx

Optional finite numeric feature matrix; defaults to training data. Named training features must match and are reordered automatically.

s

Exact penalty name ("lambda.min", "lambda.1se") or finite nonnegative numeric lambda vector. Cache-only objects support only "lambda.min".

type

Prediction type: "response", "link", or "class".

...

Additional arguments are not supported and cause an error.

Value

Probabilities (type = "response") or log-odds (type = "link"); cached probabilities of 0 and 1 give infinite log-odds. Classes use a factor with fixed levels "0", "1" for one lambda, or a dimension-preserving 0/1 matrix for multiple lambdas.

References

Zhou et al. (2022). doi:10.1371/journal.pcbi.1009956

Examples

set.seed(1)
x <- matrix(rnorm(100 * 5), ncol = 5)
y <- c(rep(1, 20), rep(0, 80))
fit <- xplus(x, y, max_iter = 5)
predict(fit, newx = x, type = "response")
#>        s=0.02089059
#>   [1,]    0.5696908
#>   [2,]    0.4742642
#>   [3,]    0.6519269
#>   [4,]    0.5574350
#>   [5,]    0.6304054
#>   [6,]    0.6312614
#>   [7,]    0.5586748
#>   [8,]    0.6026645
#>   [9,]    0.4711503
#>  [10,]    0.5418794
#>  [11,]    0.6577376
#>  [12,]    0.5528301
#>  [13,]    0.4593221
#>  [14,]    0.3688330
#>  [15,]    0.5798778
#>  [16,]    0.6190003
#>  [17,]    0.4833360
#>  [18,]    0.5387097
#>  [19,]    0.4693125
#>  [20,]    0.5845582
#>  [21,]    0.6354673
#>  [22,]    0.6628377
#>  [23,]    0.5798079
#>  [24,]    0.3073260
#>  [25,]    0.5712282
#>  [26,]    0.5777777
#>  [27,]    0.4870318
#>  [28,]    0.4558257
#>  [29,]    0.4421409
#>  [30,]    0.5945907
#>  [31,]    0.5438216
#>  [32,]    0.3693810
#>  [33,]    0.5047629
#>  [34,]    0.6283624
#>  [35,]    0.4412485
#>  [36,]    0.5602826
#>  [37,]    0.5848375
#>  [38,]    0.5072446
#>  [39,]    0.5569113
#>  [40,]    0.5161245
#>  [41,]    0.5808187
#>  [42,]    0.4468923
#>  [43,]    0.5738556
#>  [44,]    0.5146807
#>  [45,]    0.3453089
#>  [46,]    0.3674073
#>  [47,]    0.5998735
#>  [48,]    0.5385417
#>  [49,]    0.5770080
#>  [50,]    0.7027016
#>  [51,]    0.6483315
#>  [52,]    0.5542782
#>  [53,]    0.5655862
#>  [54,]    0.4596525
#>  [55,]    0.6991223
#>  [56,]    0.6597696
#>  [57,]    0.3926619
#>  [58,]    0.4761164
#>  [59,]    0.4096287
#>  [60,]    0.4985811
#>  [61,]    0.4418461
#>  [62,]    0.6141467
#>  [63,]    0.5016666
#>  [64,]    0.5037150
#>  [65,]    0.5018586
#>  [66,]    0.5805534
#>  [67,]    0.4945837
#>  [68,]    0.6110915
#>  [69,]    0.4834739
#>  [70,]    0.5007022
#>  [71,]    0.5115668
#>  [72,]    0.5202985
#>  [73,]    0.4772742
#>  [74,]    0.5129978
#>  [75,]    0.3882249
#>  [76,]    0.5495341
#>  [77,]    0.4868830
#>  [78,]    0.5224369
#>  [79,]    0.4985770
#>  [80,]    0.6394640
#>  [81,]    0.5622592
#>  [82,]    0.5955903
#>  [83,]    0.5204174
#>  [84,]    0.4643510
#>  [85,]    0.6255081
#>  [86,]    0.5213046
#>  [87,]    0.4017230
#>  [88,]    0.5489168
#>  [89,]    0.4033204
#>  [90,]    0.4869276
#>  [91,]    0.5948122
#>  [92,]    0.6227220
#>  [93,]    0.6523585
#>  [94,]    0.5582907
#>  [95,]    0.6025878
#>  [96,]    0.4797632
#>  [97,]    0.5986238
#>  [98,]    0.5155027
#>  [99,]    0.4195842
#> [100,]    0.5651255
predict(fit, newx = x, type = "link")
#>        s=0.02089059
#>   [1,]  0.280589933
#>   [2,] -0.103034136
#>   [3,]  0.627519850
#>   [4,]  0.230758666
#>   [5,]  0.533956283
#>   [6,]  0.537632127
#>   [7,]  0.235785468
#>   [8,]  0.416579784
#>   [9,] -0.115527123
#>  [10,]  0.167910932
#>  [11,]  0.653228292
#>  [12,]  0.212112236
#>  [13,] -0.163071839
#>  [14,] -0.537226587
#>  [15,]  0.322271683
#>  [16,]  0.485306970
#>  [17,] -0.066680650
#>  [18,]  0.155149286
#>  [19,] -0.122904663
#>  [20,]  0.341513800
#>  [21,]  0.555744245
#>  [22,]  0.675965775
#>  [23,]  0.321984670
#>  [24,] -0.812650414
#>  [25,]  0.286864031
#>  [26,]  0.313657290
#>  [27,] -0.051884289
#>  [28,] -0.177159004
#>  [29,] -0.232477839
#>  [30,]  0.382976237
#>  [31,]  0.175737440
#>  [32,] -0.534873459
#>  [33,]  0.019052296
#>  [34,]  0.525197876
#>  [35,] -0.236096633
#>  [36,]  0.242308883
#>  [37,]  0.342664177
#>  [38,]  0.028980562
#>  [39,]  0.228636014
#>  [40,]  0.064520252
#>  [41,]  0.326135005
#>  [42,] -0.213234940
#>  [43,]  0.297599436
#>  [44,]  0.058739746
#>  [45,] -0.639724180
#>  [46,] -0.543355705
#>  [47,]  0.404938006
#>  [48,]  0.154473268
#>  [49,]  0.310503047
#>  [50,]  0.860195859
#>  [51,]  0.611713259
#>  [52,]  0.217971925
#>  [53,]  0.263865213
#>  [54,] -0.161741867
#>  [55,]  0.843121784
#>  [56,]  0.662267850
#>  [57,] -0.436136579
#>  [58,] -0.095607349
#>  [59,] -0.365500413
#>  [60,] -0.005675624
#>  [61,] -0.233673164
#>  [62,]  0.464776605
#>  [63,]  0.006666506
#>  [64,]  0.014860316
#>  [65,]  0.007434529
#>  [66,]  0.325045599
#>  [67,] -0.021665973
#>  [68,]  0.451902499
#>  [69,] -0.066128310
#>  [70,]  0.002808825
#>  [71,]  0.046275631
#>  [72,]  0.081238744
#>  [73,] -0.090965895
#>  [74,]  0.052002879
#>  [75,] -0.454780004
#>  [76,]  0.198788638
#>  [77,] -0.052479899
#>  [78,]  0.089807854
#>  [79,] -0.005692176
#>  [80,]  0.573038630
#>  [81,]  0.250336179
#>  [82,]  0.387124601
#>  [83,]  0.081714953
#>  [84,] -0.142838334
#>  [85,]  0.512994309
#>  [86,]  0.085269998
#>  [87,] -0.398291016
#>  [88,]  0.196295057
#>  [89,] -0.391649128
#>  [90,] -0.052301354
#>  [91,]  0.383894938
#>  [92,]  0.501118019
#>  [93,]  0.629422429
#>  [94,]  0.234227796
#>  [95,]  0.416259530
#>  [96,] -0.080991432
#>  [97,]  0.399734215
#>  [98,]  0.062030520
#>  [99,] -0.324480469
#> [100,]  0.261990333