Skip to contents

Fits multi-penalty ridge regression (tuning regularisation hyperparameters and estimating regression coefficients). This is a wrapper function of some functions from the multiridge-package.

Usage

multiridge(
  x,
  y,
  z,
  family = "gaussian",
  foldid = NULL,
  nfolds = 10,
  penalties = NULL
)

Arguments

x

predictors: \(n \times p\) matrix

y

response: \(n\)-dimensional vector

z

\(p\)-dimensional vector with entries in \(\{1, \ldots, q\}\)

family

character "linear" (or "gaussian"), "logistic" (or "binomial"), or "cox"

foldid

\(n_0\)-dimensional vector containing the fold identifiers

nfolds

integer specifying the number of folds

penalties

\(q\)-dimensional vector of penalty parameters, or NULL (cross-validation)

Value

Returns an object of class "multiridge", a list with the following slots:

  • slots from IWLSridge() or IWLSCoxridge()

  • character family with value "gaussian" (also for "linear"), "binomial" (also for "logistic"), or "cox"

  • \(q\)-dimensional vector penalties containing optimised regularisation hyperparameters (one for each variable group)

  • list datablocks with \(q\) slots (one for each variable group), each containing an \(n_0 \times p_k\) matrix, where \(k \in \{1, \ldots, q\}\)

  • \(p\)-dimensional group vector z (see argument)

  • list pars with slots family (see above), the \(p\)-dimensional vectors mu.x and sd.x and the scalars mu.y and sd.y

Details

The number of observations (samples) for training or testing are indicated by \(n_0\) and \(n_1\), respectively, the number of variables (features) is indicated by \(p\), and the number of variable groups is indicated by \(q\). Observations (samples) are indexed by \(i\) in \(\{1, \ldots, n\}\), variables (features) are indexed by \(j\) in \(\{1, \ldots, p\}\), and variable groups are indexed by \(k\) in \(\{1, \ldots, q\}\). The number of variables in the \(k^{\text{th}}\) group is indicated by \(p_k\), with \(\sum_{k=1}^q p_k = p\) for non-overlapping groups.

References

Mark A. van de Wiel, Mirrelijn M. van Nee and Armin Rauschenberger (2021). "Fast cross-validation for multi-penalty high-dimensional ridge regression" Journal of Computational and Graphical Statistics 30(4):835-847. doi: 10.1080/10618600.2021.1904962. # nolint: line_length_linter.

See also

Extract coefficients with coef() or make predictions with predict(). Use cv.corila() to estimate sparse models.

This wrapper function calls various functions from the multiridge-package, namely createXXblocks(), fastCV2(), CVfolds(), optLambdasWrap(), SigmaFromBlocks(), IWLSridge(), and IWLSCoxridge().

The multiridge-package accepts not only an \(n \times p\) matrix but also a list of length \(q\) of \(n \times p_k\) matrices, with \(k\) in \(\{1, \ldots, q\}\).

Examples

