@@ -269,18 +269,21 @@ approximate_JM = function(X, active_set){
269
269
}
270
270
271
271
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
272
274
n = nrow(X )
273
275
p = ncol(X )
274
276
nactive = length(active_set )
275
277
276
278
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 )
279
281
for (i in 1 : nactive ){
280
282
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 ])
282
284
}
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)
284
287
return (M_active )
285
288
}
286
289
@@ -319,10 +322,10 @@ setup_Qbeta = function(X,
319
322
320
323
} else {
321
324
322
- if (debiasing_method == " JM" ){
325
+ if (debiasing_method == " JM" ) {
323
326
# # this should be the active rows of \hat{\Sigma}(W^{1/2} X)^T/n, so size |E|\times p
324
327
M_active = approximate_JM(W_root %*% X , active_set )
325
- } else if (debiasing_method == " BN" ){
328
+ } else if (debiasing_method == " BN" ) {
326
329
M_active = approximate_BN(W_root %*% X , active_set )
327
330
}
328
331
0 commit comments