Similar to other predict methods, this functions predicts fitted values, logits, coefficients and more from a fitted "glmnet" object.

# S3 method for glmnet
coef(object, s = NULL, exact = FALSE, ...)

# S3 method for glmnet
predict(
  object,
  newx,
  s = NULL,
  type = c("link", "response", "coefficients", "nonzero", "class"),
  exact = FALSE,
  newoffset,
  ...
)

# S3 method for relaxed
predict(
  object,
  newx,
  s = NULL,
  gamma = 1,
  type = c("link", "response", "coefficients", "nonzero", "class"),
  exact = FALSE,
  newoffset,
  ...
)

Arguments

object

Fitted "glmnet" model object or a "relaxed" model (which inherits from class "glmnet").

s

Value(s) of the penalty parameter lambda at which predictions are required. Default is the entire sequence used to create the model.

exact

This argument is relevant only when predictions are made at values of s (lambda) different from those used in the fitting of the original model. Not available for "relaxed" objects. If exact=FALSE (default), then the predict function uses linear interpolation to make predictions for values of s (lambda) that do not coincide with those used in the fitting algorithm. While this is often a good approximation, it can sometimes be a bit coarse. With exact=TRUE, these different values of s are merged (and sorted) with object$lambda, and the model is refit before predictions are made. In this case, it is required to supply the original data x= and y= as additional named arguments to predict() or coef(). The workhorse predict.glmnet() needs to update the model, and so needs the data used to create it. The same is true of weights, offset, penalty.factor, lower.limits, upper.limits if these were used in the original call. Failure to do so will result in an error.

...

This is the mechanism for passing arguments like x= when exact=TRUE; seeexact argument.

newx

Matrix of new values for x at which predictions are to be made. Must be a matrix; can be sparse as in Matrix package. This argument is not used for type=c("coefficients","nonzero")

type

Type of prediction required. Type "link" gives the linear predictors for "binomial", "multinomial", "poisson" or "cox" models; for "gaussian" models it gives the fitted values. Type "response" gives the fitted probabilities for "binomial" or "multinomial", fitted mean for "poisson" and the fitted relative-risk for "cox"; for "gaussian" type "response" is equivalent to type "link". Type "coefficients" computes the coefficients at the requested values for s. Note that for "binomial" models, results are returned only for the class corresponding to the second level of the factor response. Type "class" applies only to "binomial" or "multinomial" models, and produces the class label corresponding to the maximum probability. Type "nonzero" returns a list of the indices of the nonzero coefficients for each value of s.

newoffset

If an offset is used in the fit, then one must be supplied for making predictions (except for type="coefficients" or type="nonzero")

gamma

Single value of gamma at which predictions are required, for "relaxed" objects.

Value

The object returned depends on type.

Details

The shape of the objects returned are different for "multinomial" objects. This function actually calls NextMethod(), and the appropriate predict method is invoked for each of the three model types. coef(...) is equivalent to predict(type="coefficients",...)

References

Friedman, J., Hastie, T. and Tibshirani, R. (2008) Regularization Paths for Generalized Linear Models via Coordinate Descent (2010), Journal of Statistical Software, Vol. 33(1), 1-22, doi:10.18637/jss.v033.i01 .
Simon, N., Friedman, J., Hastie, T. and Tibshirani, R. (2011) Regularization Paths for Cox's Proportional Hazards Model via Coordinate Descent, Journal of Statistical Software, Vol. 39(5), 1-13, doi:10.18637/jss.v039.i05 .
Glmnet webpage with four vignettes, https://glmnet.stanford.edu.

See also

glmnet, and print, and coef methods, and cv.glmnet.

Author

Jerome Friedman, Trevor Hastie and Rob Tibshirani
Maintainer: Trevor Hastie [email protected]

Examples