# minimal example
n <- 50; p <- 20; q <- 5
x <- matrix(rnorm(n * p), nrow = n , ncol = p)
y <- rnorm(n)
z <- rep(seq_len(q), length.out = p)
multiridge(x = x, y = y, z = z)
#> $etas
#>               [,1]
#>  [1,] -0.075754438
#>  [2,]  0.455647949
#>  [3,] -0.300391462
#>  [4,]  0.155587108
#>  [5,] -0.212935622
#>  [6,] -0.036353054
#>  [7,] -0.213360068
#>  [8,] -0.135868448
#>  [9,] -0.249602673
#> [10,] -0.283477225
#> [11,]  0.025843994
#> [12,]  0.272801168
#> [13,] -0.066628228
#> [14,]  0.051101576
#> [15,]  0.245231870
#> [16,] -0.340477409
#> [17,]  0.288694146
#> [18,] -0.022893746
#> [19,]  0.319574477
#> [20,]  0.256122922
#> [21,] -0.295347135
#> [22,] -0.007745849
#> [23,] -0.422031967
#> [24,]  0.370005889
#> [25,]  0.102924921
#> [26,]  0.694241178
#> [27,] -0.283607982
#> [28,] -0.109879893
#> [29,] -0.189802264
#> [30,]  0.352398041
#> [31,]  0.412393197
#> [32,]  0.147621665
#> [33,] -0.195650761
#> [34,]  0.041051738
#> [35,]  0.026253283
#> [36,] -0.131109867
#> [37,]  0.223837424
#> [38,] -0.421957815
#> [39,] -0.477417172
#> [40,]  0.436804644
#> [41,]  0.032813311
#> [42,] -0.321312612
#> [43,] -0.014067663
#> [44,] -0.134378338
#> [45,] -0.133970301
#> [46,] -0.102899039
#> [47,]  0.534962424
#> [48,]  0.045134122
#> [49,] -0.194688007
#> [50,] -0.117438011
#> 
#> $Ypred
#>               [,1]
#>  [1,] -0.075754438
#>  [2,]  0.455647949
#>  [3,] -0.300391462
#>  [4,]  0.155587108
#>  [5,] -0.212935622
#>  [6,] -0.036353054
#>  [7,] -0.213360068
#>  [8,] -0.135868448
#>  [9,] -0.249602673
#> [10,] -0.283477225
#> [11,]  0.025843994
#> [12,]  0.272801168
#> [13,] -0.066628228
#> [14,]  0.051101576
#> [15,]  0.245231870
#> [16,] -0.340477409
#> [17,]  0.288694146
#> [18,] -0.022893746
#> [19,]  0.319574477
#> [20,]  0.256122922
#> [21,] -0.295347135
#> [22,] -0.007745849
#> [23,] -0.422031967
#> [24,]  0.370005889
#> [25,]  0.102924921
#> [26,]  0.694241178
#> [27,] -0.283607982
#> [28,] -0.109879893
#> [29,] -0.189802264
#> [30,]  0.352398041
#> [31,]  0.412393197
#> [32,]  0.147621665
#> [33,] -0.195650761
#> [34,]  0.041051738
#> [35,]  0.026253283
#> [36,] -0.131109867
#> [37,]  0.223837424
#> [38,] -0.421957815
#> [39,] -0.477417172
#> [40,]  0.436804644
#> [41,]  0.032813311
#> [42,] -0.321312612
#> [43,] -0.014067663
#> [44,] -0.134378338
#> [45,] -0.133970301
#> [46,] -0.102899039
#> [47,]  0.534962424
#> [48,]  0.045134122
#> [49,] -0.194688007
#> [50,] -0.117438011
#> 
#> $convergence
#> [1] FALSE
#> 
#> $nIt
#> [1] 1
#> 
#> $Hresl
#> $Hresl$Hmatl
#>               [,1]
#>  [1,] -0.075754438
#>  [2,]  0.455647949
#>  [3,] -0.300391462
#>  [4,]  0.155587108
#>  [5,] -0.212935622
#>  [6,] -0.036353054
#>  [7,] -0.213360068
#>  [8,] -0.135868448
#>  [9,] -0.249602673
#> [10,] -0.283477225
#> [11,]  0.025843994
#> [12,]  0.272801168
#> [13,] -0.066628228
#> [14,]  0.051101576
#> [15,]  0.245231870
#> [16,] -0.340477409
#> [17,]  0.288694146
#> [18,] -0.022893746
#> [19,]  0.319574477
#> [20,]  0.256122922
#> [21,] -0.295347135
#> [22,] -0.007745849
#> [23,] -0.422031967
#> [24,]  0.370005889
#> [25,]  0.102924921
#> [26,]  0.694241178
#> [27,] -0.283607982
#> [28,] -0.109879893
#> [29,] -0.189802264
#> [30,]  0.352398041
#> [31,]  0.412393197
#> [32,]  0.147621665
#> [33,] -0.195650761
#> [34,]  0.041051738
#> [35,]  0.026253283
#> [36,] -0.131109867
#> [37,]  0.223837424
#> [38,] -0.421957815
#> [39,] -0.477417172
#> [40,]  0.436804644
#> [41,]  0.032813311
#> [42,] -0.321312612
#> [43,] -0.014067663
#> [44,] -0.134378338
#> [45,] -0.133970301
#> [46,] -0.102899039
#> [47,]  0.534962424
#> [48,]  0.045134122
#> [49,] -0.194688007
#> [50,] -0.117438011
#> 
#> $Hresl$Mmatl
#>              [,1]
#>  [1,]  0.60175470
#>  [2,]  0.60546842
#>  [3,] -0.69928725
#>  [4,]  0.23800336
#>  [5,] -0.63023707
#>  [6,]  0.57675256
#>  [7,] -1.90587561
#>  [8,]  0.11862982
#>  [9,] -0.91688151
#> [10,]  1.00332789
#> [11,] -0.04498678
#> [12,]  0.71718313
#> [13,] -0.04663562
#> [14,] -0.79820067
#> [15,]  0.15814265
#> [16,]  0.11440149
#> [17,]  0.88194168
#> [18,]  0.17305918
#> [19,]  0.06622809
#> [20,]  0.04945037
#> [21,] -0.83212749
#> [22,] -0.86064059
#> [23,] -1.39749225
#> [24,] -0.13307560
#> [25,]  0.59539461
#> [26,]  1.42342915
#> [27,] -0.58213964
#> [28,] -0.60011650
#> [29,]  1.68903570
#> [30,]  0.74609832
#> [31,] -0.98531242
#> [32,]  0.65288681
#> [33,] -0.53382067
#> [34,]  1.43548279
#> [35,]  0.23938540
#> [36,] -0.27118807
#> [37,] -1.87683934
#> [38,] -1.15766686
#> [39,] -0.55370511
#> [40,]  0.65437202
#> [41,] -1.71220447
#> [42,] -0.44452441
#> [43,]  1.41777718
#> [44,]  0.56909026
#> [45,]  0.68603223
#> [46,]  0.35217058
#> [47,] -0.51443228
#> [48,]  1.32546957
#> [49,]  1.07408770
#> [50,] -0.66766543
#> 
#> 
#> $linearized
#>              [,1]
#>  [1,]  0.52600026
#>  [2,]  1.06111637
#>  [3,] -0.99967871
#>  [4,]  0.39359047
#>  [5,] -0.84317269
#>  [6,]  0.54039950
#>  [7,] -2.11923568
#>  [8,] -0.01723863
#>  [9,] -1.16648418
#> [10,]  0.71985067
#> [11,] -0.01914279
#> [12,]  0.98998430
#> [13,] -0.11326385
#> [14,] -0.74709909
#> [15,]  0.40337452
#> [16,] -0.22607592
#> [17,]  1.17063582
#> [18,]  0.15016544
#> [19,]  0.38580257
#> [20,]  0.30557329
#> [21,] -1.12747463
#> [22,] -0.86838644
#> [23,] -1.81952422
#> [24,]  0.23693029
#> [25,]  0.69831953
#> [26,]  2.11767033
#> [27,] -0.86574762
#> [28,] -0.70999639
#> [29,]  1.49923344
#> [30,]  1.09849637
#> [31,] -0.57291922
#> [32,]  0.80050848
#> [33,] -0.72947143
#> [34,]  1.47653453
#> [35,]  0.26563869
#> [36,] -0.40229794
#> [37,] -1.65300192
#> [38,] -1.57962467
#> [39,] -1.03112229
#> [40,]  1.09117667
#> [41,] -1.67939116
#> [42,] -0.76583703
#> [43,]  1.40370952
#> [44,]  0.43471192
#> [45,]  0.55206193
#> [46,]  0.24927154
#> [47,]  0.02053014
#> [48,]  1.37060369
#> [49,]  0.87939970
#> [50,] -0.78510345
#> 
#> $unpen
#> [1] FALSE
#> 
#> $intercept
#> [1] TRUE
#> 
#> $eta0
#> [1] 0
#> 
#> $X1
#>       [,1]
#>  [1,]    1
#>  [2,]    1
#>  [3,]    1
#>  [4,]    1
#>  [5,]    1
#>  [6,]    1
#>  [7,]    1
#>  [8,]    1
#>  [9,]    1
#> [10,]    1
#> [11,]    1
#> [12,]    1
#> [13,]    1
#> [14,]    1
#> [15,]    1
#> [16,]    1
#> [17,]    1
#> [18,]    1
#> [19,]    1
#> [20,]    1
#> [21,]    1
#> [22,]    1
#> [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,]    1
#> [40,]    1
#> [41,]    1
#> [42,]    1
#> [43,]    1
#> [44,]    1
#> [45,]    1
#> [46,]    1
#> [47,]    1
#> [48,]    1
#> [49,]    1
#> [50,]    1
#> 
#> $family
#> [1] "gaussian"
#> 
#> $penalties
#> [1]     51.12203 851416.48598 887650.39006     59.50577 901363.41321
#> 
#> $datablocks
#> $datablocks[[1]]
#>               [,1]        [,2]         [,3]         [,4]
#>  [1,] -0.272874129 -0.77974785  0.062379881  0.417538366
#>  [2,]  0.003785316 -2.62864860  0.450718038  0.836038471
#>  [3,]  0.791320562  0.92777344  0.162653560 -0.530208781
#>  [4,] -1.026060826 -0.12866061 -0.406774809  0.021106734
#>  [5,]  0.958517439 -2.43162719 -0.159627659  1.344097639
#>  [6,]  0.938547775 -0.55080607  0.449805837  0.093713321
#>  [7,]  1.607466482  0.01109094  1.748424886  1.217106031
#>  [8,] -0.072047553  0.03787462 -0.669982902  0.552034523
#>  [9,]  1.085482996 -0.84164056 -0.058588966  1.565809205
#> [10,] -0.091288489  0.87851623  1.450749558  0.212190818
#> [11,] -0.766565231  1.08673610  0.281392155 -0.525864558
#> [12,] -0.864316803 -0.69381898 -0.249068751 -2.846800488
#> [13,]  0.851547881  0.20136030 -0.349978848 -1.117460960
#> [14,]  0.535459811  0.10596696 -1.050386389 -1.546124285
#> [15,] -0.939604304  1.46541152  1.359457002 -0.972243020
#> [16,]  1.944437190  0.32447126 -0.946036328  0.175343876
#> [17,] -1.019596585  1.38283641  0.059455290 -0.818930819
#> [18,]  0.783175357 -0.08293317  0.904907846  0.484604769
#> [19,] -0.897566055  0.45120025  0.102267543  1.038116842
#> [20,] -0.950889699 -0.39428435 -0.624225102 -0.576870212
#> [21,]  0.323293452  1.55649194  0.401329719 -1.812007465
#> [22,]  1.137959119 -1.60045561 -1.803861310 -1.079149265
#> [23,]  0.939046678  1.38260693 -1.625623170  1.807231656
#> [24,] -1.131726693  0.72401333  0.349590104 -0.465782220
#> [25,] -1.254727505 -0.90116327  0.547398145  0.125903218
#> [26,] -1.576483719  0.89490587  0.971017592 -2.441304093
#> [27,]  0.198699129 -0.04144319  0.172555192  0.012001506
#> [28,] -0.323584360  0.41678405  1.698840385 -0.045066522
#> [29,]  1.301126597 -1.73895776  0.533812947  0.624581753
#> [30,] -1.211495713 -0.05418158 -0.067617314  0.036194393
#> [31,] -0.876825339  0.06665086  0.370674774 -0.574064073
#> [32,] -0.609080219  0.17711475 -0.002220751 -0.008639933
#> [33,] -0.641969525  0.24379539 -0.396776299  1.205764364
#> [34,]  0.377698446  0.05987094 -0.939828791  0.445782902
#> [35,] -0.840448090  0.09744734  1.222810167  0.071380164
#> [36,]  0.023999599 -0.06225028 -0.047021202  0.345414628
#> [37,] -0.728754270  1.24376820  1.342733532 -1.096345507
#> [38,]  0.651999890  0.46230575 -1.638096321  0.044595434
#> [39,]  2.464401310 -0.80110307 -3.239134398 -1.245052901
#> [40,] -2.528731671  1.06516280 -0.508344327 -0.162191777
#> [41,] -0.301588274 -0.40761523 -0.018696135  0.342265057
#> [42,]  0.160030101 -0.10565296  0.549125705  0.987525432
#> [43,] -0.098035064 -0.49563540 -1.190344396  1.132800940
#> [44,]  0.114950636  1.36648620 -0.444618823 -0.068852931
#> [45,]  1.359090417 -1.34378147  0.503747974  0.831426562
#> [46,]  0.649083749  0.24796228  1.740743178 -0.069927503
#> [47,] -1.184818638 -2.34924598  0.909827783  0.553185565
#> [48,]  0.402212806  0.08472049 -0.427291130 -0.646198173
#> [49,]  0.744072635  0.81567315  0.146904741  1.833665214
#> [50,] -0.138326619  0.65465484 -1.629179416  0.291666105
#> 
#> $datablocks[[2]]
#>               [,1]        [,2]        [,3]        [,4]
#>  [1,]  0.582152608  1.88309196 -1.47578898 -0.04385004
#>  [2,]  1.368546028  0.80132866 -0.43382537  0.35975731
#>  [3,] -0.365082593  1.37709000  0.52126734  0.47237553
#>  [4,]  0.773948892  0.04228898  0.14296430 -0.66215314
#>  [5,] -0.221636622 -0.37358931  0.68147982  0.33578616
#>  [6,]  1.264029201 -0.15989728  0.20052883  0.27898206
#>  [7,] -0.572842450 -0.03088137  2.83562799 -0.73599887
#>  [8,]  0.869652795 -1.21083448 -1.30145428  1.20495991
#>  [9,]  2.474553832  0.08879514  0.19017467  0.14515649
#> [10,] -1.850619162 -1.30706472 -0.20924233  0.15681251
#> [11,] -0.878728168  1.37539381 -0.09385463  0.07591919
#> [12,] -0.007548629 -2.39755914  0.28699874 -0.05193435
#> [13,]  0.485284781  0.92684985 -1.45039951 -0.50601985
#> [14,] -1.434682166  1.07907833 -1.76928102 -0.96753777
#> [15,] -1.122803302  0.16446246  0.61790488  0.50608071
#> [16,]  0.412221118  1.35127241  0.06350142  1.77741913
#> [17,] -0.161947781 -0.92413288  0.58219024  1.54715226
#> [18,] -0.642583475 -0.44501434 -0.83951664  0.50717312
#> [19,]  0.027834986 -0.14091769 -0.20388142 -1.34884648
#> [20,] -0.105953145 -1.66788853 -0.43550483  1.54284972
#> [21,]  1.742083075  0.41822983  0.26726752  1.50665509
#> [22,] -1.100659357  0.50395746  0.52049982  0.21571612
#> [23,] -0.328103436 -1.18231291  0.03864355 -2.95517749
#> [24,]  1.301484255  0.69831203 -0.05423161 -0.89325724
#> [25,] -0.779603173 -1.03491534 -0.12901361  0.50619564
#> [26,] -0.634664025 -0.45485082  2.09107401 -0.43682717
#> [27,] -0.577952580 -0.34819795 -2.27768680 -1.11862693
#> [28,] -0.806356541  0.44796979  2.44722923  0.27087933
#> [29,] -2.578292568  0.46304146 -0.41508973  0.76187141
#> [30,]  1.352578647  0.12117085  0.63272694  0.89633566
#> [31,]  0.018477071 -1.17425703  0.41244138  0.73273052
#> [32,]  1.020408406 -1.35807370 -0.34817616 -0.39623158
#> [33,]  0.474295257  1.76484877  0.02882642 -0.53952819
#> [34,]  0.156719892 -0.04109045 -1.03025126 -0.20654031
#> [35,]  0.084487851  0.83718495 -0.53651271  0.89655994
#> [36,] -2.122882374 -0.59969928  1.78575735 -1.49431497
#> [37,]  0.235138673  0.37273488 -0.52841675  0.75344296
#> [38,]  0.356263568 -0.85002186  0.63987765  0.30821968
#> [39,]  0.265596138  0.67492679  0.17723565 -2.27424527
#> [40,] -0.190589986  0.35864578 -0.47388219 -0.02072445
#> [41,] -0.693417324 -1.11768685 -0.26094365 -0.41177498
#> [42,]  0.414637404  1.13698714 -0.02574485  0.94108366
#> [43,]  0.392580062 -0.90760405  0.53528202 -0.90685613
#> [44,]  1.191141962  1.17804168 -0.63194201  1.42528368
#> [45,]  0.136166121 -0.25598012 -1.96971444 -1.04446925
#> [46,] -0.112844676  1.88333128  0.52226857 -0.93280726
#> [47,]  0.822542941 -1.03686882  1.12538749 -1.33253562
#> [48,]  0.501027651  0.20689618 -0.41022112 -0.21130676
#> [49,]  0.283492785  0.16521173  0.44413038 -0.01837514
#> [50,] -1.717552468 -1.30180328 -0.48671034  1.38454146
#> 
#> $datablocks[[3]]
#>               [,1]         [,2]        [,3]        [,4]
#>  [1,]  1.755957758  0.693666122  0.31321245  1.37757785
#>  [2,] -0.886345024  0.777324869  1.36519943 -1.24707805
#>  [3,] -2.029785236 -0.239898331 -0.91419804  0.68477773
#>  [4,]  1.170386975 -0.137507943 -0.13479887 -0.62985256
#>  [5,]  0.020577665 -0.177348746 -1.44889354 -0.02811236
#>  [6,] -0.602915874 -2.148510191  0.09684095 -0.54484045
#>  [7,] -1.336039286 -1.130758707  0.17825806  0.76860455
#>  [8,]  1.358983411 -0.835431171  0.17733944  0.32593340
#>  [9,] -1.243310998  1.470403956  1.35844041  1.60059847
#> [10,]  0.721183290  0.229334880  0.01141419 -1.33061527
#> [11,]  0.903796004 -0.244989345  0.72055379 -1.74114642
#> [12,]  0.828681142 -1.073515824  2.60413604 -1.10211086
#> [13,] -0.163283450 -0.952953077 -0.62234773  0.76396324
#> [14,]  0.977490408  0.879147294  1.50269642 -0.24962126
#> [15,]  1.283455057 -0.607363221  1.81255629  0.48558378
#> [16,]  0.354934540 -0.582089587  0.18545327  0.81688280
#> [17,]  1.296833575  1.041000917 -2.64152659 -0.08749482
#> [18,]  0.003873466  1.124285949 -0.80157754  0.46282299
#> [19,] -1.582237299 -0.823982216 -0.77157976 -0.20638679
#> [20,] -0.926891739 -0.001831482  0.98738218 -1.00210179
#> [21,]  0.080384486 -0.040705159  0.03821321 -0.93944482
#> [22,] -1.410355518 -0.121396575 -0.21284200 -1.19231764
#> [23,] -1.562903559 -0.134306961 -1.47048029  0.95849756
#> [24,] -0.647319926  1.562370080 -1.45279443 -0.04128580
#> [25,] -0.667471366  0.849505015  0.21563918  1.91420345
#> [26,] -1.004088488 -0.397734028 -0.68116870  0.96208527
#> [27,] -1.006901410 -0.951969973  1.12367318  0.20393346
#> [28,] -0.403974913 -1.362257954  0.13937252  0.75614233
#> [29,] -0.390142683  0.820503652 -1.78081174 -1.53046251
#> [30,] -0.713915217  0.776060532  0.14376166 -2.27134909
#> [31,] -1.193864565  1.236148496  0.78239536  0.01122164
#> [32,] -1.307843209 -1.961053927  0.75151205  0.80919434
#> [33,]  0.717104348  0.190407236 -1.69530663  0.95033449
#> [34,]  0.565849848  0.127550631 -0.06665961  0.06690798
#> [35,]  1.335703268 -1.565080277  1.28931081  0.64272577
#> [36,] -0.651655426 -0.675646041 -1.17335620  0.30092378
#> [37,]  0.745181134  0.783422045  0.54820459 -0.54123114
#> [38,]  0.901576348  1.009578103  1.11404546 -0.94191029
#> [39,]  0.644064421 -0.381917361  0.17378297 -2.79145147
#> [40,] -0.112396022  0.963475131 -0.39393899  0.69155170
#> [41,]  1.845758098 -0.412457156  0.26184891  0.30812588
#> [42,]  0.388916252  0.609062351 -0.65153790  0.40116665
#> [43,]  0.849754246 -2.104475649  0.52177095 -1.15590500
#> [44,]  1.124527528 -0.058972998 -0.61975092  1.42171668
#> [45,]  0.057521751  0.732617327 -0.16735928  0.06361962
#> [46,]  1.028030573  1.776509623  0.09616595 -0.07258061
#> [47,] -0.026892719 -0.035112237 -0.59112740  0.80892820
#> [48,] -0.420999187  0.133500616  0.05634609  0.70156685
#> [49,]  0.422168567  2.154864770 -0.19786404  0.18179961
#> [50,] -1.091161043 -0.781473457 -0.07960562  0.20590894
#> 
#> $datablocks[[4]]
#>             [,1]         [,2]        [,3]        [,4]
#>  [1,]  1.3394370 -0.548122842  0.66272922  0.41988435
#>  [2,] -0.4079333  2.221326249 -0.24333286 -0.10158125
#>  [3,] -0.2993781 -0.061290129  1.50581863  1.05411922
#>  [4,] -2.5099292 -0.337039328 -0.79314422  0.65733116
#>  [5,]  3.1608823 -1.076097376 -0.03057458 -0.82670361
#>  [6,]  0.2311184  0.013801127  0.42964465 -0.89748422
#>  [7,] -2.0974247  0.125599980  0.02690058  0.73776742
#>  [8,]  0.3318435 -0.119233647  0.16469089  0.59628507
#>  [9,] -0.9505143 -0.496521047 -0.27926162  0.30730536
#> [10,]  1.2533320 -1.912703834  0.72027222  0.39942386
#> [11,] -0.9549741 -0.894141159  1.10600993 -0.38334350
#> [12,] -0.3813977 -0.892711517 -0.21600960 -0.68832089
#> [13,]  0.9638576  1.501704666 -2.06167590  1.50829698
#> [14,] -0.2079859  2.121284428  2.07197637  0.57217011
#> [15,] -0.9468655  0.635557564  0.27268533  0.39255824
#> [16,]  0.2765178  0.577255050 -2.28262498  0.48046427
#> [17,] -0.7287412  1.063751815  0.36330684 -0.34015289
#> [18,]  0.5049800  0.731718352 -0.32510961  0.08872098
#> [19,] -0.4892622  0.166610685  0.35123267 -2.28890285
#> [20,] -0.4035885 -0.759816688 -0.07000111 -1.71191770
#> [21,]  0.2709237 -1.247505199 -1.34755573  1.29223149
#> [22,]  0.1231153 -0.396775794 -1.10105085 -1.80151869
#> [23,]  1.2925813  0.428878223 -1.24691374  0.46939187
#> [24,] -0.6062756  1.784466457  0.02804806  0.47854204
#> [25,]  1.7809148 -0.640103888  1.18834590  0.42483653
#> [26,] -0.6062660  1.614810807  0.74217436 -1.48899962
#> [27,] -0.1291466 -2.227793628 -0.97403653  0.32731054
#> [28,] -1.7779335 -1.430922370  1.00596953  1.07447590
#> [29,] -1.4751139 -0.920030571 -0.19039449  0.31665289
#> [30,]  0.3043030  0.333624098  0.80085217 -1.51839602
#> [31,] -0.7076127  0.366985352  0.47998039 -1.85899750
#> [32,]  0.6145904  0.050874542  0.13275611 -0.77649565
#> [33,]  0.6222170 -0.629137206 -0.74596853  1.56952061
#> [34,]  0.3804210  1.292910311 -1.83168703  0.06836384
#> [35,]  0.1306561 -0.689598437  1.29476793  0.67002836
#> [36,]  0.1019130 -0.325018725  0.05187243  0.78109944
#> [37,]  1.4069380 -0.226708718 -0.55222611 -1.19959891
#> [38,]  0.7744618  0.196685939  1.00949849  1.67797876
#> [39,] -0.5724209 -0.454340798 -1.05850019 -0.44611967
#> [40,]  0.2760836  0.443500061 -0.31116804 -0.50053711
#> [41,] -0.1739748 -0.628650762 -0.63880859 -0.23190529
#> [42,] -0.8812925 -0.769656529  2.59378958  1.73216164
#> [43,] -0.1630163  0.623477697 -0.86618357  0.51825403
#> [44,]  0.1682385  0.283080710  0.27250265  0.23364596
#> [45,]  0.9225208 -0.004855686 -0.91506805 -0.19087761
#> [46,]  0.4741834 -1.772795876  0.34876312 -1.65104557
#> [47,]  0.4998573  1.163179606  0.57757152 -0.42010686
#> [48,] -0.1249920  0.002401706 -1.29603699 -0.86825736
#> [49,] -1.1733610  1.316899652  0.32073201  1.39060627
#> [50,]  0.5635131  0.401186677  0.85444135 -0.04816444
#> 
#> $datablocks[[5]]
#>              [,1]        [,2]        [,3]        [,4]
#>  [1,] -0.15658804 -1.64341065 -0.12761058  1.96327745
#>  [2,]  0.34571756  0.63501745  0.02586801 -0.47968810
#>  [3,] -0.22382519 -0.49498281  0.35022592  0.30340165
#>  [4,]  0.10768165 -1.04483018  1.15216935  0.55051576
#>  [5,]  0.01133986 -1.05530470 -0.20554686 -0.21842985
#>  [6,]  1.28838568 -0.14360358  1.13668606 -1.21591079
#>  [7,] -2.97842957 -0.77122459  0.31134629  0.94949578
#>  [8,] -0.15868903 -0.75877835 -0.80614572  0.20906314
#>  [9,]  0.09845873  0.59125342  0.46862875 -0.73643943
#> [10,] -0.47002455  0.75170171  1.23180407  0.86875207
#> [11,] -0.26321507 -0.82150822  1.20767032  1.00458440
#> [12,]  0.56201571 -0.10578839  0.86777159  1.86554746
#> [13,]  0.59245620 -1.15106245 -1.26549802  0.39829451
#> [14,] -0.59946420 -0.30545137 -0.09411711 -0.11813923
#> [15,] -0.65355770  1.04993883 -0.06664862 -1.29469971
#> [16,] -0.61043647  2.15641350 -0.73954498 -0.55844962
#> [17,] -0.77402744  1.80301740 -1.18280968 -1.35160754
#> [18,] -1.23957874  1.33040717 -0.07669461  0.84849267
#> [19,]  0.62024640 -1.12527851 -0.28108143 -0.49244441
#> [20,]  0.40840038 -1.13491704  0.42473328 -0.73864657
#> [21,]  0.28577523 -0.53231545 -2.01281796  0.43570845
#> [22,]  0.02179173  1.35467576 -0.03610141  1.38615471
#> [23,]  0.32025732 -0.17886672  1.24265129 -0.59061310
#> [24,] -1.29877381  0.13523071  1.40493225 -0.53088908
#> [25,] -0.69596714 -0.96735481 -0.49605393  0.60508683
#> [26,]  0.11676871 -0.89563830 -1.10625050 -0.39551880
#> [27,]  0.80069351 -1.26166667 -1.54550721  1.78145198
#> [28,]  0.18081087  1.06047366  0.78019364 -1.16668507
#> [29,]  0.83551859  0.29616784 -0.54594387 -0.10108953
#> [30,]  1.06949630  0.91123077 -1.19838511  1.15600036
#> [31,]  0.42531444  1.23850749 -0.71740518 -0.12008486
#> [32,]  1.06445465  0.27290761  1.62991260 -0.85950410
#> [33,] -0.89449854  0.03222071 -0.34008522 -0.52637671
#> [34,]  0.06421033 -1.83498567 -1.06029568  0.40037700
#> [35,] -0.74288731 -0.21275039 -0.72990840  0.70024693
#> [36,] -1.19345352 -0.58883243 -0.26420081  0.74768091
#> [37,]  2.38481903 -0.66365314  0.62964912 -0.30240298
#> [38,]  0.61014948  0.01787445 -0.07865154 -0.12043874
#> [39,]  0.81824528  1.96173195  0.70236366  0.42167704
#> [40,] -2.50298878  0.74958303 -0.62296097 -1.86345239
#> [41,] -0.98040298 -1.29234936 -0.87497831 -1.25421228
#> [42,]  0.75378620  0.83235708  1.86448741  2.61683726
#> [43,]  1.63608674  0.25371754  1.40854633 -0.62603387
#> [44,] -0.38304698  0.92359654  1.45732967  0.57558631
#> [45,]  0.52196210  1.49303577 -0.34723401 -2.18380712
#> [46,]  1.11976838 -1.09917619 -0.35701581  0.05615334
#> [47,]  1.22655078  0.29702836 -1.49902556 -1.18518893
#> [48,]  0.62532543 -0.48177872  2.13571794 -0.16155692
#> [49,] -0.18851327 -0.50609444 -0.30142897 -0.14542935
#> [50,] -1.90811894  0.92351436 -1.45273946 -0.50664691
#> 
#> 
#> $z
#>  [1] 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5
#> 
#> $pars
#> $pars$family
#> [1] "gaussian"
#> 
#> $pars$mu.x
#>  [1] -0.097667072  0.148627602 -0.204766160  0.114856049  0.140819407
#>  [6] -0.039024518 -0.226590441 -0.029456674 -0.054433777  0.123022485
#> [11] -0.301635586  0.014430531 -0.047136283  0.145619690 -0.008746103
#> [16] -0.227864069 -0.128374650 -0.047985912  0.087451493  0.177483334
#> 
#> $pars$sd.x
#>  [1] 1.0486081 1.0988684 1.2317780 0.9843618 0.9953675 0.9552539 1.0532382
#>  [8] 0.9877092 1.0223840 0.9716549 0.9669785 0.7704978 0.8967902 0.9864069
#> [15] 0.8843963 0.9234467 1.0084955 0.9665513 0.9997043 1.1051125
#> 
#> $pars$mu.y
#> [1] 0.0885226
#> 
#> $pars$sd.y
#> [1] 0.9607169
#> 
#> 
#> attr(,"class")
#> [1] "multiridge"

