@@ -160,7 +160,7 @@ gfit = glmnet(x,y,standardize=FALSE)
160
160
# extract coef for a given lambda; note the 1/n factor!
161
161
# (and we don' t save the intercept term )
162
162
lambda = .8
163
- beta = coef(gfit , s = lambda / n , exact = TRUE )[- 1 ]
163
+ beta = coef(gfit , x = x , y = y , s = lambda / n , exact = TRUE )[- 1 ]
164
164
165
165
# compute fixed lambda p-values and selection intervals
166
166
out = fixedLassoInf(x ,y ,beta ,lambda ,sigma = sigma )
170
170
# # as above, but use lar function instead to get initial
171
171
# # lasso fit (should get same results)
172
172
lfit = lar(x ,y ,normalize = FALSE )
173
- beta = coef(lfit ,s = lambda ,mode = " lambda" )
174
- out2 = fixedLassoInf(x ,y , beta ,lambda ,sigma = sigma )
173
+ beta = coef(lfit , s = lambda , mode = " lambda" )
174
+ out2 = fixedLassoInf(x , y , beta , lambda , sigma = sigma )
175
175
out2
176
176
177
177
# # mimic different penalty factors by first scaling x
@@ -189,12 +189,12 @@ pf=c(rep(1,7),rep(.1,3)) #define penalty factors
189
189
pf = p * pf / sum(pf ) # penalty factors should be rescaled so they sum to p
190
190
xs = scale(x ,FALSE ,pf ) # scale cols of x by penalty factors
191
191
# first run glmnet
192
- gfit = glmnet(xs ,y , standardize = FALSE )
192
+ gfit = glmnet(xs , y , standardize = FALSE )
193
193
194
194
# extract coef for a given lambda; note the 1/n factor!
195
195
# (and we don't save the intercept term)
196
196
lambda = .8
197
- beta_hat = coef(gfit , s = lambda / n , exact = TRUE )[- 1 ]
197
+ beta_hat = coef(gfit , x = xs , y = y , s = lambda / n , exact = TRUE )[- 1 ]
198
198
199
199
# compute fixed lambda p-values and selection intervals
200
200
out = fixedLassoInf(xs ,y ,beta_hat ,lambda ,sigma = sigma )
@@ -221,37 +221,40 @@ set.seed(43)
221
221
# extract coef for a given lambda; note the 1/n factor!
222
222
# (and here we DO include the intercept term)
223
223
lambda = .8
224
- beta_hat = coef(gfit , s = lambda / n , exact = TRUE )
224
+ beta_hat = coef(gfit , x = x , y = y , s = lambda / n , exact = TRUE )
225
225
226
226
# compute fixed lambda p-values and selection intervals
227
227
out = fixedLassoInf(x ,y ,beta_hat ,lambda ,family = " binomial" )
228
228
out
229
229
230
- # Cox model
231
- set.seed(43 )
230
+
231
+ # Cox model
232
+
233
+ set.seed(43 )
232
234
n = 50
233
235
p = 10
234
236
sigma = 1
235
237
236
- x = matrix (rnorm(n * p ),n , p )
237
- x = scale(x ,TRUE ,TRUE )
238
+ x = matrix (rnorm(n * p ), n , p )
239
+ x = scale(x , TRUE , TRUE )
238
240
239
241
beta = c(3 ,2 ,rep(0 ,p - 2 ))
240
242
tim = as.vector(x \%* \%beta + sigma * rnorm(n ))
241
243
tim = tim - min(tim )+ 1
242
- status = sample(c(0 ,1 ),size = n ,replace = TRUE )
244
+ status = sample(c(0 ,1 ),size = n ,replace = TRUE )
243
245
# first run glmnet
244
246
245
247
246
- gfit = glmnet(x ,Surv(tim ,status ),standardize = FALSE ,family = " cox" )
248
+ y = Surv(tim ,status )
249
+ gfit = glmnet(x , y , standardize = FALSE , family = " cox" )
247
250
248
251
# extract coef for a given lambda; note the 1/n factor!
249
252
250
253
lambda = 1.5
251
- beta_hat = as.numeric(coef(gfit , s = lambda / n , exact = TRUE ))
252
-
254
+ beta_hat = as.numeric(coef(gfit , x = x , y = y , s = lambda / n , exact = TRUE ))
255
+
253
256
# compute fixed lambda p-values and selection intervals
254
- out = fixedLassoInf(x ,tim ,beta_hat ,lambda ,status = status ,family = " cox" )
257
+ out = fixedLassoInf(x , tim , beta_hat , lambda , status = status , family = " cox" )
255
258
out
256
259
257
260
# Debiased lasso or "full"
@@ -272,7 +275,7 @@ gfit = glmnet(x, y, standardize=FALSE, intercept=FALSE)
272
275
# extract coef for a given lambda; note the 1/n factor!
273
276
# (and we don't save the intercept term)
274
277
lambda = 2.8
275
- beta = coef(gfit , s = lambda / n , exact = TRUE )[- 1 ]
278
+ beta = coef(gfit , x = x , y = y , s = lambda / n , exact = TRUE )[- 1 ]
276
279
277
280
# compute fixed lambda p-values and selection intervals
278
281
out = fixedLassoInf(x , y , beta , lambda , sigma = sigma , type = ' full' , intercept = FALSE )
0 commit comments