x=matrix(rnorm(100*20),100,20)
y=rnorm(100)
g2=sample(1:2,100,replace=TRUE)
g4=sample(1:4,100,replace=TRUE)
fit1=glmnet(x,y)
predict(fit1,newx=x[1:5,],s=c(0.01,0.005))
#>              s0         s1
#> [1,] -0.3037893 -0.3067493
#> [2,] -0.5245809 -0.5450835
#> [3,] -0.6210713 -0.6606625
#> [4,] -0.9940492 -1.0306614
#> [5,] -1.0283366 -1.0802449
predict(fit1,type="coef")
#> 21 x 66 sparse Matrix of class "dgCMatrix"
#>   [[ suppressing 66 column names ‘s0’, ‘s1’, ‘s2’ ... ]]
#>                                                                        
#> (Intercept) -0.05700824 -0.05779938 -0.05852023 -0.05917704 -0.05894747
#> V1           .           .           .           .           .         
#> V2           .           .           .           .           .         
#> V3           .           .           .           .           0.01192345
#> V4           .           .           .           .           .         
#> V5           .           .           .           .           .         
#> V6           .           .           .           .           .         
#> V7           .           .           .           .           .         
#> V8           .           0.02169936  0.04147101  0.05948620  0.07579326
#> V9           .           .           .           .           .         
#> V10          .           .           .           .           .         
#> V11          .           .           .           .           .         
#> V12          .           .           .           .           .         
#> V13          .           .           .           .           .         
#> V14          .           .           .           .           .         
#> V15          .           .           .           .           .         
#> V16          .           .           .           .           .         
#> V17          .           .           .           .           .         
#> V18          .           .           .           .           .         
#> V19          .           .           .           .           .         
#> V20          .           .           .           .           .         
#>                                                                         
#> (Intercept) -0.058202084 -0.05699762 -0.05576873 -0.05437576 -0.05301113
#> V1           .            .           .           .           .         
#> V2           .            .           .           .           .         
#> V3           0.026309528  0.03933279  0.05139986  0.06281234  0.07333608
#> V4           .            .           .           .           .         
#> V5           0.004265424  0.01592085  0.02691299  0.03770242  0.04760766
#> V6           .            .           .           .           .         
#> V7           .            .           .           .           .         
#> V8           0.090425233  0.10340365  0.11470810  0.12392501  0.13194059
#> V9           .            .           .           .           .         
#> V10          .            .           .           .           .         
#> V11          .            .           .           .           .         
#> V12          .            .           .           .           .         
#> V13          .            .           .           .           .         
#> V14          .            .           .           .           .         
#> V15          .            .           .           .           .         
#> V16          .            .           .           .           .         
#> V17          .            .           .           .           .         
#> V18          .            .           .           .           .         
#> V19          .            .           0.00390379  0.01557760  0.02632822
#> V20          .            .           .           .           0.00143025
#>                                                                             
#> (Intercept) -0.051589299 -0.050432168 -0.050036979 -0.049648523 -0.049084886
#> V1           .            .            .            .            .          
#> V2           0.005104009  0.012505658  0.018755404  0.023811633  0.027886196
#> V3           0.083555283  0.094000231  0.102053383  0.110616948  0.118821633
#> V4           .            .            .            .            .          
#> V5           0.056821669  0.064074257  0.069924143  0.075115984  0.079076108
#> V6           .            .            .            .            .          
#> V7           .            .            .            .            .          
#> V8           0.136323446  0.141263547  0.148149468  0.155112894  0.162545754
#> V9           .           -0.008062357 -0.016331029 -0.024696630 -0.032592768
#> V10          .            .            .            .            .          
#> V11          .            .            .           -0.005108488 -0.012105424
#> V12          .            .            .            .            .          
#> V13          .            .            .            .            .          
#> V14          .            .            .            .            .          
#> V15          .            .            .            .            .          
#> V16          .            .            .            .            0.003404985
#> V17          .           -0.001323090 -0.008541288 -0.014925122 -0.021445394
#> V18          .            .            .            .            .          
#> V19          0.036702802  0.046021797  0.054548266  0.061753028  0.068076131
#> V20          0.010076412  0.017845184  0.024859686  0.031228923  0.036994926
#>                                                                          
#> (Intercept) -0.048942459 -0.048105605 -0.04722324 -0.04642121 -0.04569051
#> V1           .            .            .           .           .         
#> V2           0.033160730  0.037926422  0.04232308  0.04631477  0.04995122
#> V3           0.126038430  0.132757657  0.13896806  0.14461206  0.14975408
#> V4           .            .            .           .           .         
#> V5           0.082600505  0.086333179  0.08985103  0.09304582  0.09595652
#> V6           .           -0.006723596 -0.01392109 -0.02048127 -0.02645833
#> V7           .            .            .           .           .         
#> V8           0.167931948  0.172075272  0.17563993  0.17891946  0.18190836
#> V9          -0.039739925 -0.046311451 -0.05234424 -0.05783532 -0.06283825
#> V10          .            .            .           .           .         
#> V11         -0.018844972 -0.025708258 -0.03210518 -0.03793294 -0.04324265
#> V12          .            .            .           .           .         
#> V13          .            .            .           .           .         
#> V14         -0.006844741 -0.014246723 -0.02118482 -0.02750259 -0.03325876
#> V15          .            .            .           .           .         
#> V16          0.007467640  0.010312351  0.01272353  0.01493303  0.01694671
#> V17         -0.027905823 -0.034525429 -0.04061302 -0.04617594 -0.05124516
#> V18          .            .            .           .           .         
#> V19          0.074236479  0.079247134  0.08372532  0.08780104  0.09151466
#> V20          0.042046564  0.047057620  0.05170231  0.05592920  0.05978049
#>                                                                           
#> (Intercept) -0.04502472 -0.04441808 -0.044208940 -0.043811959 -0.043690501
#> V1           .           .           .            .            .          
#> V2           0.05326459  0.05628362  0.059841964  0.063877906  0.067591068
#> V3           0.15443928  0.15870826  0.162389137  0.165690887  0.168702457
#> V4           .           .           .            .            0.001668169
#> V5           0.09860864  0.10102514  0.102873951  0.104374878  0.105817359
#> V6          -0.03190440 -0.03686665 -0.041481464 -0.045425422 -0.048959556
#> V7           .           .           0.003260545  0.006488219  0.009738234
#> V8           0.18463175  0.18711321  0.189432053  0.191489475  0.193070434
#> V9          -0.06739672 -0.07155023 -0.075213611 -0.079011536 -0.082669706
#> V10          .           .           .            .            .          
#> V11         -0.04808065 -0.05248885 -0.056792604 -0.061098107 -0.064880130
#> V12          .           .           .            .            .          
#> V13          .           .           .            .            .          
#> V14         -0.03850356 -0.04328242 -0.047613236 -0.051684965 -0.055314915
#> V15          .           .           0.001511234  0.006218936  0.010658444
#> V16          0.01878151  0.02045331  0.021750601  0.022850054  0.023487348
#> V17         -0.05586405 -0.06007261 -0.063756526 -0.067061393 -0.069897526
#> V18          .           .           .            .            .          
#> V19          0.09489837  0.09798148  0.100898753  0.103423730  0.105622400
#> V20          0.06328964  0.06648705  0.069357217  0.071889223  0.074098109
#>                                                                              
#> (Intercept) -0.043283407 -0.042860610 -0.042478736 -0.042349076 -0.0422643154
#> V1           .            .            .            .            .           
#> V2           0.071192849  0.074414671  0.077376853  0.080171275  0.0827635453
#> V3           0.171389215  0.173793096  0.176005557  0.178101837  0.1798873447
#> V4           0.002713922  0.003497324  0.004237230  0.005106450  0.0060802477
#> V5           0.107135170  0.108328028  0.109417476  0.110583216  0.1116292826
#> V6          -0.052490302 -0.055741202 -0.058704416 -0.061548625 -0.0641320246
#> V7           0.012883924  0.015748698  0.018362332  0.020905283  0.0232934376
#> V8           0.194239117  0.195338436  0.196319808  0.197255617  0.1979628699
#> V9          -0.085768594 -0.088511499 -0.091032929 -0.093554477 -0.0959811826
#> V10          .            .            .            0.002633589  0.0050813248
#> V11         -0.068321676 -0.071427707 -0.074271576 -0.076633795 -0.0788045124
#> V12          .            .            .            .            .           
#> V13          .            .            .            .            0.0008893557
#> V14         -0.058702471 -0.061767256 -0.064569128 -0.066974357 -0.0693027304
#> V15          0.014576792  0.018098929  0.021318826  0.024124799  0.0266225025
#> V16          0.024132626  0.024796350  0.025379209  0.025926687  0.0264065920
#> V17         -0.072558971 -0.075048863 -0.077295713 -0.079723169 -0.0819143948
#> V18         -0.002401769 -0.004874331 -0.007118082 -0.008709924 -0.0100323677
#> V19          0.107911253  0.110042231  0.111979469  0.113811018  0.1154723858
#> V20          0.076403478  0.078546220  0.080496666  0.082295603  0.0838021830
#>                                                                             
#> (Intercept) -0.042176692 -0.042097138 -0.042024654 -0.041958610 -0.041898432
#> V1           .            .            .            .            .          
#> V2           0.085101374  0.087239079  0.089187171  0.090962213  0.092579566
#> V3           0.181503124  0.182975092  0.184316545  0.185538839  0.186652547
#> V4           0.006927799  0.007704112  0.008411657  0.009056355  0.009643780
#> V5           0.112566779  0.113425417  0.114207820  0.114920721  0.115570289
#> V6          -0.066452673 -0.068578438 -0.070515449 -0.072280384 -0.073888528
#> V7           0.025480467  0.027473718  0.029289896  0.030944731  0.032452555
#> V8           0.198568527  0.199120865  0.199623908  0.200082249  0.200499871
#> V9          -0.098205321 -0.100238244 -0.102090814 -0.103778818 -0.105316864
#> V10          0.007274958  0.009272502  0.011092511  0.012750833  0.014261833
#> V11         -0.080776331 -0.082584075 -0.084231404 -0.085732396 -0.087100043
#> V12          .            .            .            .            .          
#> V13          0.001911461  0.002844578  0.003694839  0.004469566  0.005175469
#> V14         -0.071429934 -0.073377582 -0.075152347 -0.076769454 -0.078242901
#> V15          0.028866549  0.030915477  0.032782493  0.034483652  0.036033686
#> V16          0.026859792  0.027266081  0.027636054  0.027973149  0.028280298
#> V17         -0.083891546 -0.085690726 -0.087329836 -0.088823322 -0.090184130
#> V18         -0.011233196 -0.012323939 -0.013317721 -0.014223215 -0.015048268
#> V19          0.116997713  0.118383934  0.119646960  0.120797781  0.121846366
#> V20          0.085157138  0.086389713  0.087512776  0.088536069  0.089468456
#>                                                                             
#> (Intercept) -0.041843600 -0.041793640 -0.041748118 -0.041706640 -0.041668846
#> V1           .            .            .            .            .          
#> V2           0.094053238  0.095395993  0.096619462  0.097734241  0.098749985
#> V3           0.187667317  0.188591937  0.189434417  0.190202053  0.190901495
#> V4           0.010179020  0.010666710  0.011111076  0.011515965  0.011884885
#> V5           0.116162152  0.116701435  0.117192810  0.117640532  0.118048480
#> V6          -0.075353809 -0.076688918 -0.077905420 -0.079013851 -0.080023812
#> V7           0.033826428  0.035078250  0.036218863  0.037258148  0.038205105
#> V8           0.200880393  0.201227111  0.201543027  0.201830878  0.202093157
#> V9          -0.106718274 -0.107995187 -0.109158663 -0.110218778 -0.111184716
#> V10          0.015638601  0.016893060  0.018036076  0.019077550  0.020026503
#> V11         -0.088346193 -0.089481639 -0.090516214 -0.091458881 -0.092317803
#> V12          .            .            .            .            .          
#> V13          0.005818662  0.006404715  0.006938705  0.007425257  0.007868584
#> V14         -0.079585452 -0.080808734 -0.081923343 -0.082938933 -0.083864301
#> V15          0.037446019  0.038732884  0.039905427  0.040973805  0.041947271
#> V16          0.028560159  0.028815159  0.029047506  0.029259211  0.029452109
#> V17         -0.091424048 -0.092553815 -0.093583216 -0.094521169 -0.095375796
#> V18         -0.015800025 -0.016484999 -0.017109121 -0.017677798 -0.018195955
#> V19          0.122801797  0.123672351  0.124465567  0.125188316  0.125846858
#> V20          0.090318012  0.091092096  0.091797413  0.092440071  0.093025637
#>                                                                             
#> (Intercept) -0.041634411 -0.041603034 -0.041574445 -0.041548395 -0.041524660
#> V1           .            .            .            .            .          
#> V2           0.099675494  0.100518784  0.101287157  0.101987271  0.102625188
#> V3           0.191538800  0.192119488  0.192648590  0.193130688  0.193569957
#> V4           0.012221031  0.012527315  0.012806389  0.013060672  0.013292364
#> V5           0.118420187  0.118758873  0.119067471  0.119348653  0.119604856
#> V6          -0.080944051 -0.081782539 -0.082546537 -0.083242664 -0.083876949
#> V7           0.039067937  0.039854118  0.040570456  0.041223157  0.041817874
#> V8           0.202332136  0.202549884  0.202748289  0.202929067  0.203093786
#> V9          -0.112064843 -0.112866781 -0.113597478 -0.114263261 -0.114869898
#> V10          0.020891153  0.021678990  0.022396837  0.023050913  0.023646883
#> V11         -0.093100422 -0.093813515 -0.094463258 -0.095055280 -0.095594709
#> V12          .            .            .            .            .          
#> V13          0.008272528  0.008640587  0.008975948  0.009281516  0.009559939
#> V14         -0.084707462 -0.085475719 -0.086175726 -0.086813546 -0.087394704
#> V15          0.042834258  0.043642446  0.044378838  0.045049810  0.045661175
#> V16          0.029627870  0.029788017  0.029933938  0.030066895  0.030188040
#> V17         -0.096154500 -0.096864027 -0.097510521 -0.098099582 -0.098636313
#> V18         -0.018668081 -0.019098264 -0.019490231 -0.019847376 -0.020172794
#> V19          0.126446897  0.126993630  0.127491793  0.127945700  0.128359284
#> V20          0.093559183  0.094045330  0.094488289  0.094891897  0.095259650
#>                                                                              
#> (Intercept) -0.0415092829 -0.041501715 -0.041499004 -0.041496756 -0.041494723
#> V1           .             .            .            .            .          
#> V2           0.1032457313  0.103820060  0.104351076  0.104833591  0.105273011
#> V3           0.1940317637  0.194504106  0.194925226  0.195307652  0.195655923
#> V4           0.0135248089  0.013756197  0.013964215  0.014152877  0.014324632
#> V5           0.1197850004  0.119900386  0.119988706  0.120067762  0.120139658
#> V6          -0.0844891124 -0.085066100 -0.085610072 -0.086106034 -0.086557904
#> V7           0.0424725705  0.043161986  0.043810509  0.044402262  0.044941495
#> V8           0.2033356411  0.203654027  0.203977427  0.204275635  0.204547732
#> V9          -0.1154290645 -0.115939220 -0.116403853 -0.116826363 -0.117211185
#> V10          0.0242832925  0.024947699  0.025565562  0.026129488  0.026643414
#> V11         -0.0961538057 -0.096712247 -0.097230487 -0.097702593 -0.098132679
#> V12         -0.0005085754 -0.001392721 -0.002222262 -0.002979659 -0.003669891
#> V13          0.0098387420  0.010104161  0.010347528  0.010569046  0.010770851
#> V14         -0.0878937054 -0.088307344 -0.088688210 -0.089034494 -0.089349889
#> V15          0.0462282336  0.046749390  0.047228017  0.047663926  0.048061052
#> V16          0.0303077820  0.030433978  0.030559326  0.030675164  0.030780928
#> V17         -0.0992085526 -0.099807826 -0.100375493 -0.100894930 -0.101368477
#> V18         -0.0205704994 -0.021014124 -0.021421972 -0.021793857 -0.022132744
#> V19          0.1286987247  0.128977108  0.129223516  0.129447668  0.129651893
#> V20          0.0955613298  0.095808326  0.096026168  0.096224201  0.096404609
#>                                                                              
#> (Intercept) -0.041492871 -0.04149118 -0.041489647 -4.149906e-02 -0.0415164791
#> V1           .            .           .            5.885664e-05  0.0001558717
#> V2           0.105673363  0.10603815  0.106370521  1.066747e-01  0.1069675087
#> V3           0.195973232  0.19626235  0.196525782  1.967621e-01  0.1969735052
#> V4           0.014481109  0.01462368  0.014753591  1.486451e-02  0.0149619307
#> V5           0.120205153  0.12026483  0.120319201  1.203719e-01  0.1204210283
#> V6          -0.086969625 -0.08734477 -0.087686587 -8.799753e-02 -0.0882754377
#> V7           0.045432828  0.04588051  0.046288425  4.665942e-02  0.0469972151
#> V8           0.204795699  0.20502164  0.205227513  2.054139e-01  0.2055821778
#> V9          -0.117561800 -0.11788127 -0.118172349 -1.184354e-01 -0.1186781051
#> V10          0.027111696  0.02753838  0.027927154  2.828958e-02  0.0286147663
#> V11         -0.098524545 -0.09888160 -0.099206931 -9.949943e-02 -0.0997638148
#> V12         -0.004298816 -0.00487187 -0.005394016 -5.861572e-03 -0.0062842912
#> V13          0.010954724  0.01112226  0.011274916  1.140725e-02  0.0115215295
#> V14         -0.089637249 -0.08989908 -0.090137647 -9.035188e-02 -0.0905432101
#> V15          0.048422891  0.04875258  0.049052988  4.934032e-02  0.0496175863
#> V16          0.030877323  0.03096516  0.031045190  3.112322e-02  0.0311933713
#> V17         -0.101799985 -0.10219316 -0.102551412 -1.028714e-01 -0.1031501169
#> V18         -0.022441530 -0.02272289 -0.022979245 -2.322072e-02 -0.0234442643
#> V19          0.129837976  0.13000753  0.130162016  1.302936e-01  0.1304041387
#> V20          0.096568987  0.09671876  0.096855232  9.697168e-02  0.0970693586
#>                                                                    
#> (Intercept) -0.0415303928 -0.0415430072 -0.0415467493 -0.0415563089
#> V1           0.0002358817  0.0003084364  0.0003709984  0.0004306885
#> V2           0.1072293146  0.1074674569  0.1076428086  0.1078394627
#> V3           0.1971680577  0.1973451062  0.1975050517  0.1976530487
#> V4           0.0150509954  0.0151320874  0.0151821407  0.0152478993
#> V5           0.1204655823  0.1205061838  0.1205614751  0.1205964889
#> V6          -0.0885300181 -0.0887620557 -0.0889367280 -0.0891273970
#> V7           0.0473044646  0.0475844508  0.0478145875  0.0480446097
#> V8           0.2057357665  0.2058758713  0.2059793617  0.2060921097
#> V9          -0.1188983600 -0.1190988348 -0.1192654269 -0.1194311406
#> V10          0.0289138341  0.0291864629  0.0294209900  0.0296463708
#> V11         -0.1000048896 -0.1002245015 -0.1004072015 -0.1005869607
#> V12         -0.0066691380 -0.0070198510 -0.0073013345 -0.0075891444
#> V13          0.0116268044  0.0117228085  0.0118156813  0.0118956880
#> V14         -0.0907182730 -0.0908777949 -0.0910119165 -0.0911436356
#> V15          0.0498664962  0.0500930788  0.0502834941  0.0504703232
#> V16          0.0312583065  0.0313176002  0.0313726810  0.0314222590
#> V17         -0.1034075248 -0.1036423599 -0.1038392814 -0.1040329146
#> V18         -0.0236476365 -0.0238329364 -0.0239982417 -0.0241525303
#> V19          0.1305071941  0.1306011846  0.1307004927  0.1307800276
#> V20          0.0971605109  0.0972436330  0.0973300182  0.0974002563
#>                                                                    
#> (Intercept) -0.0415663603 -0.0415757374 -0.0415843152 -0.0415921357
#> V1           0.0004857522  0.0005360629  0.0005819284  0.0006237225
#> V2           0.1080227900  0.1081903526  0.1083430853  0.1084822507
#> V3           0.1977870663  0.1979091149  0.1980203121  0.1981216272
#> V4           0.0153110126  0.0153689528  0.0154217883  0.0154699291
#> V5           0.1206260538  0.1206525132  0.1206765255  0.1206983851
#> V6          -0.0893055850 -0.0894686101 -0.0896172505 -0.0897526999
#> V7           0.0482580555  0.0484531969  0.0486311136  0.0487932433
#> V8           0.2061993504  0.2062980419  0.2063881700  0.2064703348
#> V9          -0.1195838961 -0.1197234022 -0.1198505589 -0.1199664225
#> V10          0.0298535858  0.0300426813  0.0302150265  0.0303720700
#> V11         -0.1007541326 -0.1009070614 -0.1010465023 -0.1011735697
#> V12         -0.0078569490 -0.0081019391 -0.0083253372 -0.0085289198
#> V13          0.0119679585  0.0120336888  0.0120935548  0.0121480973
#> V14         -0.0912652019 -0.0913761292 -0.0914772076 -0.0915693027
#> V15          0.0506428165  0.0508003560  0.0509439551  0.0510748037
#> V16          0.0314669845  0.0315077263  0.0315448686  0.0315787209
#> V17         -0.1042117053 -0.1043750217 -0.1045239123 -0.1046595950
#> V18         -0.0242930059 -0.0244209727 -0.0245375713 -0.0246438134
#> V19          0.1308502664  0.1309138638  0.1309717440  0.1310244716
#> V20          0.0974624671  0.0975188314  0.0975701340  0.0976168701
#>                                                     
#> (Intercept) -0.0415992620 -0.041605755 -0.0416116716
#> V1           0.0006618038  0.000696502  0.0007281175
#> V2           0.1086090508  0.108724585  0.1088298556
#> V3           0.1982139402  0.198298052  0.1983746912
#> V4           0.0155137912  0.015553756  0.0155901696
#> V5           0.1207182986  0.120736442  0.1207529738
#> V6          -0.0898761181 -0.089988572 -0.0900910364
#> V7           0.0489409729  0.049075579  0.0491982274
#> V8           0.2065452101  0.206613436  0.2066756015
#> V9          -0.1200719924 -0.120168183 -0.1202558285
#> V10          0.0305151640  0.030645546  0.0307643461
#> V11         -0.1012893504 -0.101394845 -0.1014909686
#> V12         -0.0087144222 -0.008883446 -0.0090374547
#> V13          0.0121977934  0.012243074  0.0122843327
#> V14         -0.0916532144 -0.091729671 -0.0917993354
#> V15          0.0511940284  0.051302661  0.0514016433
#> V16          0.0316095693  0.031637678  0.0316632903
#> V17         -0.1047832289 -0.104895881 -0.1049985254
#> V18         -0.0247406180 -0.024828823 -0.0249091921
#> V19          0.1310725136  0.131116287  0.1311561726
#> V20          0.0976594529  0.097698253  0.0977336055
fit2=glmnet(x,g2,family="binomial")
predict(fit2,type="response",newx=x[2:5,])
#>        s0        s1        s2        s3        s4        s5        s6        s7
#> [1,] 0.49 0.4962467 0.5062733 0.5206122 0.5407381 0.5591158 0.5779415 0.5970651
#> [2,] 0.49 0.4795820 0.4706659 0.4628296 0.4560337 0.4497829 0.4480645 0.4478387
#> [3,] 0.49 0.4814987 0.4777668 0.4756991 0.4753262 0.4749664 0.4800043 0.4845192
#> [4,] 0.49 0.4862242 0.4928133 0.4974646 0.4986801 0.4997877 0.5141471 0.5285622
#>             s8        s9       s10       s11       s12       s13       s14
#> [1,] 0.6212125 0.6464876 0.6716376 0.6948439 0.7124006 0.7275561 0.7437893
#> [2,] 0.4523336 0.4584540 0.4631188 0.4684622 0.4739401 0.4798677 0.4872773
#> [3,] 0.4790691 0.4664649 0.4575183 0.4522991 0.4565731 0.4602511 0.4654025
#> [4,] 0.5366545 0.5385771 0.5434832 0.5476718 0.5455655 0.5436697 0.5422430
#>            s15       s16       s17       s18       s19       s20       s21
#> [1,] 0.7595146 0.7742376 0.7878513 0.8022617 0.8189572 0.8346100 0.8484135
#> [2,] 0.4946109 0.4963838 0.4944780 0.4923234 0.4851229 0.4782814 0.4719317
#> [3,] 0.4704631 0.4692565 0.4663457 0.4632768 0.4581653 0.4526547 0.4474877
#> [4,] 0.5412817 0.5420389 0.5430920 0.5450619 0.5488526 0.5547055 0.5603860
#>            s22       s23       s24       s25       s26       s27       s28
#> [1,] 0.8608808 0.8719649 0.8816613 0.8901519 0.8975978 0.9041381 0.9098931
#> [2,] 0.4662941 0.4611939 0.4564759 0.4521115 0.4480772 0.4443509 0.4409117
#> [3,] 0.4413815 0.4350968 0.4292907 0.4239341 0.4189950 0.4144434 0.4102515
#> [4,] 0.5656447 0.5704850 0.5749503 0.5790711 0.5828711 0.5863727 0.5895971
#>            s29       s30       s31       s32       s33       s34       s35
#> [1,] 0.9149658 0.9194454 0.9233344 0.9266993 0.9296935 0.9323620 0.9347439
#> [2,] 0.4377401 0.4348173 0.4320922 0.4295490 0.4272113 0.4250645 0.4230941
#> [3,] 0.4063932 0.4028442 0.3996101 0.3966766 0.3939826 0.3915102 0.3892422
#> [4,] 0.5925641 0.5952925 0.5977441 0.5999261 0.6019300 0.6037689 0.6054557
#>            s36       s37       s38       s39       s40       s41       s42
#> [1,] 0.9368728 0.9387700 0.9404780 0.9420108 0.9433877 0.9446259 0.9457405
#> [2,] 0.4212866 0.4196292 0.4181104 0.4167192 0.4154454 0.4142795 0.4132127
#> [3,] 0.3871627 0.3852671 0.3835211 0.3819221 0.3804585 0.3791193 0.3778944
#> [4,] 0.6070021 0.6084297 0.6097271 0.6109146 0.6120014 0.6129957 0.6139050
#>            s43       s44       s45       s46       s47       s48       s49
#> [1,] 0.9467448 0.9476415 0.9484593 0.9491984 0.9498665 0.9504708 0.9510178
#> [2,] 0.4122370 0.4113491 0.4105332 0.4097877 0.4091065 0.4084843 0.4079160
#> [3,] 0.3767744 0.3757621 0.3748262 0.3739705 0.3731888 0.3724749 0.3718230
#> [4,] 0.6147363 0.6155073 0.6162014 0.6168348 0.6174134 0.6179417 0.6184241
#>            s50       s51       s52       s53       s54       s55       s56
#> [1,] 0.9515030 0.9519518 0.9523594 0.9527291 0.9530645 0.9533689 0.9536452
#> [2,] 0.4074076 0.4069332 0.4065001 0.4061048 0.4057440 0.4054149 0.4051147
#> [3,] 0.3712394 0.3706964 0.3701998 0.3697466 0.3693330 0.3689557 0.3686115
#> [4,] 0.6188748 0.6192771 0.6196430 0.6199767 0.6202812 0.6205590 0.6208123
predict(fit2,type="nonzero")
#> $s0
#> NULL
#> 
#> $s1
#> [1] 19
#> 
#> $s2
#> [1] 17 19
#> 
#> $s3
#> [1] 14 17 19
#> 
#> $s4
#> [1] 14 17 19
#> 
#> $s5
#> [1] 14 17 19
#> 
#> $s6
#> [1] 14 17 19 20
#> 
#> $s7
#> [1]  3 14 17 19 20
#> 
#> $s8
#> [1]  3  5 14 17 19 20
#> 
#> $s9
#> [1]  1  3  5 14 17 19 20
#> 
#> $s10
#> [1]  1  3  5 14 17 19 20
#> 
#> $s11
#> [1]  1  3  5  7 12 14 17 19 20
#> 
#> $s12
#>  [1]  1  3  4  5  7 12 14 17 19 20
#> 
#> $s13
#>  [1]  1  3  4  5  7 12 14 17 19 20
#> 
#> $s14
#>  [1]  1  3  4  5  7  8 12 14 17 19 20
#> 
#> $s15
#>  [1]  1  3  4  5  7  8 10 12 14 17 19 20
#> 
#> $s16
#>  [1]  1  3  4  5  7  8 10 11 12 14 17 19 20
#> 
#> $s17
#>  [1]  1  3  4  5  7  8  9 10 11 12 14 17 19 20
#> 
#> $s18
#>  [1]  1  2  3  4  5  6  7  8  9 10 11 12 14 17 19 20
#> 
#> $s19
#>  [1]  1  2  3  4  5  6  7  8  9 10 11 12 14 17 19 20
#> 
#> $s20
#>  [1]  1  2  3  4  5  6  7  8  9 10 11 12 14 15 17 19 20
#> 
#> $s21
#>  [1]  1  2  3  4  5  6  7  8  9 10 11 12 14 15 17 19 20
#> 
#> $s22
#>  [1]  1  2  3  4  5  6  7  8  9 10 11 12 14 15 16 17 19 20
#> 
#> $s23
#>  [1]  1  2  3  4  5  6  7  8  9 10 11 12 14 15 16 17 19 20
#> 
#> $s24
#>  [1]  1  2  3  4  5  6  7  8  9 10 11 12 14 15 16 17 19 20
#> 
#> $s25
#>  [1]  1  2  3  4  5  6  7  8  9 10 11 12 14 15 16 17 19 20
#> 
#> $s26
#>  [1]  1  2  3  4  5  6  7  8  9 10 11 12 14 15 16 17 19 20
#> 
#> $s27
#>  [1]  1  2  3  4  5  6  7  8  9 10 11 12 14 15 16 17 19 20
#> 
#> $s28
#>  [1]  1  2  3  4  5  6  7  8  9 10 11 12 14 15 16 17 19 20
#> 
#> $s29
#>  [1]  1  2  3  4  5  6  7  8  9 10 11 12 14 15 16 17 19 20
#> 
#> $s30
#>  [1]  1  2  3  4  5  6  7  8  9 10 11 12 14 15 16 17 19 20
#> 
#> $s31
#>  [1]  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 19 20
#> 
#> $s32
#>  [1]  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 19 20
#> 
#> $s33
#>  [1]  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 19 20
#> 
#> $s34
#>  [1]  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 19 20
#> 
#> $s35
#>  [1]  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 19 20
#> 
#> $s36
#>  [1]  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 19 20
#> 
#> $s37
#>  [1]  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 19 20
#> 
#> $s38
#>  [1]  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 19 20
#> 
#> $s39
#>  [1]  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 19 20
#> 
#> $s40
#>  [1]  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 19 20
#> 
#> $s41
#>  [1]  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 19 20
#> 
#> $s42
#>  [1]  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 19 20
#> 
#> $s43
#>  [1]  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 19 20
#> 
#> $s44
#>  [1]  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 19 20
#> 
#> $s45
#>  [1]  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 19 20
#> 
#> $s46
#>  [1]  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 19 20
#> 
#> $s47
#>  [1]  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 19 20
#> 
#> $s48
#>  [1]  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 19 20
#> 
#> $s49
#>  [1]  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 19 20
#> 
#> $s50
#>  [1]  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 19 20
#> 
#> $s51
#>  [1]  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 19 20
#> 
#> $s52
#>  [1]  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 19 20
#> 
#> $s53
#>  [1]  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 19 20
#> 
#> $s54
#>  [1]  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 19 20
#> 
#> $s55
#>  [1]  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 19 20
#> 
#> $s56
#>  [1]  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 19 20
#> 
fit3=glmnet(x,g4,family="multinomial")
predict(fit3,newx=x[1:3,],type="response",s=0.01)
#> , , 1
#> 
#>              1         2          3          4
#> [1,] 0.2143507 0.2815262 0.11093754 0.39318563
#> [2,] 0.1603873 0.2412464 0.08515374 0.51321254
#> [3,] 0.6666361 0.0227436 0.22279029 0.08782998
#> 
OSZAR »