Skip to content

Commit 2960b99

Browse files
BF: fix shape of approximate_BN inv matrix, correct the output to be scaled pseudoinverse
1 parent d9c034e commit 2960b99

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

selectiveInference/R/funs.ROSI.R

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -269,18 +269,21 @@ approximate_JM = function(X, active_set){
269269
}
270270

271271
approximate_BN = function(X, active_set){
272+
# from (6) of https://arxiv.org/pdf/1703.03282.pdf
273+
# approximate inverse is a scaled pseudo-inverse
272274
n=nrow(X)
273275
p=ncol(X)
274276
nactive=length(active_set)
275277

276278
svdX = svd(X)
277-
inv = solve(svdX$v %*% diag(svdX$d^2) %*% t(svdX$v))
278-
D = matrix(rep(0, nactive*p), nrow=nactive, ncol=p)
279+
inv = solve(svdX$u %*% diag(svdX$d^2) %*% t(svdX$u))
280+
D = rep(0, nactive)
279281
for (i in 1:nactive){
280282
var = active_set[i]
281-
D[i, var] = 1/(t(X[,var]) %*% inv %*% X[,var])
283+
D[i] = 1/(t(X[,var]) %*% inv %*% X[,var])
282284
}
283-
M_active = D %*% svdX$v %*% t(svdX$v) # last two terms: projection onto row(X)
285+
pseudo_XTX = svdX$v[active_set,,drop=FALSE] %*% diag(1/svdX$d^2) %*% t(svdX$v)
286+
M_active = diag(D) %*% pseudo_XTX # last two terms: projection onto row(X)
284287
return(M_active)
285288
}
286289

@@ -319,10 +322,10 @@ setup_Qbeta = function(X,
319322

320323
} else {
321324

322-
if (debiasing_method == "JM"){
325+
if (debiasing_method == "JM") {
323326
## this should be the active rows of \hat{\Sigma}(W^{1/2} X)^T/n, so size |E|\times p
324327
M_active = approximate_JM(W_root %*% X, active_set)
325-
} else if (debiasing_method == "BN"){
328+
} else if (debiasing_method == "BN") {
326329
M_active = approximate_BN(W_root %*% X, active_set)
327330
}
328331

0 commit comments

Comments
 (0)