Skip to content

Commit 43fbddf

Browse files
added a full n>p example
1 parent eb2a5e4 commit 43fbddf

File tree

1 file changed

+42
-17
lines changed

1 file changed

+42
-17
lines changed

selectiveInference/man/fixedLassoInf.Rd

Lines changed: 42 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -257,29 +257,54 @@ set.seed(43)
257257
out = fixedLassoInf(x, tim, beta_hat, lambda, status=status, family="cox")
258258
out
259259

260-
# Debiased lasso or "full"
260+
# Debiased lasso or "full"
261261

262-
n = 50
263-
p = 100
264-
sigma = 1
262+
n = 50
263+
p = 100
264+
sigma = 1
265265

266-
x = matrix(rnorm(n*p),n,p)
267-
x = scale(x,TRUE,TRUE)
266+
x = matrix(rnorm(n*p),n,p)
267+
x = scale(x,TRUE,TRUE)
268268

269-
beta = c(3,2,rep(0,p-2))
270-
y = x\%*\%beta + sigma*rnorm(n)
269+
beta = c(3,2,rep(0,p-2))
270+
y = x\%*\%beta + sigma*rnorm(n)
271271

272-
# first run glmnet
273-
gfit = glmnet(x, y, standardize=FALSE, intercept=FALSE)
272+
# first run glmnet
273+
gfit = glmnet(x, y, standardize=FALSE, intercept=FALSE)
274274

275-
# extract coef for a given lambda; note the 1/n factor!
276-
# (and we don't save the intercept term)
277-
lambda = 2.8
278-
beta = coef(gfit, x=x, y=y, s=lambda/n, exact=TRUE)[-1]
275+
# extract coef for a given lambda; note the 1/n factor!
276+
# (and we don't save the intercept term)
277+
lambda = 2.8
278+
beta = coef(gfit, x=x, y=y, s=lambda/n, exact=TRUE)[-1]
279279

280-
# compute fixed lambda p-values and selection intervals
281-
out = fixedLassoInf(x, y, beta, lambda, sigma=sigma, type='full', intercept=FALSE)
282-
out
280+
# compute fixed lambda p-values and selection intervals
281+
out = fixedLassoInf(x, y, beta, lambda, sigma=sigma, type='full', intercept=FALSE)
282+
out
283+
284+
# When n > p and "full" we use the full inverse
285+
# instead of Javanmard and Montanari's approximate inverse
286+
287+
n = 200
288+
p = 50
289+
sigma = 1
290+
291+
x = matrix(rnorm(n*p),n,p)
292+
x = scale(x,TRUE,TRUE)
293+
294+
beta = c(3,2,rep(0,p-2))
295+
y = x\%*\%beta + sigma*rnorm(n)
296+
297+
# first run glmnet
298+
gfit = glmnet(x, y, standardize=FALSE, intercept=FALSE)
299+
300+
# extract coef for a given lambda; note the 1/n factor!
301+
# (and we don't save the intercept term)
302+
lambda = 2.8
303+
beta = coef(gfit, x=x, y=y, s=lambda/n, exact=TRUE)[-1]
304+
305+
# compute fixed lambda p-values and selection intervals
306+
out = fixedLassoInf(x, y, beta, lambda, sigma=sigma, type='full', intercept=FALSE)
307+
out
283308

284309
}
285310

0 commit comments

Comments
 (0)