Skip to content

Commit 344f404

Browse files
committed
now debias lasso only computes theta for the active set
1 parent b5f4bfd commit 344f404

File tree

2 files changed

+13
-44
lines changed

2 files changed

+13
-44
lines changed

selectiveInference/R/funs.fixed.R

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -148,12 +148,15 @@ sigma=NULL, alpha=0.1,
148148
hsigma <- 1/n*(t(Xordered)%*%Xordered)
149149
hsigmaS <- 1/n*(t(XS)%*%XS) # hsigma[S,S]
150150
hsigmaSinv <- solve(hsigmaS) # pinv(hsigmaS)
151-
151+
152152
# Approximate inverse covariance matrix for when (n < p) from lasso_Inference.R
153-
htheta <- InverseLinfty(hsigma, n, verbose=FALSE)
153+
htheta <- InverseLinfty(hsigma, n, length(S), verbose=FALSE)
154+
# htheta <- InverseLinfty(hsigma, n, verbose=FALSE)
154155

155156
FS = rbind(diag(length(S)),matrix(0,pp-length(S),length(S)))
156-
ithetasigma = (diag(pp)-(htheta%*%hsigma))
157+
GS = cbind(diag(length(S)),matrix(0,length(S),pp-length(S)))
158+
ithetasigma = (GS-(htheta%*%hsigma))
159+
# ithetasigma = (diag(pp) - (htheta%*%hsigma))
157160

158161
M <- (((htheta%*%t(Xordered))+ithetasigma%*%FS%*%hsigmaSinv%*%t(XS))/n)
159162
# vector which is offset for testing debiased beta's
@@ -254,20 +257,21 @@ fixedLasso.poly=
254257

255258
##############################
256259

257-
### Functions borrowed from lasso_inference.R
260+
### Functions borrowed and slightly modified from lasso_inference.R
258261

259262
## Approximates inverse covariance matrix theta
260-
InverseLinfty <- function(sigma, n, resol=1.5, mu=NULL, maxiter=50, threshold=1e-2, verbose = TRUE) {
261-
isgiven <- 1;
263+
InverseLinfty <- function(sigma, n, e, resol=1.5, mu=NULL, maxiter=50, threshold=1e-2, verbose = TRUE) {
264+
# InverseLinfty <- function(sigma, n, resol=1.5, mu=NULL, maxiter=50, threshold=1e-2, verbose = TRUE) {
265+
isgiven <- 1;
262266
if (is.null(mu)){
263267
isgiven <- 0;
264268
}
265269

266270
p <- nrow(sigma);
267-
M <- matrix(0, p, p);
271+
M <- matrix(0, e, p);
268272
xperc = 0;
269273
xp = round(p/10);
270-
for (i in 1:p) {
274+
for (i in 1:e) {
271275
if ((i %% xp)==0){
272276
xperc = xperc+10;
273277
if (verbose) {

selectiveInference/R/linear.tests.R

Lines changed: 1 addition & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ robs.test <- function() {
1515
hbeta <- as.numeric(coef(las,x=X,y=y,s=lambda/n,exact=TRUE,intercept=T))
1616

1717

18-
return(fixedLassoInf(X,y,hbeta[-1],lambda,family="gaussian",type="partial",intercept=T,sigma=sigma)$pv)
18+
return(fixedLassoInf(X,y,hbeta[-1],lambda,family="gaussian",type="partial",intercept=T,sigma=sigma))
1919
}
2020

2121

@@ -134,39 +134,4 @@ power.partial.pval.dist <- function(n,p,intercept=T,lambda=1) {
134134
}
135135
qqplot(x=runif(length(pvs)),y=pvs,xlab="Expected",ylab="Observed",main="Partial Coef. 10 Corr. X")
136136
abline(0,1)
137-
}
138-
139-
140-
141-
142-
## Tests pop inf for X and y randomly generated
143-
nullPopTest <- function(n,p,intercept=T,lambda=1) {
144-
y <- matrix(rnorm(n),ncol=1) # rand N(0,1) response
145-
X <- matrix(rnorm(p*n),ncol = p) # p rand N(0,1) predictors
146-
147-
# lambda <- 1
148-
X=scale(X,T,T)/sqrt(n-1)
149-
150-
# lambda <- 1
151-
las <- glmnet(X,y,family="gaussian",alpha=1,standardize=F,intercept=intercept)
152-
hbeta <- as.numeric(coef(las,x=X,y=y,s=lambda/n,exact=TRUE,intercept=intercept))
153-
154-
### perform post selection inference
155-
156-
sigma = estimateSigma(X,y)$sigmahat
157-
158-
if (intercept) return(fixedLassoInf(X,y,hbeta,lambda,family="gaussian",type="full",intercept=intercept,sigma=sigma))
159-
else return(fixedLassoInf(X,y,hbeta[-1],lambda,family="gaussian",type="full",intercept=intercept,sigma=sigma))
160-
}
161-
162-
## QQ plot of p-values for all null data now that bug fix is implemented
163-
null.pop.pval.dist <- function(n,p,intercept=T,lambda=1) {
164-
pvs <- c()
165-
for(i in 1:10) {
166-
a <- nullPopTest(n,p,intercept,lambda)
167-
ps <- a$pv
168-
pvs <- c(pvs,ps,recursive=T)
169-
}
170-
qqplot(x=runif(length(pvs)),y=pvs,xlab="Expected",ylab="Observed",main="Pop Coef. Null X")
171-
abline(0,1)
172137
}

0 commit comments

Comments
 (0)