# \donttest{
# simulation
set.seed(1)
n0 <- 100
n1 <- 10000
n <- n0 + n1
p <- c(100, 50)
z <- rep(x = seq_along(p), times = p)
x <- sapply(X = z, FUN = function(x) stats::rnorm(n = n, sd = x))
beta <- stats::rnorm(n = sum(p), mean = 1, sd = 0) *
        stats::rbinom(n = sum(p), size = 1, prob = 0.2)
eta <- x %*% beta
family <- "gaussian"
if (identical(family, "gaussian")) {
  y <- eta + 0.5 * stats::rnorm(n = n, sd = stats::sd(eta))
} else if (identical(family, "binomial")) {
  y <- stats::rbinom(n = n, size = 1, prob = 1 / (1 + exp(-eta)))
} else if (identical(family, "cox")) {
  time <- stats::rexp(n = n, rate = exp(eta))
  status <- stats::rbinom(n = n, prob = 0.5, size = 1)
  y <- survival::Surv(time = time, event = status)
}
cond <- rep(x = c(TRUE, FALSE), times = c(n0, n1))

y_hat <- coef <- list()

# standard ridge regression
object <- glmnet::cv.glmnet(x = x[cond, ], y = y[cond],
                           family = family, alpha = 0)
coef$glmnet <- stats::coef(object = object, s = "lambda.min")
y_hat$glmnet <- stats::predict(object = object, newx = x[!cond, ],
                              type = "response", s = "lambda.min")

# multi-penalty ridge regression
object <- multiridge(x = x[cond, ], y = y[cond], z = z, family = family)
coef$multiridge <- stats::coef(object = object)
y_hat$multiridge <- stats::predict(object = object, newx = x[!cond, ])

# estimation performance
sapply(coef, function(x) stats::cor(beta, x[-1]))
#>     glmnet multiridge 
#>  0.4692074  0.5982584 
sapply(coef, function(x) mean((beta-x[-1])^2))
#>     glmnet multiridge 
#>  0.1718059  0.1262343 

# predictive performance
if (identical(family, "gaussian")) {
  metric <- sapply(X = y_hat, FUN = function(x)
    mean((x-y[!cond])^2))
} else if (identical(family, "binomial")) {
  metric <- sapply(X = y_hat, FUN = function(x)
    pROC::auc(response = y[!cond],
              predictor = as.vector(x),
              levels = c(0, 1),
              direction = "<"))
} else if (identical(family, "cox")) {
  metric <- sapply(X = y_hat, FUN = function(x)
    survival::concordance(y[!cond]~I(-x))$concordance)
}
metric
#>     glmnet multiridge 
#>   73.65774   50.10826 
# }