Skip to content

Commit 33ae2ce

Browse files
trevorhastiecran-robot
authored andcommitted
version 4.1-2
1 parent f4fc95a commit 33ae2ce

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+3114
-2342
lines changed

DESCRIPTION

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
Package: glmnet
22
Type: Package
33
Title: Lasso and Elastic-Net Regularized Generalized Linear Models
4-
Version: 4.1-1
5-
Date: 2021-02-17
4+
Version: 4.1-2
5+
Date: 2021-06-21
66
Authors@R: c(person("Jerome", "Friedman", role=c("aut")),
77
person("Trevor", "Hastie", role=c("aut", "cre"), email = "[email protected]"),
88
person("Rob", "Tibshirani", role=c("aut")),
@@ -22,7 +22,7 @@ URL: https://glmnet.stanford.edu,
2222
https://dx.doi.org/10.18637/jss.v039.i05
2323
RoxygenNote: 7.1.1
2424
NeedsCompilation: yes
25-
Packaged: 2021-02-18 01:22:34 UTC; hastie
25+
Packaged: 2021-06-22 19:59:09 UTC; hastie
2626
Author: Jerome Friedman [aut],
2727
Trevor Hastie [aut, cre],
2828
Rob Tibshirani [aut],
@@ -32,4 +32,4 @@ Author: Jerome Friedman [aut],
3232
Junyang Qian [ctb]
3333
Maintainer: Trevor Hastie <[email protected]>
3434
Repository: CRAN
35-
Date/Publication: 2021-02-21 17:40:03 UTC
35+
Date/Publication: 2021-06-24 06:30:11 UTC

MD5

Lines changed: 44 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
1c79ad913d0f27ee763728e18f7884bc *DESCRIPTION
1+
405719048147a83a40afd4658a2e83c6 *DESCRIPTION
22
a4e9841f3d7c3df90e1e5e013d53e5ec *NAMESPACE
3-
a1debac8a87a4bf3cb4e29c5c169341e *NEWS.md
3+
8173da17d52644d17b983af8304e9936 *NEWS.md
44
b7e403cbac1975dfabbd5b1e6ec68cfc *R/Cindex.R
55
4bd3eb09b5b5e4d5dd4a6d885c734b0d *R/assess.coxnet.R
6-
2f177df723d0565cbae683046d5ad550 *R/assess.glmnet.R
6+
7172891b9097b44ef3d8951153eee111 *R/assess.glmnet.R
77
6d3a93c6972ccbfee9aa0c264cb08ad3 *R/auc.R
88
8cd96999dce298c1d81ce51ea2f6d2a3 *R/auc.mat.R
99
8b2f65e1c21c123294a132887081c627 *R/bigGlm.R
@@ -12,6 +12,7 @@ d8808544bfbafb423ce60e359ade4b64 *R/blend.relaxed.R
1212
70162e7910431ac9e89fcb5526469b84 *R/buildPredmat.coxnetlist.R
1313
019453d01483ecda68866eaa73e1df3c *R/buildPredmat.default.R
1414
885a478709d197d973cdc621cd3e5225 *R/check.dots.R
15+
612fef55db8dfaf923f5b986d8dad11e *R/check.exclude.R
1516
05d1834f8f3dc30e0428eb6d1dcb1ba1 *R/coef.cv.glmnet.R
1617
da1e68b0c4ae43a6ffcaa2ea3d7c287a *R/coef.cv.relaxed.R
1718
f288cf974491d93b56e5c4d6d204d658 *R/coef.glmnet.R
@@ -35,6 +36,7 @@ ece778c00ca6b58e088f6a700d23e15b *R/cv.multnet.R
3536
c739878e7fc617dab75e8cd65cf9b356 *R/cvcompute.R
3637
2b98d1871792cda71bd9323e9ee2a0b0 *R/cvstats.R
3738
90e2fb9130f89ddaef65e43202dc4261 *R/cvtype.R
39+
9a25662a16138900203c201bb4bd057b *R/data.R
3840
959eaac0e190795f3ee1ced251d60a90 *R/deviance.glmnet.R
3941
fb1ae53f9285f39d93592b6a0de61f6f *R/elnet.R
4042
0c6c0b1dfa5c98b55f2e9e097df3747d *R/error.bars.R
@@ -45,8 +47,8 @@ c65547cba8e3d5ad16b28a84881e7fca *R/getOptcv.glmnet.R
4547
b0325f5e584fbe646aedb73d02f6b86d *R/getOptcv.relaxed.R
4648
dd14d7acb21ae8f1bb87a54ea763950b *R/getcoef.R
4749
c1a8bceef71c915555f8bffc7298137e *R/getcoef.multinomial.R
48-
cc5c36c94de80e5399ef2db9355d4b09 *R/glmnet-package.R
49-
86176ceaf91d77a9f843143c05d38bc0 *R/glmnet.R
50+
495b7a692179c35799664c5510e04f3f *R/glmnet-package.R
51+
0b3c808ebf16acd3be2f7d5a83f2a69c *R/glmnet.R
5052
e0da0e93d1a87cc5d5342050a15e6354 *R/glmnet.control.R
5153
741a587449cd2f3613c2e52f25bc0280 *R/glmnet.measures.R
5254
d3b6ab46fd14433716fdc40cfd72807c *R/glmnetFlex.R
@@ -73,11 +75,11 @@ ea50b48783cf8f7f19578990a2fcd656 *R/plot.mrelnet.R
7375
18015a23b5efc79de433ac2b1fa5746a *R/plot.relaxed.R
7476
636feb1ac600bb09dccdfabfecc52c1d *R/plotCoef.R
7577
fa0986bb58c46a8481b78b877a6e7636 *R/predict.coxnet.R
76-
c56faa301b0f15275d45b356b364e2c6 *R/predict.cv.glmnet.R
77-
e4f6bd75906fdb9c58057143edbacbe5 *R/predict.cv.relaxed.R
78+
56a20beb9e09cba4456a611d6e385ca4 *R/predict.cv.glmnet.R
79+
46ef747bea2ff68cef5ef2ffbb5bb466 *R/predict.cv.relaxed.R
7880
459ca7b37d845f842e8b5681a2e3a5aa *R/predict.elnet.R
7981
0f470237229a0f3b973d29ef3683d73b *R/predict.fishnet.R
80-
fd9ff0509dd08f46b0d98d933bb0f02e *R/predict.glmnet.R
82+
1702dafa0f89817b8c77d231ad9224c3 *R/predict.glmnet.R
8183
3272244ba2c54519d973d5a4cbc2df8a *R/predict.lognet.R
8284
1bc0c68ce624df57b07bdabfd1e84597 *R/predict.mrelnet.R
8385
02fc6050ced4badab91cc882e06f3bb5 *R/predict.multnet.R
@@ -96,35 +98,42 @@ e44a2d10d5135f6931a13542d8996d56 *R/survfit.coxnet.R
9698
e2f22c34e46e1ec2964d1968e7116342 *R/survfit.cv.glmnet.R
9799
0d040824da1ffcd1edb57b252f6b1f6e *R/zeromat.R
98100
8920f300fb3d337d7048ef8af005d41e *README.md
99-
9305e0262835e4bf9ec618fb06fe020b *build/vignette.rds
100-
058ca4ea844ab733e99395fa1488546b *data/BinomialExample.RData
101+
70bc1a33f67d10989622ea3f4e680ebb *build/vignette.rds
102+
0814c5a080c9ba7874362051b6cbd89f *data/BinomialExample.rda
101103
7a404bc6a255ac95a6cc06cf4fe6ddbf *data/CVXResults.RData
102-
64d84fd86c91dfde6cbda5f13da82327 *data/CoxExample.RData
103-
2740a6e77cb5875cca0de3f5a6b2c2ed *data/MultiGaussianExample.RData
104-
f00302d6b4d512cd1f24c30c21335211 *data/MultinomialExample.RData
105-
c4f36770e60c6421603e9933930fec06 *data/PoissonExample.RData
106-
beaffe6c0ae597f8803216e3bbd4a2d1 *data/QuickStartExample.RData
107-
7056d5f98a624c060d0522045f1b68f8 *data/SparseExample.RData
104+
9497636bb0edb7f76c792f33c47ba681 *data/CoxExample.rda
105+
a72ec47b364e0eb3a85fc2d402c7ac16 *data/MultiGaussianExample.rda
106+
892fa8ad5b2ff24f9c989ebcec41bfb8 *data/MultinomialExample.rda
107+
cac6b8e217715098a5ee94e4066c1a4b *data/PoissonExample.rda
108+
35754bd4878bc234696cc2d9b880d90e *data/QuickStartExample.rda
109+
54067bd791ff172cff97ff9d26b6de12 *data/SparseExample.rda
108110
edcd84fb25d51203916ae3a39b1fc655 *inst/CITATION
109-
c2a99f2de8eaafe08dcdfdb754e1772e *inst/doc/Coxnet.R
110-
fae7a9d02341e6576b9560e26701ad9b *inst/doc/Coxnet.Rmd
111-
0190e2afe30e6b71eb740dd027b0918f *inst/doc/Coxnet.pdf
112-
2d93b78f53f037a964659ffaabe3aaac *inst/doc/glmnet.R
113-
bdb8b818d178d74a2af22608038932a1 *inst/doc/glmnet.Rmd
114-
731c80df0edc379d7a22fd2c85b002f7 *inst/doc/glmnet.pdf
111+
a93a7d8728d7660982e08bba82f720dc *inst/doc/Coxnet.R
112+
0bb3a929eff4b5695d75d5c08ae8360c *inst/doc/Coxnet.Rmd
113+
d8a790a361d27e7edd1988cf9728630a *inst/doc/Coxnet.pdf
114+
9ae5eaa92f330dbf58b156e1b5871dda *inst/doc/glmnet.R
115+
79ccc7b5e10f841e74ed9612b0e10cfd *inst/doc/glmnet.Rmd
116+
d00ef4196b199e0b00d9627b81487273 *inst/doc/glmnet.pdf
115117
85579e41e7c36b006e98a47bb0ca7f6f *inst/doc/glmnetFamily.R
116118
cab72afa072399ca5ae1906987ef89f4 *inst/doc/glmnetFamily.Rmd
117-
3f91549589947d5815b735619ea0cba7 *inst/doc/glmnetFamily.pdf
118-
4a3dfcb5e091bb6803bf35f9c689c16f *inst/doc/relax.R
119-
690ad421e350cde18389898140f41325 *inst/doc/relax.Rmd
120-
105554c99d10a7e387cc9305d54512ac *inst/doc/relax.pdf
121-
6b106667c04d867e9c1e279eedeff266 *inst/mortran/README.Rmd
122-
eca43bff4d1443c399d8305003777a9b *inst/mortran/glmnet5dpclean.m
119+
a79621fc63d35dbb310cf2c88dd6f2ef *inst/doc/glmnetFamily.pdf
120+
f3b0466d566df6079e63fe164a809f82 *inst/doc/relax.R
121+
e1dc532562ac69525a0b9c3c095be562 *inst/doc/relax.Rmd
122+
dc7816a0686ee4acc325cbbc3e10c2d6 *inst/doc/relax.pdf
123+
64c471277309951b4697ffdd1ee15fb8 *inst/mortran/README.Rmd
124+
a475108243c0db9c33089a0275c7eaba *inst/mortran/glmnet5dpclean.m
123125
d8516f118db49ea4fbde5d5b2f6e67a6 *inst/mortran/wls.m
124126
52e95162e7dc0e62ec329602b05cd001 *inst/testscripts/save_results.R
127+
6e03129049a39674c7ea15de8339511d *man/BinomialExample.Rd
125128
5a4389a6279bf8f6db41b6c7c5862bf9 *man/Cindex.Rd
126-
dbc0b807ae35fcb67ab8f8f849daa1d2 *man/assess.glmnet.Rd
127-
d0a7f0da9827e41030fd7644b421bb58 *man/beta_CVX.Rd
129+
9f14f46f2d349831ddf8fd8958bf69ef *man/CoxExample.Rd
130+
e472e3fbbaa3c1286891a59a561123ad *man/MultiGaussianExample.Rd
131+
2023e16a435a534ce184ddbb01a04bb7 *man/MultinomialExample.Rd
132+
287fe75c09580f4475f97e6a4653a2ca *man/PoissonExample.Rd
133+
81a89d362e387093991343cbbe045fce *man/QuickStartExample.Rd
134+
d9cb26ef685c853112acfa17afee001f *man/SparseExample.Rd
135+
db803cacf2e2783af427a53ae29000de *man/assess.glmnet.Rd
136+
404ddf86d813ed00f2ddfaf0cc88bf5f *man/beta_CVX.Rd
128137
413f29637810f0c84718ca2f5bb00ab1 *man/bigGlm.Rd
129138
9b08d40ce7e666b059b2679f2c878d9f *man/cox.fit.Rd
130139
e6388e65131a54875a8f44c9e536e17e *man/cox.path.Rd
@@ -142,7 +151,7 @@ d465886739abcf9ba23dd6928504e073 *man/elnet.fit.Rd
142151
1e9b7d5537b29ef0a4c097e26e0fb2a7 *man/get_start.Rd
143152
ec561c83a75b43232a6a10335e911ac3 *man/glmnet-internal.Rd
144153
d6e356e0500e6f9f2678cb03f2ec828d *man/glmnet-package.Rd
145-
322ad6277d1da769781a9d18404ddf25 *man/glmnet.Rd
154+
3011fcd9b2eed1ab588f6f17c8b01125 *man/glmnet.Rd
146155
5cc46f5cf2cc5389a89709d6ae129d0c *man/glmnet.control.Rd
147156
6d468edc0d0317c2098d27c64e17955e *man/glmnet.fit.Rd
148157
fed187cbcdf90f65defb1e5de08b3539 *man/glmnet.measures.Rd
@@ -167,15 +176,15 @@ a62678b3f19900ec74d299d7eebafbd7 *man/stratifySurv.Rd
167176
f2447246ed1bc0682526b694b2ff1daa *man/survfit.cv.glmnet.Rd
168177
24b1289dbc6e8d8bcc0a90fe57286599 *man/use.cox.path.Rd
169178
ef3f52f020e0348152d26890bb7e717e *man/weighted_mean_sd.Rd
170-
496f9de703e1b3d9ce71d4039b0ecaf8 *src/glmnet5dpclean.f
179+
df1527bce45036b9b3b532e9c376f645 *src/glmnet5dpclean.f
171180
32b239d462d1f062fe7389da6d2b2a27 *src/glmnet_init.c
172181
3965fc0eb8205870ea724035d96d8945 *src/pb.c
173182
f2fefcc9ad61b762fa701181df5ab618 *src/wls.f
174-
fae7a9d02341e6576b9560e26701ad9b *vignettes/Coxnet.Rmd
183+
0bb3a929eff4b5695d75d5c08ae8360c *vignettes/Coxnet.Rmd
175184
789121c8d4e2c1681d05f19d7a69a054 *vignettes/assets/coxnet.RDS
176185
3969a7d30dda77ddac9a8dcea40f8f58 *vignettes/assets/glmnet_refs.bib
177186
6b485f932628ec1755201811c3e05f49 *vignettes/assets/vignette_binomial.png
178187
3f2e5f9cf200b832dd68492f66f63f9e *vignettes/assets/vignette_gaussian.png
179-
bdb8b818d178d74a2af22608038932a1 *vignettes/glmnet.Rmd
188+
79ccc7b5e10f841e74ed9612b0e10cfd *vignettes/glmnet.Rmd
180189
cab72afa072399ca5ae1906987ef89f4 *vignettes/glmnetFamily.Rmd
181-
690ad421e350cde18389898140f41325 *vignettes/relax.Rmd
190+
e1dc532562ac69525a0b9c3c095be562 *vignettes/relax.Rmd

NEWS.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
# glmnet 4.1-2
2+
3+
A new feature added, as well as some minor fixes to documentation.
4+
* The exclude argument has come to life. Users can now pass a function
5+
that can take arguments x, y and weights, or a subset of these, for
6+
filtering variables. Details in documentation and vignette.
7+
* Prediction with single `newx` observation failed before. This is
8+
fixed.
9+
* Labeling of predictions from `cv.glmnet` improved.
10+
* Fixed a bug in mortran/fortran that caused program to loop ad infinitum
11+
112
# glmnet 4.1-1
213

314
Fixed some bugs in the coxpath function to do with sparse X.

R/assess.glmnet.R

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
#'
1919
#' @aliases assess.glmnet confusion.glmnet roc.glmnet
2020
#' @param object Fitted \code{"glmnet"} or \code{"cv.glmnet"}, \code{"relaxed"}
21-
#' or \code{"cv.relaxed"} object, or a matrix of predictions (for
21+
#' or \code{"cv.relaxed"} object, OR a matrix of predictions (for
2222
#' \code{roc.glmnet} or \code{assess.glmnet}). For \code{roc.glmnet} the model
2323
#' must be a 'binomial', and for \code{confusion.glmnet} must be either
2424
#' 'binomial' or 'multinomial'
@@ -42,6 +42,7 @@
4242
#' @examples
4343
#'
4444
#' data(QuickStartExample)
45+
#' x <- QuickStartExample$x; y <- QuickStartExample$y
4546
#' set.seed(11)
4647
#' train = sample(seq(length(y)),70,replace=FALSE)
4748
#' fit1 = glmnet(x[train,], y[train])
@@ -53,13 +54,15 @@
5354
#' plot(fit1c$lambda, log="x",fit1a$mae,xlab="Log Lambda",ylab="Mean Absolute Error")
5455
#' abline(v=fit1c$lambda.min, lty=2, col="red")
5556
#' data(BinomialExample)
57+
#' x <- BinomialExample$x; y <- BinomialExample$y
5658
#' fit2 = glmnet(x[train,], y[train], family = "binomial")
5759
#' assess.glmnet(fit2,newx = x[-train,], newy=y[-train], s=0.1)
5860
#' plot(roc.glmnet(fit2, newx = x[-train,], newy=y[-train])[[10]])
5961
#' fit2c = cv.glmnet(x, y, family = "binomial", keep=TRUE)
6062
#' idmin = match(fit2c$lambda.min, fit2c$lambda)
6163
#' plot(roc.glmnet(fit2c$fit.preval, newy = y)[[idmin]])
6264
#' data(MultinomialExample)
65+
#' x <- MultinomialExample$x; y <- MultinomialExample$y
6366
#' set.seed(103)
6467
#' train = sample(seq(length(y)),100,replace=FALSE)
6568
#' fit3 = glmnet(x[train,], y[train], family = "multinomial")

R/check.exclude.R

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
check.exclude <- function(exclude,nvars){
2+
exclude <- unique(exclude)
3+
if(length(exclude)> (nvars-2))stop("cannot retain 1 or less variables")
4+
if(length(exclude)==0)exclude <- NULL
5+
exclude
6+
}

R/data.R

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
#' Synthetic dataset with binary response
2+
#'
3+
#' Randomly generated data for binomial regression example.
4+
#'
5+
#' @name BinomialExample
6+
#' @docType data
7+
#' @usage data(BinomialExample)
8+
#' @keywords data
9+
#' @format List containing the following elements:
10+
#' \describe{
11+
#' \item{x}{100 by 30 matrix of numeric values.}
12+
#' \item{y}{Numeric vector of length 100 containing 44 zeros and 56 ones.}
13+
#' }
14+
"BinomialExample"
15+
16+
#' Synthetic dataset with right-censored survival response
17+
#'
18+
#' Randomly generated data for Cox regression example.
19+
#'
20+
#' @name CoxExample
21+
#' @docType data
22+
#' @usage data(CoxExample)
23+
#' @keywords data
24+
#' @format List containing the following elements:
25+
#' \describe{
26+
#' \item{x}{1,000 by 30 matrix of numeric values.}
27+
#' \item{y}{1,000 by 2 matrix with column names "time" and "status". The
28+
#' first column consists of positive numbers representing time to event,
29+
#' while the second column represents the status indicator
30+
#' (0=right-censored, 1=observed).}
31+
#' }
32+
"CoxExample"
33+
34+
#' Synthetic dataset with multiple Gaussian responses
35+
#'
36+
#' Randomly generated data for multi-response Gaussian regression example.
37+
#'
38+
#' @name MultiGaussianExample
39+
#' @docType data
40+
#' @usage data(MultiGaussianExample)
41+
#' @keywords data
42+
#' @format List containing the following elements:
43+
#' \describe{
44+
#' \item{x}{100 by 20 matrix of numeric values.}
45+
#' \item{y}{100 by 4 matrix of numeric values, each column representing
46+
#' one response vector.}
47+
#' }
48+
"MultiGaussianExample"
49+
50+
#' Synthetic dataset with multinomial response
51+
#'
52+
#' Randomly generated data for multinomial regression example.
53+
#'
54+
#' @name MultinomialExample
55+
#' @docType data
56+
#' @usage data(MultinomialExample)
57+
#' @keywords data
58+
#' @format List containing the following elements:
59+
#' \describe{
60+
#' \item{x}{500 by 30 matrix of numeric values.}
61+
#' \item{y}{Numeric vector of length 500 containing 142 ones, 174 twos
62+
#' and 184 threes.}
63+
#' }
64+
"MultinomialExample"
65+
66+
#' Synthetic dataset with count response
67+
#'
68+
#' Randomly generated data for Poisson regression example.
69+
#'
70+
#' @name PoissonExample
71+
#' @docType data
72+
#' @usage data(PoissonExample)
73+
#' @keywords data
74+
#' @format List containing the following elements:
75+
#' \describe{
76+
#' \item{x}{500 by 20 matrix of numeric values.}
77+
#' \item{y}{Numeric vector of length 500 consisting of non-negative
78+
#' integers.}
79+
#' }
80+
"PoissonExample"
81+
82+
#' Synthetic dataset with Gaussian response
83+
#'
84+
#' Randomly generated data for Gaussian regression example.
85+
#'
86+
#' @name QuickStartExample
87+
#' @docType data
88+
#' @usage data(QuickStartExample)
89+
#' @keywords data
90+
#' @format List containing the following elements:
91+
#' \describe{
92+
#' \item{x}{100 by 20 matrix of numeric values.}
93+
#' \item{y}{Numeric vector of length 100.}
94+
#' }
95+
"QuickStartExample"
96+
97+
#' Synthetic dataset with sparse design matrix
98+
#'
99+
#' Randomly generated data for Gaussian regression example with the
100+
#' design matrix x being in sparse matrix format.
101+
#'
102+
#' @name SparseExample
103+
#' @docType data
104+
#' @usage data(SparseExample)
105+
#' @keywords data
106+
#' @format List containing the following elements:
107+
#' \describe{
108+
#' \item{x}{100 by 20 matrix of numeric values. x is in sparse matrix
109+
#' format, having class "dgCMatrix".}
110+
#' \item{y}{Numeric vector of length 100.}
111+
#' }
112+
"SparseExample"

R/glmnet-package.R

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#' @examples
2424
#'
2525
#' data(QuickStartExample)
26+
#' x <- QuickStartExample$x; y <- QuickStartExample$y
2627
#' glmnet(x, y)
2728
#'
2829
NULL

R/glmnet.R

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,13 @@
146146
#' very large \code{nvars}, if a partial path is desired.
147147
#' @param pmax Limit the maximum number of variables ever to be nonzero
148148
#' @param exclude Indices of variables to be excluded from the model. Default
149-
#' is none. Equivalent to an infinite penalty factor (next item).
149+
#' is none. Equivalent to an infinite penalty factor for the variables excluded (next item).
150+
#' Users can supply instead an \code{exclude} function that generates the list of indices.
151+
#' This function is most generally defined as \code{function(x, y, weights, ...)},
152+
#' and is called inside \code{glmnet} to generate the indices for excluded variables.
153+
#' The \code{...} argument is required, the others are optional.
154+
#' This is useful for filtering wide data, and works correctly with \code{cv.glmnet}.
155+
#' See the vignette 'Introduction' for examples.
150156
#' @param penalty.factor Separate penalty factors can be applied to each
151157
#' coefficient. This is a number that multiplies \code{lambda} to allow
152158
#' differential shrinkage. Can be 0 for some variables, which implies no
@@ -346,6 +352,11 @@ glmnet=function(x,y,family=c("gaussian","binomial","poisson","multinomial","cox"
346352
if(is.null(np)|(np[2]<=1))stop("x should be a matrix with 2 or more columns")
347353
nobs=as.integer(np[1])
348354
nvars=as.integer(np[2])
355+
if(is.null(weights))weights=rep(1,nobs)
356+
else if(length(weights)!=nobs)stop(paste("number of elements in weights (",length(weights),") not equal to the number of rows of x (",nobs,")",sep=""))
357+
if(is.function(exclude))exclude <- check.exclude(exclude(x=x,y=y,weights=weights),nvars)
358+
if (length(penalty.factor) != nvars)
359+
stop("the length of penalty.factor does not match the number of variables")
349360

350361
### See whether its a call to glmnet or to glmnet.path, based on family arg
351362
if(!is.character(family)){
@@ -378,8 +389,6 @@ glmnet=function(x,y,family=c("gaussian","binomial","poisson","multinomial","cox"
378389
alpha=as.double(alpha)
379390
nlam=as.integer(nlambda)
380391
y=drop(y) # we dont like matrix responses unless we need them
381-
if(is.null(weights))weights=rep(1,nobs)
382-
else if(length(weights)!=nobs)stop(paste("number of elements in weights (",length(weights),") not equal to the number of rows of x (",nobs,")",sep=""))
383392
dimy=dim(y)
384393
nrowy=ifelse(is.null(dimy),length(y),dimy[1])
385394
if(nrowy!=nobs)stop(paste("number of observations in y (",nrowy,") not equal to the number of rows of x (",nobs,")",sep=""))

R/predict.cv.glmnet.R

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ predict.cv.glmnet=function(object,newx,s=c("lambda.1se","lambda.min"),...){
5959
if(is.character(s)){
6060
s=match.arg(s)
6161
lambda=object[[s]]
62+
names(lambda)=s
6263
}
6364
else stop("Invalid form for s")
6465
predict(object$glmnet.fit,newx,s=lambda,...)

0 commit comments

Comments
 (0)