Skip to content

Commit 2e592f0

Browse files
committed
added optional 'add.targets' parameter to fixedLassoInference to allow user to add variables as targets for inference, even if they are not selected by the lasso
1 parent 344f404 commit 2e592f0

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

selectiveInference/R/funs.fixed.R

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# for the solution of
33
# min 1/2 || y - \beta_0 - X \beta ||_2^2 + \lambda || \beta ||_1
44

5-
fixedLassoInf <- function(x, y, beta, lambda, family=c("gaussian","binomial","cox"),intercept=TRUE, status=NULL,
5+
fixedLassoInf <- function(x, y, beta, lambda, family=c("gaussian","binomial","cox"),intercept=TRUE, add.targets=NULL, status=NULL,
66
sigma=NULL, alpha=0.1,
77
type=c("partial","full"), tol.beta=1e-5, tol.kkt=0.1,
88
gridrange=c(-100,100), bits=NULL, verbose=FALSE) {
@@ -60,6 +60,12 @@ sigma=NULL, alpha=0.1,
6060
bits = NULL
6161
}
6262

63+
if (!is.null(add.targets) && (!is.vector(add.targets)
64+
|| !all(is.numeric(add.targets)) || !all(add.targets==floor(add.targets))
65+
|| !all(add.targets >= 1 && add.targets <= p))) {
66+
stop("'add.targets' must be a vector of integers between 1 and p")
67+
}
68+
6369
# If glmnet was run with an intercept term, center x and y
6470
if (intercept==TRUE) {
6571
obj = standardize(x,y,TRUE,FALSE)
@@ -117,12 +123,15 @@ sigma=NULL, alpha=0.1,
117123
}
118124
}
119125

126+
# add additional targets for inference if provided
127+
if (!is.null(add.targets)) vars = sort(unique(c(vars,add.targets,recursive=T)))
128+
120129
k = length(vars)
121130
pv = vlo = vup = numeric(k)
122131
vmat = matrix(0,k,n)
123132
ci = tailarea = matrix(0,k,2)
124133
sign = numeric(k)
125-
134+
126135
if (type=="full" & p > n) {
127136
if (intercept == T) {
128137
pp=p+1

0 commit comments

Comments
 (0)