Skip to content

Commit d487526

Browse files
BF: percent signs in example
1 parent 27af0d5 commit d487526

File tree

1 file changed

+30
-5
lines changed

1 file changed

+30
-5
lines changed

selectiveInference/man/fixedLassoInf.Rd

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ p = 10
145145
sigma = 1
146146
147147
x = matrix(rnorm(n*p),n,p)
148-
x=scale(x,TRUE,TRUE)
148+
x = scale(x,TRUE,TRUE)
149149
150150
beta = c(3,2,rep(0,p-2))
151151
y = x\%*\%beta + sigma*rnorm(n)
@@ -165,10 +165,10 @@ out
165165

166166
## as above, but use lar function instead to get initial
167167
## lasso fit (should get same results)
168-
lfit = lar(x,y,normalize=FALSE)
169-
beta = coef(lfit,s=lambda,mode="lambda")
170-
out2 = fixedLassoInf(x,y,beta,lambda,sigma=sigma)
171-
out2
168+
lfit = lar(x,y,normalize=FALSE)
169+
beta = coef(lfit,s=lambda,mode="lambda")
170+
out2 = fixedLassoInf(x,y,beta,lambda,sigma=sigma)
171+
out2
172172

173173
## mimic different penalty factors by first scaling x
174174
set.seed(43)
@@ -249,5 +249,30 @@ status=sample(c(0,1),size=n,replace=TRUE)
249249
# compute fixed lambda p-values and selection intervals
250250
out = fixedLassoInf(x,tim,beta_hat,lambda,status=status,family="cox")
251251
out
252+
253+
# Debiased lasso or "full"
254+
255+
n = 50
256+
p = 100
257+
sigma = 1
258+
259+
x = matrix(rnorm(n*p),n,p)
260+
x = scale(x,TRUE,TRUE)
261+
262+
beta = c(3,2,rep(0,p-2))
263+
y = x\%*\%beta + sigma*rnorm(n)
264+
265+
# first run glmnet
266+
gfit = glmnet(x, y, standardize=FALSE, intercept=FALSE)
267+
268+
# extract coef for a given lambda; note the 1/n factor!
269+
# (and we don't save the intercept term)
270+
lambda = 2.8
271+
beta = coef(gfit, s=lambda/n, exact=TRUE)[-1]
272+
273+
# compute fixed lambda p-values and selection intervals
274+
out = fixedLassoInf(x, y, beta, lambda, sigma=sigma, type='full', intercept=FALSE)
275+
out
276+
252277
}
253278

0 commit comments

Comments
 (0)